r/PowerShell • • Nov 18 '25

FileMover

10 Upvotes

My client scans a lot of documents. Their infrastructure is a total mix of legacy and modern (law firm). When a law clerk scans a document, the resulting document needs to be moved to an another folder that is one drive synced. This needs to be automated. Suggestions on how I do this?


r/PowerShell • • Nov 18 '25

Paste not working in powershell Connect-ExchangeOnline pop-up

1 Upvotes

Is anyone else experiencing this issue? When I connect to the server, open PowerShell, and run Connect-ExchangeOnline, the login pop-up appears—but I am unable to paste into it.

Interestingly, pasting also does not work in the windows search bar, though it works fine in notepad. No changes have been made to the system recently.

Has anyone seen this behavior or found a solution?


r/PowerShell • • Nov 18 '25

Need Help Writing Script to Fix Gaps in Sequentially Numbered Save Files

0 Upvotes

I have a folder filled with save files from a Ren'Py game and they are correctly sequenced like this:
1-1-LT1.save
1-2-LT1.save
1-3-LT1.save
1-4-LT1.save
1-5-LT1.save
1-6-LT1.save
2-1-LT1.save
2-2-LT1.save
following this pattern.

Let's say the next three files in the folder need to be renamed:
2-4-LT1.save → 2-3-LT1.save
3-1-LT1.save → 2-4-LT1.save
3-3-LT1.save → 2-5-LT1.save
etc.
I'm looking for a PowerShell script that can rename all the files in the folder to bridge those gaps. 

I have no experience with coding and would really appreciate the help.


r/PowerShell • • Nov 17 '25

Question Connect Private Teams Channel

5 Upvotes

Hello techies,

I am trying to connect to Microsoft Teams using App Registration and Microsoft Graph API. I am successfully able to connect to Teams, I am getting private teams name and people who are part of that team and General channel. However my requirement is to get the details of people in private channel. I am getting 403 forbidden error.

I have given the following API permission

  1. Channel.ReadBasic.All
  2. ChannelMember.Read.All
  3. Directory.Read.All
  4. Group.Read.All
  5. Team.ReadBasic.All
  6. TeamMember.Read.All
  7. User.Read.All

Any inputs would be appreciated, Thanks


r/PowerShell • • Nov 17 '25

update dynamic distribution list

0 Upvotes

i am in an environment running exchange 2019 hybrid with a bunch of DDLs. Any tips on how i can add an extra CustomAttribute to this rule and perhaps include a security group? I know the command is Set-DynamicDistributionGroup but my head hurts just looking at this and trying to workout an easy way to read it and know where to make the addition. I suspect it was created many exchange versions ago

((((((((((((((((((((((((((Company -eq 'Contoso') -and (CustomAttribute4 -eq 'City'))) -and (((((CustomAttribute7 -eq 'Group') -or (CustomAttribute7 -eq 'Contractor'))) -or (CustomAttribute7 -eq 'Permanent'))))) -and (((RecipientType -eq 'UserMailbox') -or (((RecipientType -eq 'MailUser') -and (CustomAttribute12 -ne 'Excluded'))))))) -and (-not(Name -like 'SystemMailbox{*')))) -and (-not(Name -like 'CAS_{*')))) -and (-not(RecipientTypeDetailsValue -eq 'MailboxPlan')))) -and (-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'PublicFolderMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'ArbitrationMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'AuditLogMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'AuxAuditLogMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'SupervisoryReviewPolicyMailbox')))) -and (-not(Name -like 'SystemMailbox{*')) -and (-not(Name -like 'CAS_{*')) -and (-not(RecipientTypeDetailsValue -eq 'MailboxPlan')) -and (-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'PublicFolderMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'ArbitrationMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'AuditLogMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'AuxAuditLogMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'SupervisoryReviewPolicyMailbox')))


r/PowerShell • • Nov 17 '25

Error when updating PowerShell

12 Upvotes

I was trying to see to see if I can update PowerShell when I got the error:

Failed when searching source; results will not be included: winget
No installed package found matching input criteria.

I used the command: "winget list --id Microsoft.PowerShell --upgrade-available" to see if I could update it.

Trying to update it with: "winget install --id Microsoft.PowerShell", gives the error:

Failed when searching source: winget
An unexpected error occurred while executing the command:
0x8a15000f : Data required by the source is missing

Winget is installed, and I doing something wrong?


r/PowerShell • • Nov 16 '25

Not able to retrieve results from Invoke-Command scriptblock running Start-Process

6 Upvotes

Updated

<#

.Synopsis

Troubleshoot network issues

.DESCRIPTION

Tests Winsock-based port of ttcp to Windows.

It helps measure network driver performance and throughput on different network topologies and hardware setups.

It provides the customer with a multithreaded, asynchronous performance workload for measuring an achievable data transfer rate on an existing network setup.

.EXAMPLE

Run test only (no export)

Invoke-Ntttcp -ServerIP "10.0.0.1" -ServerCPUs 4 -ClientIP "10.0.0.2" -Time 60 -RunClient

Export to CSV in custom folder

Invoke-Ntttcp -ServerIP "10.0.0.1" -ServerCPUs 4 -ClientIP "10.0.0.2" -Time 60 -RunClient -ExportCsv -ExportPath "D:\Logs"

Export to JSON in default folder

Invoke-Ntttcp -ServerIP "10.0.0.1" -ServerCPUs 4 -ClientIP "10.0.0.2" -Time 60 -RunClient -ExportJson

Export to both CSV and JSON in one folder

Invoke-Ntttcp -ServerIP "10.0.0.1" -ServerCPUs 4 -ClientIP "10.0.0.2" -Time 60 -RunClient -ExportCsv -ExportJson -ExportPath "E:\PerfResults"

.Requires

Microsoft ntttcp.exe

https://github.com/microsoft/ntttcp

https://learn.microsoft.com/en-us/azure/virtual-network/virtual-network-bandwidth-testing?tabs=windows

#>

function Invoke-Ntttcp {

[CmdletBinding()]

param(

[ipaddress]$ServerIP,

[int]$ServerCPUs,

[ipaddress]$ClientIP,

[int]$Time,

[switch]$RunClient,

[switch]$ExportCsv,

[switch]$ExportJson,

[string]$ExportPath = "C:\Temp\ntttcp"

)

function Ensure-Ntttcp {

param([ipaddress]$SystemIP)

$path = "\\$SystemIP\C\$\Temp\ntttcp\ntttcp.exe"`

if (!(Test-Path $path -ErrorAction SilentlyContinue)) {

Write-Host "[$SystemIP] Missing ntttcp.exe, copying..." -ForegroundColor Red

New-Item -Path (Split-Path $path) -ItemType Directory -Force | Out-Null

Copy-Item ".\ntttcp\ntttcp.exe" $path -Force

} else {

Write-Host "[$SystemIP] Found ntttcp.exe" -ForegroundColor Green

}

}

foreach ($ip in @($ServerIP, $ClientIP)) {

Write-Host "Checking [$ip] availability..." -ForegroundColor Cyan

if (!(Test-Connection $ip -Count 2 -Quiet)) {

Write-Host "Not Available: $ip" -ForegroundColor Red

return

}

Write-Host "Available: $ip" -ForegroundColor Green

Ensure-Ntttcp $ip

}

if (!(Test-Path $ExportPath)) {

New-Item -Path $ExportPath -ItemType Directory -Force | Out-Null

}

$ServerIPString = $ServerIP.IPAddressToString

$ClientIPString = $ClientIP.IPAddressToString

try {

$serverName = (Resolve-DnsName $ServerIP -ErrorAction Stop).NameHost

} catch {

$serverName = $ServerIP.IPAddressToString

}

Write-Host "Starting Server on $serverName" -ForegroundColor Cyan

$serverScript = {

`Start-Process "C:\Temp\ntttcp\ntttcp.exe" ``

`-ArgumentList "-r -m $Using:ServerCPUs,*,$Using:ServerIPString -t $Using:Time" ``

-NoNewWindow

}

$serverSession = New-PSSession -ComputerName $serverName

Invoke-Command -Session $serverSession -ScriptBlock $serverScript

$clientResult = $null

if ($RunClient) {

try {

$clientName = (Resolve-DnsName $ClientIP -ErrorAction Stop).NameHost

} catch {

$clientName = $ClientIP.IPAddressToString

}

Write-Host "Starting Client on $clientName" -ForegroundColor Cyan

$clientScript = {

$outFile = "C:\Temp\ntttcp\ntttcp_client_output.txt"

`Start-Process "C:\Temp\ntttcp\ntttcp.exe" ``

`-ArgumentList "-s -m $Using:ServerCPUs,*,$Using:ServerIPString -t $Using:Time" ``

-NoNewWindow -Wait -RedirectStandardOutput $outFile

$raw = Get-Content $outFile

# Totals section

$totalsIndex = ($raw | Select-String "Bytes\(MEG\)").LineNumber

$bytesMeg = $realtimeSec = $avgFrameSize = $throughputMb = $throughputGb = $null

if ($totalsIndex) {

$valuesLine = $raw[$totalsIndex+1]

$parts = $valuesLine.Trim() -split "\s+"

$bytesMeg = [double]$parts[0]

$realtimeSec = [double]$parts[1]

$avgFrameSize = [double]$parts[2]

$throughputMb = [double]$parts[3]

$throughputGb = ($throughputMb * 8) / 1024

}

# Packets section

$packetsIndex = ($raw | Select-String "Packets Sent").LineNumber

$packetsSent = $packetsRecv = $retransmits = $errors = $cpuUsage = $null

if ($packetsIndex) {

$valuesLine = $raw[$packetsIndex+1]

$parts = $valuesLine.Trim() -split "\s+"

$packetsSent = [int]$parts[0]

$packetsRecv = [int]$parts[1]

$retransmits = [int]$parts[2]

$errors = [int]$parts[3]

$cpuUsage = [double]$parts[4]

}

return [PSCustomObject]@{

Machine = $env:COMPUTERNAME

TimeRun = Get-Date

BytesMeg = $bytesMeg

RealtimeSec = $realtimeSec

AvgFrameSize = $avgFrameSize

ThroughputMb = $throughputMb

ThroughputGb = $throughputGb

PacketsSent = $packetsSent

PacketsRecv = $packetsRecv

Retransmits = $retransmits

Errors = $errors

CPUPercent = $cpuUsage

RawOutput = ($raw -join "\n")`

}

}

$clientSession = New-PSSession -ComputerName $clientName

$clientResult = Invoke-Command -Session $clientSession -ScriptBlock $clientScript

}

if ($serverSession) { Remove-PSSession $serverSession }

if ($clientSession) { Remove-PSSession $clientSession }

if ($clientResult) {

# Console summary

Write-Host ("Summary: {0} MB/s ({1:F2} Gbps), Avg Frame {2} bytes, Packets Sent {3}, Recv {4}, Retrans {5}, Errors {6}, CPU {7}%" -f $clientResult.ThroughputMb,

$clientResult.ThroughputGb,

$clientResult.AvgFrameSize,

$clientResult.PacketsSent,

$clientResult.PacketsRecv,

$clientResult.Retransmits,

$clientResult.Errors,

$clientResult.CPUPercent) -ForegroundColor Yellow

$csvFile = Join-Path $ExportPath "ntttcp_results.csv"

$jsonFile = Join-Path $ExportPath "ntttcp_results.json"

if ($ExportCsv) {

$clientResult | Select-Object Machine,TimeRun,BytesMeg,RealtimeSec,AvgFrameSize,ThroughputMb,ThroughputGb,PacketsSent,PacketsRecv,Retransmits,Errors,CPUPercent |

Export-Csv -Path $csvFile -Append -NoTypeInformation

Write-Host "Results exported to CSV: $csvFile" -ForegroundColor Cyan

}

if ($ExportJson) {

$existingJson = @()

if (Test-Path $jsonFile) {

$existingJson = Get-Content $jsonFile | ConvertFrom-Json

}

$allResults = $existingJson + $clientResult

$allResults | ConvertTo-Json -Depth 3 | Set-Content $jsonFile

Write-Host "Results exported to JSON: $jsonFile" -ForegroundColor Cyan

}

return $clientResult

}

}


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

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