r/PowerShell • • Nov 17 '25

Need help retrieving hash from password protected word file within unprotected zip

0 Upvotes

Basically, the situation is I was trying to open a password protected word document in a zip without remembering the password, obviously couldn't, which led me down the rabbit hole of john the ripper, office2john, etc. The problem is it doesn't look like office2john can access the word file from within the zip, and the password protection prevents me from extracting it. Anyone know anything that could help? Again, the zip itself is not protected.


r/PowerShell • • Nov 15 '25

do you guys have any fun commands to use? I'm new to PowerShell and programming in general and just wanna expirement.

35 Upvotes

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