r/PowerShell • • Nov 18 '25

Question Pull out a section of code from a PS1

5 Upvotes

I have a PS1 file that includes a very large custom object (arrays of objects of arrays of objects). The file also contains functions and actual code. I don't control the file contents or code.

I have the need to extract just the custom object from the script. I can't execute the script to get the object data because that will also execute the code and functions in the script. I need to actually extract just the object part.

The intention is that I can run just the section where the object is set, and then I can create an output script that parses that object into a CSV for reporting.

Here is kinda what the code looks like, in general (it is 100's of lines long and I can't paste it):

params ([string]$param)
import-module -Name MainModule

$Config = @(
  [pscustomobject]@{
    forest=@('contoso','microsoft')
    domains = @('child1','child2')
    configurations = @(
      [pscustomobject]@{
        more='stuff'
        even='morestuff'
      }
    )
  }
  ....
)

Get-Function1 {
}

Get-Function2 {
}

$Variable='x'
$Date = Get-Date
Get-Function1
Write-Host 'done'

r/PowerShell • • Nov 18 '25

Question Help for simple command or script to extract all possible date info from ~1000 audio/video files for a documentary that I’ve stored on an external SSD?

4 Upvotes

I’ve recorded an audio/video podcast-style documentary and I have ADHD, so things got pretty messy. Id like to get an overview and dates to organize a timeline on whats copied and whats not.

I have tons of files: WAVs (inside parent folders with varying naming conventions after I changed system language), M4A, MP4, etc. Most of it is on an external SSD.

Some files have a sensible creation date, others have a media creation date, others seem to inherit the parent folder date, and some probably have other kinds of date info attached.

I need to sort and organize everything, and also figure out what I still need to download from backups in OneDrive and Google Photos.

As you might guess, I’m not very organized. I tried using ChatGPT to get a PowerShell command for this, but it keeps hallucinating and giving me broken stuff.

Can someone help me with a non-destructive command or script that will produce a file list with at least:

Location / full path

Folder (if relevant)

File name

All available date fields

(And maybe other useful metadata)

Thanks!


r/PowerShell • • Nov 18 '25

How do you update help files for connect-ippssession?

4 Upvotes

Hi All,
Point me to a different subreddit if this isn't a good place but how do you update the help file for connect-ippssession? I've tried update-help as admin (with force too), I've reinstalled the exchangeonlinemanagement module. Everything I try seems to execute OK and without errors but nothing seems to get it current with the online version

What am I missing?

Side rant.... hate all the depreciation of commands and mggraph. I'm having a really hard time getting it.


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