r/PowerShell • • Nov 16 '25

Help, I ran irm "https:christitus.com/win" | iex

0 Upvotes

So I ran this command I saw from a reel to uninstall onedrive, I chose Debloat edge, disable recall, remove ondrive and disable microsoft copilot. Then I went to research (Which I should've done before running this) and I found 1 reddit post which comments saying not safe. I'm not sure what to do now? Reinstall windows or something? Can anyone give me some advices?

Edit: I saw https://www.reddit.com/r/PowerShell/comments/1izktf1/irm_httpschristituscomwin_iex_is_it_safe/ this thats why I want to make sure it didn't install anything malicious and why I posted here.


r/PowerShell • • Nov 14 '25

How do I update PowerShell?

5 Upvotes

I need to install PowerShell version 7.5.4, but I don't know how. When I go to https://github.com/PowerShell/PowerShell/releases/tag/v7.5.4, I don't know which file to choose for Windows or how to install it. This hasn't happened to me before; it seems like something changed.


r/PowerShell • • Nov 14 '25

Script Sharing Parsing Json with duplicate keys with Windows Powershell

18 Upvotes

I ran into an API that returns Json with duplicate keys at work and haven't yet ported most necessary modules to Powershell Core which has -AsHashTable.

Went ahead and wrote this to deal with it. All duplicate keys at the same nested level get a number suffix so the json can be fed into ConvertFrom-Json.

Example output from running this script:

    # test 1
    id    : 50001
    test  : {@{id=50001; ID0=50001; Id1=50001; iD2=50001}}
    ID0   : 50001
    Id1   : 50001
    test2 : {@{id=50001; ID0=50001; Id1=50001; iD2=50001; test3=System.Object[]}}
    iD2   : 50001
    
    #test 2
    id  : blah
    iD0 : 1

The functions that do the work are Find-JsonDuplicates and Format-NormalizedJson. Called by putting Format-NormalizedJson between your Json string and ConvertFrom-Json like:

$jsonStringWithDuplicates | Format-NormalizedJson | ConvertFrom-Json

Script:

    # Comprehensive test of nested duplicates and duplicate
    # properties separated by other elements
    $testJson = @'
    {
        "id": 50001,
        "test": [
            {
                "id": 50001,
                "ID": 50001,
                "Id": 50001,
                "iD": 50001
            }
        ],
        "ID": 50001,
        "Id": 50001,
        "test2": [
            {
                "id": 50001,
                "ID": 50001,
                "Id": 50001,
                "iD": 50001,
                "test3": [
                    {
                        "id": 50001,
                        "ID": [
                            "50001"
                        ],
                        "Id": {
                            "blah": "50001"
                        },
                        "iD": [
                            50001
                        ]
                    }
                ]
            }
        ],
        "iD": 50001
    }
'@
    
    # Test of single occurrence of duplicate
    $testJson2=@'
    [
        {
            "id": "blah",
            "iD": 1
        }
    ]
'@
    
    function Find-JsonDuplicates {
        param(
            [string]$json
        )
        # levelCount is nested level
        $levelCount = -1
        $levelInstances = [System.Collections.ArrayList]::new()
        # levelInstance is for occurrences at same nested level
        $levelInstance = 0
        # build property keys
        $keyBuilder = [System.Text.StringBuilder]::new()
        $startQuote = $false
        $endQuote = $false
        $buildKey = $false
        $currentQuoteIndex = 0
    
        $jsonChars = $json.ToCharArray()
    
        $keyCollection = [System.Collections.ArrayList]::new()
        for ($i = 0; $i -lt $jsonChars.Count; $i++ ) {
            $currentChar = $jsonChars[$i]
    
            if ($buildKey -and !$currentChar.Equals([char]'"')) {
                $keyBuilder.Append($currentChar) | Out-Null
                continue
            }
    
            switch ($currentChar) {
                # Collect values between quotes
                '"' {
                    if (!$startQuote) {
                        $currentQuoteIndex = $i
                        $startQuote = $true
                        $buildKey = $true
                    }
                    elseif (!$endQuote) {
                        $endQuote = $true
                        $buildKey = $false
                    }
                }
                # Increment nested level and set or retrieve instance
                '{' {
                    $levelCount++
                    if ($levelInstances.Count - 1 -lt $levelCount) {
                        $levelInstance = 0
                        $levelInstances.Add(0) | Out-Null
                    }
                    else {
                        $levelInstances[$levelCount] = $levelInstances[$levelCount] + 1
                        $levelInstance = $levelInstances[$levelCount]
                    }
                }
                # Decrement nested level and retrieve the instance for the last nested level
                '}' {
                    $levelCount--
                    $levelInstance = $levelInstances[$levelCount]
                    $startQuote = $false
                    $endQuote = $false
                    # String was value and not key, reset builder
                    $keyBuilder.Clear() | Out-Null
                }
                ':' {
                    # Add property keeping track of its nested instance and startindex
                    if ($endQuote) {
                        $currentKey = $keyBuilder.ToString()
                        $keyCollection.Add(
                            [pscustomobject]@{
                                Level      = "$($levelCount)$($levelInstance)"
                                Key        = $currentKey
                                StartIndex = $currentQuoteIndex + 1
                            }
                        ) | Out-Null
                        $keyBuilder.Clear() | Out-Null
                        $startQuote = $false
                        $endQuote = $false
                    }
                }
                # String was value and not key, reset builder
                ',' {
                    $startQuote = $false
                    $endQuote = $false
                    $keyBuilder.Clear() | Out-Null
                }
            }
        }
    
        $duplicates = @($keyCollection | Group-Object Level, Key | Where-Object { $_.Count -gt 1 })
    
        $outCollection = [System.Collections.ArrayList]::New()
    
        foreach ($d in $duplicates) {
            $outCollection.AddRange(@($d.Group[1..($d.Count)])) | Out-Null
        }
        $outCollection = $outCollection | Sort-Object StartIndex
        return , $outCollection
    }
    
    Function Format-NormalizedJson {
        [CmdletBinding()]
        param(
            [parameter(ValueFromPipeline)]
            [string]$json
        )
    
        process {
            $duplicates = Find-JsonDuplicates $json
            # Adding characters to the Json offsets the subsequent index
            # keep track of offset
            $suffixOffset = 0
            $levelKeyCounter = @{}
       
            foreach ($d in $duplicates) {
                # Maintain increment consistency with Key and Level
                if ($levelKeyCounter.ContainsKey("$($d.Key):$($d.Level)")) {
                    $currentCounter = $levelKeyCounter["$($d.Key):$($d.Level)"]
                }
                else {
                    $currentCounter = 0
                }
                # Replace the duplicate property with numbered suffix
                $json = $json.Substring(0, $d.StartIndex + $suffixOffset) `
                    + "$($d.Key)$currentCounter" `
                    + $json.Substring($d.StartIndex + $d.Key.Length + $suffixOffset, $Json.Length - ($d.StartIndex + $d.Key.Length + $suffixOffset))
    
                $suffixOffset += $currentCounter.ToString().Length
                $currentCounter++
                $levelKeyCounter["$($d.Key):$($d.Level)"] = $currentCounter
            }
    
            return $json
        }
    }
    
    $testJsonUpdated = $testJson | Format-NormalizedJson | ConvertFrom-Json
    
    $testJsonUpdated
    
    $testJsonUpdated2 = $testJson2 | Format-NormalizedJson | ConvertFrom-Json
    
    $testJsonUpdated2

r/PowerShell • • Nov 14 '25

Private items in share Mailbox prevent access for Otter users - looking for a PowerShell command

0 Upvotes

Hello everyone,

I’m an IT administrator in our company and currently facing the following issue: We are using a shared mailbox that several employees have FullAccess permissions to. However, one user is accidentally marking incoming or forwarded emails as “Private.” As a result, other team members are unable to see these messages, even though they have the correct permissions on the mailbox.

Since Outlook hides private items by default in shared mailboxes, these emails remain invisible to the rest of the team. This causes workflow disruptions because important information is not accessible to everyone who needs it.

From what I understand, the issue can be resolved by granting the affected users the “CanViewPrivateItems” permission on the relevant folder (e.g., Inbox) of the shared mailbox.

Therefore, I am looking for a PowerShell command that allows me to assign this permission so that team members are able to view private items within the shared mailbox.

Has anyone dealt with this before, or does someone have a working command for Exchange Online (or on-prem) that reliably enables this permission?

Thanks in advance!

Best regards, Daniel