r/PowerShell • u/AutoModerator • Sep 01 '26
Script Sharing What have you done with PowerShell this month?
A sticked post for the community to share their projects throughout the month.
Make sure to post a link to the code!
19
Upvotes
14
u/cyrixlord Sep 01 '26
a month of lunches
14
u/warren_stupidity Sep 01 '26
I got annoyed at netstat.exe taking minutes to complete so I replaced it with a powershell script front end to Get-NetTCPConnection and Get-NetUDPEndpoint. Runs really fast.
8
u/shockerocker Sep 01 '26
Built a PowerShell based tool that pops up a windows toast notification to let me know when a monitored host comes online and is available for a WinRM connection.
5
u/teethingrooster Sep 01 '26
Wrote a PowerShell script to scan for apps in our org I know that use SQL 2016. Check the named instances and if there’s no apps and no named instances it uninstalls the localdb.
Also not a software developer I work in IT. But I’m learning C# to replace an internal IT tool. I wrote some PowerShell scripts to setup and reset some folders that way I can repeatedly test my C# app as I write it.
4
u/FieryHDD Sep 01 '26
Archive 700+ teams
4
u/kboutelle Sep 01 '26
Welp, there's this garbageware that someone needs at our firm. It requires that chromedriver is installed on the system. That damn driver has to be the same version as Chrome, which updates every three days. So I built a remediation in Intune to check the version of Chrome and the driver and if needed, download the newer version and extract it to the correct location. Then clean up and report back that all is well.
FML
3
u/Gron_Tron Sep 01 '26
Scripted an alert for Entra Risk detections. There is a built in alert mechanism but it's locked behind Entra P2.
3
u/StartAutomating Sep 02 '26
Figured out how to Remix Music with PowerShell. Wrote a post about it. Made a post to BlueSky about an hour after I figured it out, and attached my first remix.
3
u/m0zi- Sep 02 '26
ping 8.8.8.8
3
u/Szeraax Sep 05 '26
I got sick of dealing with rate limiting irm requests. I've used my PoshInteractive module to manage it in the past (which is awesome in a pipeline). But I wanted a solution that would work in other contexts. Ended up making a module that works as a drop-in replacement for Invoke-RestMethod that will delay requests as needed to ensure you stay under target rate limiting criteria.
One thing to note: You can already build your use of irm defensively (use the retry count parameter with ps 7 and let it handle 429 "retry after" if the API is kind enough to tell you that you're hitting rate limiting). This module does not replace that capability or automatically add it either. It is simply a proactive tool to allow you to pick your own rate limits for what you send and can be used in complement to 429 rate limits too.
You can install it from PSGallery today!
https://github.com/Szeraax/RateLimitedRestMethod
AI disclosure: AI was used in the making of this module. I did the scaffolding and described how I want it all to work. I've tested it and it works great. I've reviewed the code and I'm happy with it as well. This is not simply a "write a module that is a drop in rate limite replacement to invoke-restmethod".
3
u/Vern_Anderson Sep 09 '26
Completed the excersize https://exercism.org/tracks/powershell/exercises/bottle-song
Let me know your thoughts on my solution
Function Get-BottleCount{Param ([Parameter(Mandatory=$true,Position=0)]$Number)switch ($Number){10 {$Number = "Ten" ; $Minus1 = "Nine"}9 {$Number = "Nine" ; $Minus1 = "Eight"}8 {$Number = "Eight" ; $Minus1 = "Seven"}7 {$Number = "Seven" ; $Minus1 = "Six"}6 {$Number = "Six" ; $Minus1 = "Five"}5 {$Number = "Five" ; $Minus1 = "Four"}4 {$Number = "Four" ; $Minus1 = "Three"}3 {$Number = "Three" ; $Minus1 = "Two"}2 {$Number = "Two" ; $Minus1 = "One"}1 {$Number = "One" ; $Minus1 = "No"}}Write-Host -Object "$Number green bottles hanging on the wall," -ForegroundColor GreenWrite-Host -Object "$Number green bottles hanging on the wall," -ForegroundColor GreenWrite-Host -Object "And if one green bottle should accidentally fall," -ForegroundColor GreenWrite-Host -Object "There'll be $($Minus1.ToLower()) green bottles hanging on the wall." -ForegroundColor GreenWrite-Host -Object " "}10..1 | Foreach-Object {Get-BottleCount $_}5
u/VeryRareHuman Sep 01 '26
Claude done few PowerShell scripts, all of the very useful. So I didn't do shit.
4
u/hwntw Sep 01 '26
can people post some scripts please
2
u/ihaxr Sep 02 '26
Automated SQL Server certificates utilizing DBAtools and Windows Certificate Authority.
Windows CA has built in auto renewal after you deploy the initial cert using a template, with a configurable timespan to auto renew before expiration. The certs will auto renew and install themselves to the server, then a weekly script will apply the new cert to SQL and grant the gMSA account read permission (if needed, it seems to remember it).
When the server is rebooted for patching the new certificate is in use, until then SQL will still use the valid, archived, certificate.
2
u/_RemyLeBeau_ Sep 02 '26
Wrote a 1-liner to parse an .env file, then add those vars to the process and start an MCP Gateway in streaming mode.
2
u/Alone_Marionberry900 Sep 02 '26
Built a pode api backend and razor pages front end to call native exchange online commands that don’t work through graph. Allows me to give simple tasks to other teams without exposing more rights to exchange.
2
u/Powerful-Passenger24 Sep 02 '26
Built PwshRichLite: lightweight Rich-style output for PowerShell using
$PSStyle— tables, trees, panels and markup. I use it in OwnerLensLite. https://github.com/kodevza/PwshRichLight2
u/Lotus_Domino_Guy Sep 02 '26
HR external system to Active Directory syncronization.
2
u/NurglesToes Sep 02 '26
Powershell noobish / junior sysadmin here. Finished a 1k line script to update OpenJDK in our environment. (at least that’s the ultimate goal of the script)
In reality it’s a state managed script that has to:
Stop services
back up the certificate in the jdk installation
uninstall openjdk
install openjdk
restore the certs
update the directory to a custom directory
update the Zena Agent controller xml with the new bin location
update the environment variables
start the services back up
and validate all of it.
Took me 2 months of working on it intermittently. The previous script was like 300 lines and had a 35% failure rate, so i figured if we’re gonna be updating hundreds of production machines every quarter, might as well go full autism on it. Tested it today and it works so much better
2
u/Revolutionary-Gold53 Sep 05 '26
Developed a script to remove decommissioned systems from any one of our domains and from SCCM. Had AI rewrite it to have better error handling and logging, and also generate a Pester test script.
2
u/jeffrey_f Sep 06 '26
Rather simple I run Windows updates + winget updates. Right now it is a manual script which could be place on the job scheduler and run as admin.
Still a time saver as I run the script and go back to whatever it was that I was doing.
2
u/Andrew-Powershell Sep 10 '26
I've been:
- hosting lots of PowerShell Wednesdays
- releasing PowerShell Podcast episodes every Monday
- takings steps to revive PSKoans
- working on a silly PowerShell Idle game
- lots of Maester and 365
1
u/DenialP Sep 01 '26
Munged a hr dataset down to automate the orgs identity lifecycle
1
u/scoinv6 Sep 02 '26
Ensure all SQL servers had SPNs set
1
u/T3-Trinity Sep 02 '26
Wrapped Python in it lol
1
u/KavyaJune Sep 02 '26
I wrote a script to bulk transfer meetings from one organizer to another. It can be helpful during employee offboarding and role changes.
Script available in GitHub: https://github.com/admindroid-community/powershell-scripts/blob/master/ChangeMeetingOrganizer.ps1
1
u/Admirable_Day_3202 Sep 02 '26
For a specific app - Script to leverage azd CLI that connects to a tennant, resource group then export the bicep files for the app and related components it then allows you to import into another env/tennant. Then it allows you setup everything for that app and components e.g. entra groups and app regs Upload files to the static web app and azure function Connect to key vault and setup certs Create run book and schedule to rotate certs automatically Create sharepoint site
1
u/AlkHacNar Sep 02 '26
Integrated psadt 4.2 in my pmpc clone ^
1
u/yahuei Sep 03 '26
Templated the rollout of new sharepoint sites.
1
u/Sharlihe Sep 03 '26
Update of two of my daily used tools PSBITE and PSWEE. Added a new feature and fixed some stuff on these.
Fixed also the PSModule Framework used for them that got breaking changes recently. All is fresh and deployed !
https://github.com/arnaudcharles/PSBITE
https://github.com/arnaudcharles/PSWEE
1
u/ismaelw Sep 03 '26
Tried to fix the worst user entry script I have seen in a very long time. Oh and trying to replace Basic Auth showed me that some Microsoft APIs don‘t work unattended
1
u/Practical_Air6315 Sep 04 '26
Ran every write/read encoding combination I could think of on PS 5.1 and 7 - 51,775 cases. Get-Content -Encoding UTF8 never throws on bad bytes, so a round trip can "succeed" and hand back 8 chars where 4 went in. Table's on GitHub.
1
u/tructt Sep 06 '26
A W11 deployment engine to bring installation time to under 5 mins. Automated way
1
u/simwai Sep 08 '26
TUI Text Editor:
https://github.com/simwai/babae/
1
u/Syronn Sep 09 '26
Automated Microsoft Bookings shared site creation. The variables come from a sharepoint listform. Was a pain in the ass, because the documentation sucks...
1
u/CypherAus Sep 15 '26
Set processor affinity in a script
$Process = Get-Process myperformancetask
$Process.ProcessorAffinity = 0x00000000000FFC00
1
u/Reaction-Consistent Sep 19 '26 edited Sep 19 '26
Learned the amazing power of 'here strings'! I use them to store multi-line strings without having to escape anything, and this also eliminates the necessity of importing separate text files into a script to read in the data, which can present other issues. Here's a short example of how I might use a here string inline to represent a config file that before I may have imported. The down side is that I must update that string if the source text file changes in content at all.. so it's not the best solution in every scenario of course.
# Access Task Sequence Environment
try {
$TSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment
$serverName = $TSEnv.Value("SVR_Connection")
}
catch {
Write-Error "Unable to access SCCM Task Sequence environment."
exit 1
}
Write-Host "========================================="
Write-Host "IBM Shortcut Creation Starting"
Write-Host "SVR_Connection = $serverName"
Write-Host "========================================="
if (-not $serverName) {
Write-Error "Task Sequence variable SVR_Connection is not populated."
exit 1
}
if ([string]::IsNullOrWhiteSpace($serverName)) {
Write-Error "Task Sequence variable SVR_Connection is not populated."
}
#SSL config per AS400 server - to be updated in client .hod file
$hosts = @(
[PSCustomObject]@{ System = "server1"; SSL = "TRUE"; SSO = "TRUE"; CodePage = "37" }
[PSCustomObject]@{ System = "server2"; SSL = "TRUE"; SSO = "TRUE"; CodePage = "37" }
)
# Lookup selected host definition
$hostDefinition = $hosts | Where-Object {
$_.System -eq $serverName
} | Select-Object -First 1
if (-not $hostDefinition) {
Write-Error "Server '$serverName' was not found in host definition list."
exit 1
}
Write-Host "Host Definition Found"
Write-Host "System : $($hostDefinition.System)"
Write-Host "SSL : $($hostDefinition.SSL)"
Write-Host "SSO : $($hostDefinition.SSO)"
Write-Host "CodePage : $($hostDefinition.CodePage)"
# 'here string' in place of importing an existing .hod file
$content = @"
<.hod file content goes here - config file for AS400 connection. the script uses this as a template for the creation of a customized .hod file using the parameters from the PS custom objects array above>
"@
$hostDefinition = $hosts | Where-Object {$_.System -eq $serverName} | Select-Object -First 1
$newServername = $serverName + '.contoso.com'
# set variables for SSL SSO Lines in .HOD
if ($hostDefinition.SSL -eq "TRUE"){
$secPol = "SecurityProtocol=SESSION_PROTOCOL_TLS"
$sslJ = "sslJSSETrustStoreType=jks"
$ssl = "SSL=true"
$port = "port=992"
} else {
$secPol = "SecurityProtocol=SESSION_PROTOCOL_TELNET"
$sslJ = "sslJSSETrustStoreType="
$ssl = "SSL=false"
$port = "port=23"
}
if ($hostDefinition.SSO -eq "TRUE"){
$sso = "acsPasswordPrompt=5_kerberos"
} else {
$sso = "acsPasswordPrompt=1_useAcsSetting"
}
$newContent = $content -replace '(?m)^SecurityProtocol=.*$', $SecPol
$newContent = $newContent -replace '(?m)^sslJSSETrustStoreType=.*$', $sslj
$newContent = $newContent -replace '(?m)^SSL=.*$', $ssl
$newContent = $newContent -replace '(?m)^port=.*$', $port
$newContent = $newContent -replace '(?m)^acsPasswordPrompt=.*$', $sso
$newContent = $newContent -replace 'servewrname', $newServername
$IBMFolder = "C:\Users\Public\IBM"
if (-not (Test-Path $IBMFolder)) {
New-Item -Path $IBMFolder -ItemType Directory -Force | Out-Null
}
#create the new .hod file on the client PC with the custom settings
Set-Content -Path "C:\Users\Public\IBM\$serverName.hod" -Value $newContent
$LASTEXITCODE
1
u/0f_rice_and_men Sep 23 '26
if I'm lucky, something to keep the damn pc awake longer than 10 minutes when it's sitting at home idle by itself
1
u/Intelligent_East_517 Sep 24 '26 edited Sep 24 '26
I did a script (with help from copilot) that lists all our Exchange distribution lists, their name, email addresses, type, members (including groups), owners, notes and descriptions and creates a Excel spreadsheet of this.
Need this to clean up the swamp... :)
Not very sexy I know...but I need this.
1
u/CowSlow431 Sep 30 '26
4 irc bots in python with copilot n powershell! :P
1
u/Substantial-Put-6318 Sep 01 '26
Criado script bem completo para Backup de Ambiente Windows, com S3. O script contempla erros, analises, rotacionamentos, tudo isso em variaveis, além de adicionar as notificações com Telegram ou E-mail.
Inicialmente o Script tinha 400 linha, terminei ele com 1950.
1
u/Icemagic Sep 01 '26
T1 Hell Desk analyst here! Heavy onboarding week:
Fixed a broken client script: A new client handed us a script meant to copy AD groups from a template user to a new hire, except it was dead on arrival. Rewrote it and gave it back (waiting to see if they'll actually use it).
Killed account creation errors: After seeing a ton of errors popping up across the desk, I built a full onboarding script. Now analysts just plug in 5 values from the ticket, and PowerShell handles the rest:
Copies template AD groups
Creates & names the .bat file + provisions home share
Maps logon script & drive letters
Fills in Manager and Description attributes
Spits out a clean block for ticket notes
Saved the team a ton of manual clicks and cut down on typos. This one is running up the chain too.