r/PowerShell • • 7d ago

News New Rule - AI Disclosure

287 Upvotes

If you are posting a script, tool, or anything else you’ve used AI, LLM or whatever to make, it must be disclosed. This includes anything from complete authorship, formatting, comments, or language/translation assistance.

If your script or content is suspected of being AI written and it is not disclosed in a tag or at the top of the post, it will be removed until investigated.

Community: This is at your request. Report any undisclosed suspected AI “slop” for investigation.

EDIT: I’m going to be clear. We’re not saying you can’t post AI created stuff. We’re saying you have to disclose that you are. If you have a problem with that, you’re not proud of the fact you used an AI tool. You’re deceiving people into thinking you wrote it. Anyone who uses whatever AI wrote deserves to know and take the diligence necessary to review it before using it, same as they would anything else.


r/PowerShell • • 20d ago

Script Sharing What have you done with PowerShell this month?

20 Upvotes

A sticked post for the community to share their projects throughout the month.

Make sure to post a link to the code!


r/PowerShell • • 16m ago

Question Get current logged on User from System context script

• Upvotes

I need to query the current logged on user and then write the info in HKLM registry for branding. Does anyone have a script or idea how this will work when the script is deployed from SCCM/Intune with System Context?


r/PowerShell • • 8h ago

AI Disclosure agent-manager runs natively on windows now (psmux + pwsh 7), a keyboard tui for running all your ai coding agents [OC, i'm the dev]

2 Upvotes

i'm the dev, so this is a show and tell. ai disclosure per rule 11, built largely with claude code, i review and test everything. agent-manager is a local terminal app that connects to your existing subscriptions and tools and runs your ai coding clis side by side, each in its own session, in one list with live status (working, waiting on you, finished, errored). it supports claude code, codex, opencode, grok build, gemini cli, antigravity cli, pi, hermes agent, muse code and oh my pi natively on windows. the 11th, command code, only works under wsl2 because its name clashes with cmd.exe.

until last week it was tmux only, so windows meant wsl. as of 0.42 you get both. natively, psmux 3.4+ stands in for tmux and powershell 7.3+ is the pane shell (a contributor, larroy, did most of the port). or keep using wsl2 like before, on tmux inside the distro.

the native install is one line, read the script first if piping to iex bothers you

irm https://raw.githubusercontent.com/YoanWai/agent-manager/main/install.ps1 | iex

it goes to %LOCALAPPDATA%\Programs\agent-manager, adds itself to your user path, and tells you the winget command for psmux, git or pwsh 7 if one is missing. windows powershell 5.1 is refused on purpose, it splits prompts containing quotes into several arguments.

what you get once it's running is keyboard driven. space sends a prompt into any agent without attaching, x kills a session to free its ram and v revives it on the same conversation, and ctrl+r opens a full-file diff review where c comments a line and C sends every comment back to the agent. it's one go binary, no electron or browser.

there's also agent-manager settings list/get/set for scripting your setup, and notify_command runs a powershell command every time an agent needs you (docs have an ntfy push example using $env:AM_BODY).

known gaps on native windows: previews poll instead of stream, and agent clis installed only as .cmd/.bat are refused (npm installs are fine). if it misbehaves with your profile or psmux version i'd like to hear about it.

https://github.com/YoanWai/agent-manager


r/PowerShell • • 23h ago

Question PowerShell Script and Task Scheduler 0x1 2147942401

8 Upvotes

I need a sanity check, as I feel like I am missing something obvious and I'm too close or too frustrated to see it.

I have a basic scheduled task. Runs as SYSTEM, no triggers, action to run a program, PowerShell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "C:\Tasks\MyScript.ps1"

I run this task it fails, 0x1 as last run result, event 201 action completed with return code from PowerShell of 2147942401

Things I have checked:

  • SYSTEM can access the script and directory it resides in
  • SYSTEM can execute other PowerShell scripts from task scheduler without issues
  • Tried using the full path to powershell.exe
  • Tried with and without quotes around the script path in -File parameter
  • With and without trailing '/' in the path for 'Start In'
  • Tried using -Command { } to create a file as a test
  • Removed all arguments except -File or -Command
  • Script is wrapped with Start/Stop-Transcript; never executes/no transcript is created

I don't know what else to try short of the old method of using a .bat to call PowerShell to see if that gives better clues as to what isn't working.

What am I missing that is preventing PowerShell from executing properly?


r/PowerShell • • 1d ago

Script Sharing EoL Dependency Auditing Script For Vulnerability Remediation Work

8 Upvotes

I've been doing a bit of vulnerability remediation work this past year or so, and I got tired of 'scream tests' across multiple environments, and was unable to affectively find a way to use something like Dependency Walker in a set-it-and-forget-it kind of way, so I built out the following:

https://github.com/cmcalgher/EoL-Dependency-Auditing

This will set the auditing-side of ACL's on specified .DLL files (configured in the CSV's), and will then allow you to parse through the last 24 hours of the security event log to pull instances of processes that touched/acted on those .DLLs.

When ran on individual machines, it will spit out a CSV with a handful of columns, that can be fed into whatever formatting/reporting you see fit.

Internally at the org I work for, we were pretty much immediately able to write off Visual C++ 2012 as accepted risk on our fully up to date on-prem Exchange SE servers, for example. Would Exchange keep working if we had ripped that off? Would we have to restore corrupted DBs? Not sure, but with how many Exchange processes were using those Visual C++ 2012 .DLL's, I'm glad I didn't have to find out.

The above was inspired by the following Microsoft article, detailing how to audit VC++ usage in coding projects:

https://learn.microsoft.com/en-us/cpp/windows/redist-version-auditing?view=msvc-170


r/PowerShell • • 1d ago

Question Methods of a class that's not instanced

3 Upvotes

Hi there,

i can't seem to find relevant informations for this particular topic using my own google skills so maybe someone here can shed some light on this.

if i use a class that doesen't provide any methods without creating an instance of it, but i skip creating an instance via "new().SomeMethod", will this leak memory?

example, sending an async ping to some host without creating a $Ping Object first:

[System.Net.NetworkInformation.Ping]::new().SendPingAsync($IPAddress)

Usually one would create a $Ping object, ping something and in the end, dispose of the $Ping to free the ressources.

If the SendPingAsync Method could work without an instance of the class, the class probably would have some static method's providing the mechanism. So an instance is probably created somewhere but that instance is probably not automatically disposed after the fact?

Can this method be used without worries or should such trickery be avoided?

thanks in advance


r/PowerShell • • 1d ago

News Why the Microsoft Graph PowerShell SDK has Two Cmdlets to Add Group Members

2 Upvotes

It’s a consequence of how the Microsoft Graph PowerShell SDK is built that two cmdlets are available to add members to Entra ID groups (the same is true for group owners). The reason why the New-MgGroupMember and New-MgGroupMemberByRef cmdlets exist is down to how the Graph SDK build process constructs cmdlets from Graph metadata. The Graph exposes two ways to add new group members, so the SDK follows suit.

https://office365itpros.com/2026/10/20/group-member-sdk-cmdlets/


r/PowerShell • • 2d ago

News Microsoft to Retire the Search-UnifiedAuditLog Cmdlet in 2027

30 Upvotes

MC1505599 covers two big announcements. First, the AuditLogQuery Graph API is GA. Second, Microsoft will retire the heavily used Search-UnifiedAuditLog cmdlet in October 2027. Microsoft hasn’t said why they want to retire Search-UnifiedAuditLog and have tenants convert their PowerShell scripts to use the AuditLogQuery API but reducing engineering cost and complexity are probably at the heart of the matter. In any case, the conversion will cost Microsoft 365 development effort and money between now and October 2027, and that’s a bad thing.

https://office365itpros.com/2026/10/19/search-unifiedauditlog-retirement/


r/PowerShell • • 3d ago

Question alias ls works but alias doesn't exist anywhere — what is it?

8 Upvotes

Title:

On PowerShell 5.1 (Windows 11 24H2, build 26100.9711), running alias ls gives valid output:

PS C:\> alias ls

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           ls -> Get-ChildItem

But every way I know to look it up says it doesn't exist:

Get-Alias alias          # ItemNotFoundException
Get-Command alias        # CommandNotFoundException
Get-Command -Name 'alias' -CommandType Alias, Function, Cmdlet -ErrorAction SilentlyContinue  # returns nothing
Get-Item Alias:\alias -ErrorAction SilentlyContinue  # returns nothing

No $PROFILE exists. Only standard modules are loaded. What is alias actually doing here?


r/PowerShell • • 4d ago

Script Sharing Open MS Office files in Office Online with a simple double click - NOW POSSIBLE! - Powershell to the Rescue~

0 Upvotes

I dug around the internet for a solution and couldn't find anything worth diving into. Even the one "paid" solution (Files App) that I read might be able to do it, didn't seem like it could when I tested it and it also would be a pain to deploy at any scale but your own computer.

So I did what any developer minded IT person would do and dug through open source solutions, still nothing but one for the completely wrong OS (https://github.com/bewithdhanu/office-online-bridge-macos). This project gave me the idea to try porting the same work around to Windows. I sort of did it. Basically the same idea but used the existing "View Online" function from the context menu and wrote a PowerShell script to execute it. The script was then improved with an exe wrapper to make it more user friendly.

I am pretty surprised this solution hasn't been made before, but here it is now! (AI Disclosure: I wrote the readme using AI and used it to help create my exe wrappers via the compile.ps1 script. All other components were written largely by me with some assistance from AI to grab basic methodology on getting/triggering functions from the context menu)

https://github.com/Fireant456/M365-Bridge

It is bundled with an installer that can be deployed silently. Only requirement (at the moment) is that your files you are attempting to open must be in a OneDrive synced folder. If they are not an error will tell you they need to be. I might work to add automatic handling of uploading files to a temporary OneDrive directory and writeback to the original location in order to seamlessly handle non-synced file editing, but I don't require that in my use case. Happy to take pull requests if anyone wants to give it a shot.

Would love any feedback. Enjoy!


r/PowerShell • • 5d ago

Solved Gathering meter reads from Konica printers.

15 Upvotes

(I'll start by admitting that some of my PoSh may be unconventional / and abbreviated - I have embraced it accordingly).
(Edit - I discovered some discrepancies and found additional OID's that count towards both 'Black' and 'Color' totals - Added: "ScanFax_Black" and "Copy_SingleColor")

I needed to come up with a way to create some logs of the usage on the fleet of 10 Konica printers across four locations / print servers.

These logs will be used to validate the pricing figures our printer support vendor provides (pricing is based on estimated / averaged usage per device - that data is audited on a quarterly basis, via automated auditing tools on each print server - FM Audit).

Currently - Without any of our own historical data - We have to take the vendors word, that those quarterly averages are 'OK'...

So, someone from accounting asked me for help.

The below script collects settings info for all of the Konica printers on each of the print servers, then uses the 'PortName' (IP address) to run an SNMP query on each device (SNMP must be enabled in the devices network settings).

The critical items are the OID's.

Figuring out which ones pull in the values for 'black' and for 'color' were the first challenge.

Once I got that figured out - It took me a while to find the OID that gathers the devices serial number - I could NOT find this documented anywhere, and AI (Copilot, Gemini, Claude) wasn't able to either.

For this last bit - I ended up walking (snmpwalk) through ALL 7125 OID's to locate the one that gathers the serial number.

wsl snmpwalk -v2c -c public <printer IP> 1.3.6.1 > 'C:\Users\richie\Documents\PoSh_Stuff\OID_walk.txt'

And looking for the serial number I already knew for that printer.

Select-String -Path 'C:\Users\richie\Documents\PoSh_Stuff\OID_walk.txt' -Pattern '<SerialNumber>'

OID_walk.txt:460:iso.3.6.1.2.1.43.5.1.1.17.1 = STRING: "<SerialNumber>"

Posting what I figured out.

I will pipe '$Report' to a Csv, and save it accordingly.

I'll be scheduling this to run on a quarterly basis - And handing the Csv's over to accounting when they ask for them.

$AllKonica = @()

("Site1,site2,site3,site4").Split(',') | % {
    If (Test-Connection $_ -Count 1 -ErrorAction SilentlyContinue) {
    $AllKonica += Get-Printer -ComputerName $_ | ? { $_.DriverName -match 'Konica' -and $_.PortName -NOTmatch "portprompt|microsoft|_"} | Select ComputerName, Name, PortName, DriverName 
    } 
}

# (NOTE: You could also just list the name, and port name - This removes the need to use domain auth for the script - Since SNMP does not reqiure authentication)

<#
$AllKonica = @"
"Name","PortName"
"S1-PTR-066","192.168.1.66"
"S1-PTR-062","192.168.1.62"
"S1-PTR-061","192.168.1.61"
"S1-PTR-060","192.168.1.60"
"S1-PTR-064","192.168.1.64"
"S2-PTR--034","192.168.2.34"
"S3-PTR-060","192.168.3.60"
"S3-PTR-061","192.168.3.61"
"S4-PTR-068","192.168.4.68"
"S4-PTR-066","192.168.4.66"
"@ | ConvertFrom-Csv
#>

$OIDs = [Ordered]@{
    "Model"            = ".1.3.6.1.4.1.18334.1.1.1.3.5.2.2.0"
    "SerialNo"         = ".1.3.6.1.2.1.43.5.1.1.17.1"
    "Total"            = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.1.1.0"
    "Print_Black"      = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.1.2"
    "Copy_Black"       = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.1.1"
    "ScanFax_Black"    = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.3.1.7.1"
    "Copy_SingleColor" = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.3.1"
    "Print_Color"      = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.2.2"
    "Copy_Color"       = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.2.1"
    "Print_2Color"     = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.4.2"
    "Copy_2Color"      = ".1.3.6.1.4.1.18334.1.1.1.5.7.2.2.1.5.4.1"
}

$Report = @()
$SNMP_Community = "public"
$AllKonica | % {

$PrinterIP = $_.PortName  
$PrinterName = $_.Name

If (Test-Connection $PrinterIP -Count 1 -ErrorAction SilentlyContinue) {

$snmp = New-Object -ComObject OlePrn.OleSNMP

try {
    $snmp.Open($PrinterIP, $SNMP_Community, 2, 1200)
    $Data = [Ordered]@{ "Printer" = "$PrinterName - $PrinterIP" }

foreach ( $Key in $OIDs.Keys ) {
    try { $Value = $snmp.Get($OIDs[$Key])
         if ( $null -eq $Value -or $Value -eq "" ) 
         { $Data[$Key] = 0 }
         #{ $Data[$Key] = $null }
          else { $Data[$Key] = $Value }
    } # END 'try' # 2
    # catch { $Data[$Key] = $null }
    catch { $Data[$Key] = 0 }
} # END 'foreach ($Key in $OIDs.Keys)'

$TotalColor = 0; $OIDs.Keys | ? { $_ -match "color" } | %  { $TotalColor += [int]$Data["$_"] }
$TotalBlack = 0; $OIDs.Keys | ? { $_ -match "black" } | %  { $TotalBlack += [int]$Data["$_"] }

$Report += [PSCustomObject][Ordered]@{
"Model"    = $Data["Model"]
"SerialNo" = $Data["SerialNo"]
"Printer"  = $Data["Printer"]
"Total"    = $Data["Total"]
"Black"    = $TotalBlack
"Color"    = $TotalColor
    }
} # END 'try' # 1

catch { Write-Host "Connection failed: $PrintServer -> $PrinterIP ($PrinterName)" -F 14 }
finally { $snmp.Close() }

} # END 'If (Test-Connection...'

else {
    $Report += [PSCustomObject][Ordered]@{
        "Model"    = "Unk"
        "SerialNo" = "Unk"
        "Printer"  = "$PrinterName - Unreacheable"
        "Total"    = "NULL"
        "Black"    = "NULL"
        "Color"    = "NULL"
    }
} # END 'else'

} # END '$AllKonica | %'

$Report | ft

r/PowerShell • • 5d ago

Question REPOST Issue with $PROFILE function

2 Upvotes

Hello everyone. I hope you are having a good time.

function gethash {

param([string]$string = "")

if ($string -eq [string]::Empty -or $string -isnot [string])

{

Write-Output "input not valid"

}

else

{

(Get-FileHash -algorithm sha256 $string).Hash | tee -Variable b

}

}  

I Have this function in my $Profile script. when i run gethash something it returns the hash string as expected, but when I try to print the variable containing the hash i just obtained from the piped command: tee, (alias of Tee-Object) with `$b

it prints nothing, the variable is not saved.

on the other hand, if i copy the exact same command from the $profile function directly through the terminal, $b prints what expected: the hash of the file.

I haven't used this function so much, but I'm pretty sure it worked before today.

Thanks in advance to any who will respond.


r/PowerShell • • 5d ago

Question Function Issue in $PROFILE path

1 Upvotes

Hello everyone. I hope you are having a good time.

```powershell

function gethash {

param([string]$string = "")

if ($string -eq [string]::Empty -or $string -isnot [string])

{

Write-Output "input not valid"

}

else

{

(Get-FileHash -algorithm sha256 $string).Hash | tee -Variable b

}

}
```

I Have this function in my $Profile script. when i run gethash something it returns the hash string as expected, but when I try to print the variable containing the hash i just obtained from piped command tee, (alias of Tee-Object) as an input with `$b

it prints nothing, the variable is not saved.

on the other hand, if i copy the exact same command from the $profile function directly through the terminal, $b prints what expected: the hash of the file.

I haven't used this function so much, but I'm pretty sure it worked before today.

Thanks in advance to any who will respond.


r/PowerShell • • 6d ago

News Microsoft Graph PowerShell SDK V2.41.2

10 Upvotes

Microsoft released V2.41.2 of the Graph PowerShell SDK on 14 October. This version fixes the problem with versions of PowerShell older than 7.6. Azure Automation runbooks execute successfully in a PowerShell 7.4 runtime environment with the 2.41.2 modules.


r/PowerShell • • 6d ago

Question Compare-Object unexpected results

8 Upvotes

Hi all,

I recently posted here with a question about using Compare-Object to compare two CSV files.

There were some great suggestions in that thread and I was able to get the functionality I needed to create a summary of items that were present in the Reference Object, but not present in the Difference Object.

Having applied this to my real datasets, I'm now getting unexpected behaviour when trying to summarise the entries that have been added and / or changed (NOT present in Ref Object, present in Dif Object).

Basically, I have a fairly large CSV file that is re-produced periodically, and each time it's reproduced, I need to summarise the changes from the previous file to the new one.

Generally, the CSV has about 40 columns and about 8000 rows. The first column always contains a value unique within the file.

In my testing, I have added a single row to the Difference Object. All other rows are exactly the same. The added row is around row 4500.

So old file = 8000 rows.
New file = 8001 rows, with the new item at row 4500, other 8000 rows unchanged.

I'm running the following:
("@files" is only in quotes to stop Reddit formatting it as a user tag)

$files = @{
ReferenceObject = (Get-Content -Path $OldFile)
DifferenceObject = (Get-Content -Path $NewFile) }

Compare-Object "@files" |
    ?{$_.SideIndicator -eq '=>'} |
        export-csv $ResultsFile -NoTypeInformation

This works if an existing row between the files has one of its column values changed. But when a row is added from old file to new file, I don't just get the added row in my results - in my tests at the moment I'm getting about 700 rows returned as new in $newfile vs $oldfile.

I must be missing something and this is expected, but I'm not sure why it's picking up that many rows as changed when manually comparing those rows shows them to be exactly the same.


r/PowerShell • • 6d ago

Information agent manager 0.42 runs natively on Windows with psmux and PowerShell 7

2 Upvotes

we released 0.42 of agent manager. we are the creators. it is a free open source go TUI that runs coding agent CLIs side by side, each in its own session, with live status and diff review.

this one is Windows. we added support for running natively on Windows with psmux 3.4 or newer in place of tmux and PowerShell 7.3 or newer as the pane shell. you do not need WSL for the TUI itself. Command Code on native Windows still uses WSL2.

also added a notify_command setting that runs a shell command on every notification, and an agent-manager settings CLI to read or change any setting from the shell.

Windows install irm https://raw.githubusercontent.com/YoanWai/agent-manager/main/install.ps1 | iex

https://github.com/YoanWai/agent-manager/releases/tag/v0.42.0


r/PowerShell • • 7d ago

Question Computer Lab Firewall Rule Toggle Script

6 Upvotes

I work for an MSP and we have a client that has a computer lab for students to use. I was tasked with creating a script that would allow the teacher to enable and disable the workstations ability to communicate with the internet.

I pretty much have most of the script working, but I run into an issue when trying to make it so the user can enable or disable all the workstations at once. Attempted various methods so that when the user types All, the invoked command is sent to all the workstations listed; Get-Content is just the latest method I have tried.

When my boss asked to look at it, he said that I should just have the full command as shown at the bottom for each switch.

Any help on this would be great!

EDIT: Additional Information.

We don't have an AD environment setup for this client, and even with my limited knowledge I understand that AD would probably make this a lot easier.

IP Addresses are used due to the Asset ID of the workstations being used as the Host Name. They are also used because the workstations have static addresses and any replacements will get the same addresses.

#First Pull Username and Password from SecretVault for Account on all workstations
$remoteCred = Get-Secret -Name "Alias"


#Prompt to ask user if they are enabling or disabling workstations.
$prompt = Read-Host -Prompt "Enter E for enable and D for disable"


#Determine which command to use based on provided answer
if ($prompt -eq "E") {
    $command = "Disable-NetFirewallRule -DisplayName 'NoInternet'"
}else {
    $command = "Enable-NetFirewallRule -DisplayName 'NoInternet'"
}

#Use while to re-prompt user if they are enabling or disabling multiple workstations.
while ($true) {
$pcName = Read-Host -Prompt "Enter the name of the Computer you want to change. Or enter All if you wish to change all. Enter exit when finished"


#Use switch to base workstation name on user imput. All will use variable for all workstations.
switch ($pcName) {
    "SW1" { $name = "192.168.100.211" }
    "SW2" { $name = "192.168.100.212" }
    "SW3" { $name = "192.168.100.213" }
    "SW4" { $name = "192.168.100.214" }
    "SW5" { $name = "192.168.100.215" }
    "SW6" { $name = "192.168.100.216" }
    "SW7" { $name = "192.168.100.217" }
    "SW8" { $name = "192.168.100.218" }
    "SW9" { $name = "192.168.100.219" }
    "SW10" { $name = "192.168.100.220" }
    "SW11" { $name = "192.168.100.221" }
    "SW12" { $name = "192.168.100.222" }
    "SW13" { $name = "192.168.100.223" }
    "SW14" { $name = "192.168.100.224" }
    "SW15" { $name = "192.168.100.225" }
    "SW16" { $name = "192.168.100.226" }
    "All"  { $name = '(Get-Content -Path "C:\Users\userx\Desktop\Scripts\Workstations.txt")'}
    "Exit" { 
        exit }
    Default { Write-Host "Please try again." }
    }
    Invoke-Command -ComputerName $name -ScriptBlock { $command } -Credential $remoteCred
    if ($pcName -eq "Exit" -or "All") { break }
}


#Invoke-Command -ComputerName "$name" -ScriptBlock {Disable-NetFirewallRule -DisplayName "NoInternet"} -Credential $remoteCred

r/PowerShell • • 7d ago

Script Sharing I built a free PowerShell tool to find out where all the storage in a Microsoft 365 tenant is going

3 Upvotes

I've been working on a PowerShell 7 script to help us understand exactly how much storage our Microsoft 365 tenants are consuming.

It started as a way to estimate Microsoft 365 backup requirements, but evolved into something more useful.

The script collects storage information from Exchange Online (including online archives), OneDrive, and SharePoint, including Teams-connected file storage.

It produces a console summary, CSV export, and a standalone HTML report with charts and storage breakdowns.

There's also an optional backup cost estimator.

I've tested it against a couple of production tenants, including comparisons between the Fast and Exact Exchange measurement modes. Results were reasonably close.

I've released it under the MIT license, along with documentation and a sample report.

If anyone finds it useful, I'd welcome feedback, bug reports, or suggestions for improvements.

GitHub: [M365 Tenant Storage Assessment]()


r/PowerShell • • 6d ago

Script Sharing PrtgSensorKit 1.5: credential masking, crash-safe state and stricter error handling

0 Upvotes

AI disclosure: PrtgSensorKit is developed with Claude Code. I plan and review every change myself, and every release is tested properly including a real PRTG probe.

Hey r/PowerShell,

Back in July I posted PrtgSensorKit here (original thread), a module for writing PRTG custom sensors without the boilerplate. Here's what changed since 1.2.0.

Credential masking

PRTG resolves credential placeholders before it displays the output, so a failing Invoke-RestMethod that prints the full URI can show your password in the sensor message. The module now masks resolved PRTG credentials and Get-PrtgSecret values in messages, errors and log files. Nothing to configure.

Crash-safe state, secrets and cache

PRTG kills sensors on timeout. If that hit mid-write, you could lose the state history, a cached result or a secret. All writes now go to a temp file that gets swapped in, so a killed run leaves the old data intact.

Failing sensors now actually fail

Invoke-PrtgSensor claimed to set $ErrorActionPreference = 'Stop' inside your block, but it never reached it. Non-terminating errors were swallowed and the sensor stayed green with stale or missing channels. That's fixed, so some sensors may turn red after the upgrade because they were hiding real failures. Use -ErrorAction on a command if it should keep failing quietly.

Smaller changes

  • New-PrtgChannel accepts UInt64 and the other unsigned types, so CIM/WMI sizes and counters work without casting
  • -Verbose no longer adds "Verbose":1 to the sensor JSON
  • Duplicate channel names are rejected, since PRTG requires them to be unique
  • -MaxLogs retention only deletes the module's own log files, not unrelated .log files in the same folder
  • The secret store no longer locks out other sensor accounts on the same probe
  • Set-PrtgMessage takes pipeline input

Every release is now tested on Windows PowerShell 5.1 (x86 and x64) and pwsh 7, plus integration sensors on a real PRTG probe.

Update-Module PrtgSensorKit. Read the changelog before upgrading production: the error handling fix and the duplicate channel check can turn sensors red on purpose.

Repo: https://github.com/ArchitektApx/PrtgSensorKit

One thing I'm considering for a future release: requiring channels to come from New-PrtgChannel so parameters can use [PSTypeName('PrtgSensorKit.Channel')], as u/surfingoldelephant suggested in the last thread. That would break hand-built channel objects. Does anyone actually build channels by hand?

At this point the module covers everything I need for my own sensors, so the next features depend on what other people run into. If you're using it, or tried it and gave up, I'd like to hear what's missing or annoying.


r/PowerShell • • 7d ago

News Tracking File-Level Archiving Activity in SharePoint Online with PowerShell

5 Upvotes

File-level archiving is now generally available and can be applied to files automatically, by users through the SharePoint browser UX, or via a Graph API. The big problem with Purview retention processing is its black box nature, so to discover how effective retention labels with an archiving step are, we use the Microsoft Graph PowerShell SDK to check the archiving status of files and report the results via email. All in a nice script, of course.

https://office365itpros.com/2026/10/14/file-level-archiving-report/


r/PowerShell • • 7d ago

Question Modernizing a Legacy PowerShell Mining Automation Project (SWARM) – Looking for Technical Advice and Open-Source Collaboration

1 Upvotes

Hello r/PowerShell!

I'm working on an open-source project called SWARM, originally developed by MaynardMiner. SWARM is a PowerShell-based cryptocurrency mining management and automatic profit-switching application.

I've forked the project as part of my personal mining infrastructure project, MazufaMine, in Finland.

Project repository: https://github.com/Mazufa/SWARM

Modernization discussion: https://github.com/Mazufa/SWARM/issues/1

I'm building a Linux-based mining environment with approximately 30 AMD Radeon RX 580 8GB GPUs across multiple rigs. I've already successfully established GPU mining using HiveOS and GMiner.

However, I'd like to explore how SWARM could be comprehensively modernized into a reliable, maintainable and actively developed PowerShell application.

I'm particularly interested in advice from experienced PowerShell developers who have worked with large legacy codebases, cross-platform automation and open-source maintenance.

Areas that need investigation and modernization

1. Complete codebase audit

  • Review the existing PowerShell architecture and identify technical debt.
  • Identify obsolete, deprecated, insecure or broken components.
  • Improve code organization, performance and maintainability.
  • Evaluate opportunities for safe refactoring.

2. PowerShell 7 and Linux compatibility

  • Review compatibility with current PowerShell versions.
  • Improve Linux support and installation procedures.
  • Investigate modern HiveOS integration.
  • Improve cross-platform behavior and dependency management.

3. External tools and integrations

  • Update outdated mining software integrations and download URLs.
  • Review mining pool and profitability APIs.
  • Update obsolete algorithms and configurations.
  • Improve benchmarking and automatic profitability switching.

4. Electricity pricing and automation

  • Investigate integration with Finnish Nord Pool electricity prices.
  • Support 15-minute electricity pricing intervals.
  • Include electricity transmission charges and taxes.
  • Enable automated profitability-based mining decisions.

5. Reliability and monitoring

  • Improve error handling and structured logging.
  • Investigate GPU monitoring and failure detection.
  • Implement safe recovery mechanisms.
  • Improve testing, validation and troubleshooting.

6. Long-term maintainability

  • Establish a modernization roadmap.
  • Introduce automated testing where practical.
  • Improve documentation and reproducible releases.
  • Make the project easier for future open-source contributors to maintain.

What I'm hoping to learn

I'm not an experienced software developer, so I would appreciate guidance on the best approach to modernizing a project of this size.

In particular:

  1. How would you approach a complete technical audit of an older PowerShell application?
  2. Which tools would you recommend for identifying compatibility issues and technical debt?
  3. What would be the best way to modernize a cross-platform PowerShell application without breaking existing functionality?
  4. How should automated testing and dependency management be introduced?
  5. Are there existing PowerShell frameworks, modules or open-source projects that could simplify this modernization?
  6. Has anyone here worked on similar legacy PowerShell modernization projects?

I'm also interested in connecting with open-source contributors who have experience in this area and enjoy discussing or improving existing projects.

I can provide real hardware testing, logs, configuration feedback and project coordination.

My ultimate goal is to preserve SWARM's existing functionality while making the entire application modern, reliable and maintainable.

Any technical advice, relevant GitHub projects, recommendations or experiences would be greatly appreciated.

Thank you!


r/PowerShell • • 8d ago

Solved How to Retrieve SharePoint Sites with the Microsoft Graph PowerShell SDK

20 Upvotes

If you use the Microsoft Graph PowerShell SDK, you might know that the Graph APIs for SharePoint sites sometimes need a little help. For instance, finding a set of sites to process can be problematic because the APIs do not support extensive filtering capabilities. The solution is to use other Microsoft 365 cmdlets to find objects associated with sites. Inserting an intermediate step might seem crazy, but it can be the most effective way of solving the problem.

https://office365itpros.com/2026/10/13/get-sharepoint-sites/


r/PowerShell • • 9d ago

Misc I made a <slop>

145 Upvotes

Maybe I'm just jaded but I can't help but get annoyed when half the posts I see are someone saying they made some <buzzword + thing>, and that thing happens to be some 10000 line, 40 file vibe coded tool solving a problem one person had, once, often in the convoluted way the AI could come up with. Worse, when they cannot even answer questions about it themselves so you end up with AI responses to any genuine interest in the goal.

We have the script sharing tag, but that was there before we had this absurd volume of AI submissions and it feels like the average post quality of the sub is suffering because of it.

Am I in the minority here? Would it be better to have a separate sub for all of these? My favorite times on this sub are when powershell is the focus, and the task at hand is a flavor of that focus, rather than the 'complete' project being dumped on here as if it's GitHub2 with upvotes.

Maybe an AI script sharing tag so it can be filtered? Idk, just throwing out ideas. Rant over.


r/PowerShell • • 9d ago

Question Parallel thread disposing?

5 Upvotes

Hey got a wierd issue or its by desing not sure but when I run

$computers | foreach-object -parallel {
  $vmobject = Get-VM $_
  $ram = $vmobject.MemoryGB
  $CPU = $vmobject.numCPU
  $HDD = $_ | get-harddisk 
} 

lets say I run in against 500 computers when that happens powershell will spike cpu on machine that this command is ran and keeps increasing ram usage which is understandable but problem is even when command is done ram usage stays high untill powershell window is close. Is there something I am missing or is there some method to dispose of parallel runspace manually?

Thanks for advice

EDIT: The code itself is not important , the behaviour of parallel scripblock itself is my question and why doesnt it free up RAM after code has ran successfully