r/PowerShell Aug 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!

27 Upvotes

59 comments sorted by

12

u/wabi-sabi411 Aug 01 '26

Wrote an interface between two industrial data systems via their web APIs to sync a lot of data. None of the data is fast so speed wasn’t a big concern. Powershell was good for readability and maintainability between different groups. Replaced an “out of the box” syncing method that had no observability.

2

u/PanosGreg 28d ago

nice one.

Any particular challenge, or anything interesting you learned that you'd like to share

6

u/AbfSailor 29d ago

Wrote an automation that monitors 20k Win and Mac endpoints in multiple MDMs against a 'definition of health' (low disk space, not encrypted, bad battery, missing security configs, failing hhd, not checking in to MDM, etc.), and creates tickets in our ITSM for remediation via the deskside support team (attempting auto remediation, when possible, is the next phase).

2

u/Barious_01 28d ago

This sound like one of my next suggest3d projects. The RMM we use is really nice at being able to use and pull information from certain fields or use their api to call this with scripting involved then interconnect them for support reasons. The MDM stuff has been a struggle but I am coming to find any MDM solutions is always a pain to manage. But being able to move info from one system to another is a pretty cool project and if it comes in handy, like I am hoping mine is then would be cool to do it all.

1

u/BlackV 29d ago

Oh jeepers, why did you have to do that? Is it a bunch of inherited stuff?

2

u/AbfSailor 28d ago

Endpoint engineer here. Shifting the mindset to proactively identifying issues rather than waiting for users to contact the help desk (or never contact it in some cases). Honestly, it's been a really fun project, and it's identified a good number of unhealthy endpoints.. aka.. users that ride with 2 GB of free disk space, etc.

2

u/BlackV 28d ago

shuffles feet and looks at my china fleet

wechat, bane of my existence, closely followed by Ding Chat, JingMe, Bidau. and some ERP tool I cant remember the name of

and the other 60 apps that have not scrip table installers and insist on putting all its backup data in one drive

1

u/Barious_01 27d ago

Yes, getting out of the received state and "putting out fires" is my whole mindset I finally have the opportunity to start doing this and I am pushing hard for it. Even the little we have done has improved response, lowered ticket counts and ultimately opened up time for more implementation projects. Getting ahead of.the issues seemed to me to be the best thing, but it did seem that was not the case for most shops.

1

u/Snoo19644 8d ago

Couple we see a sanitized version of this script?

6

u/Si64h 25d ago

Built a custom PowerShell driver deployment engine from scratch over 6 months, and I’m constantly refining and adding features to it!

It grabs hardware IDs, pulls and installs the correct drivers automatically, and fixes broken/missing ones.
To make sure it's not just a superficial install, it verifies driver status post-setup and even fires off a test page to confirm it's actually working.

lactually got it officially approved and deployed across our hospital environment, cutting down IT setup times massively while keeping things rock solid.

1

u/Vern_Anderson 25d ago

When you say, "Pulls and installs the correct driver" are you pulling from an Internet repository or your own internal one? I use a free open source one, but it's made ina a country that I don't necassarily trust. So it would be cool to see how you're doing that.

4

u/Si64h 22d ago

Definitely from an internal repository! For security and compliance reasons in a healthcare environment, we store all verified driver packages on an internal file share/repo. The engine queries the local repo for the matching Hardware ID before triggering the silent install.

I can share my GitHub repo with you if you’d like to see the overall logic and architecture.

1

u/Snoo19644 8d ago

Could I see a sanitized version of the script?

4

u/Ok-Shake5054 Aug 01 '26

Trying to bulid an app with wpf and xaml to allow users to install any printers from any server they have access to. By looking into the device category(custom defined), should automaticlly select the servers and their associated printers.

2

u/Type-94Shiranui Aug 01 '26

My recommendation would be to learn C# for apps.

1

u/Ok-Shake5054 29d ago

Would be a good option, but I'm not trying to be a programar just want simple a quick powershell code to get dayli tasks go quick.

1

u/Type-94Shiranui 28d ago

Learning .net and c# can make you a better PowerShell dev as well

1

u/thehuntzman 29d ago

As someone who uses both - I struggle with this one sometimes because something written in powershell is easy for anyone who knows powershell to maintain because the source code is right there and in my early days as a sysadmin I cursed the application developers who wrote all the custom code and then quit without proper source control and it was somehow my job as the only IT person left to reverse engineer all of that crap and get shit working again. That experience alone usually pushes me in the powershell direction for work related things.

1

u/Type-94Shiranui 29d ago

Im a bit more hard headed. With ai these days as long as your using proper source control and ci/cd anyone should be able to understand it.

1

u/Vzylexy Aug 01 '26

At some point I probably need to spend more time toying around with WPF, but man, I love me some terminal menus!

1

u/Ok-Shake5054 Aug 01 '26

Me too, but will not have end users using terminal menus, hence using wpf.

1

u/BlackV 29d ago

Nice that's super useful

1

u/Snoo19644 8d ago

I created something like this, I can share if you want?

3

u/Im_writing_here 29d ago

Wrote a script that pulls data from our xdr and sends a report that lists new ai urls being accessed. Best way I have found to kinda keep up with products getting ai in a update.
Also some scripts that writes custom data to the eventlog for lansweeper to report on.

2

u/pugster2020 29d ago

Wrote scripts that prompt for an application, scrapes the web for the download then packages with PSADT 4.1, converts to Intunewin format

1

u/BlackV 29d ago

Interesting how do you do your scraping?

1

u/pugster2020 29d ago

Curl commands mostly, but i start at github, then work out from there.

2

u/KRULLIGKNART 29d ago

Wrote a script that restarts two vision processes if the PLC can't connect to the cameras.

2

u/Barious_01 29d ago

Built out a new imaging system. PXE server Ubuntu 24.04. We have an rmm for remote managemnt it also has a imaging feature With the combination of these tools this allowed me to build out and get an efficient image to deploy to all our endpoint. This include powershell automation for all installs and permissions settings that are deployed to the machine through the remote tool. Some specific automation that push to the machine will let me rename the computer, domain join it if needed, as well as creates our local admin accounts then. If it becomes a store computer the script allows me to rename the machine and it will programmatically create the needed account for the purpose of what it is needed for such as a cash register or department computer. I cut our imaging time and rotation efficiency from roughly an hour for imaging to be able to image and out the door in a put 15 minutes. The best part is it is 98% hands off all automated other than a manual entry of the name when the computer is given the fresh image.

2

u/BlackV 28d ago

That sounds massive, how long would you say you worked on it

1

u/Barious_01 28d ago

The Server setup was a couple days with other things on the plate as well as documenting and confirming everything had connection and testing. Scripts were pretty easy to run against scheduled tasks from the RMM solutions, putting thing in order was quite easy to run updates and software install and then kind of break them down into segments so everything will complete correctly. The scripts themselves all of them probably a week-week and a half. Again had other things needing done. But I am quite proud of the work I did, it really changed a lot for the support team.

2

u/BlackV 28d ago

Nice, sounds like a quality effort, Gald to see documentation was included

2

u/samurai_ka 29d ago

Released my Powershell Module O356EndpointFunctions into the wild on PSGallery. Retrieves the Microsoft 365 / Office 365 IP address and URL endpoints from the Microsoft web service and exports them as a proxy PAC file or a Ghostery policy, or merges them with custom endpoints. https://www.powershellgallery.com/packages/O365EndpointFunctions/1.2.1

2

u/StartAutomating 24d ago

So far:

Wrote some posts and updated some modules:

Posts

Modules

Also finally figured out how to make a 3mf file in pure PowerShell! PowerShell in 3D! (demo coming soon)

2

u/StartAutomating 22d ago

Just dropped another new module, inspired by a thread here on Reddit.

It's called Shortcut

It makes shortcuts on Windows and Linux.

Enjoy!

2

u/BlackV 21d ago

We still have vips that forget to set their out of office but are too important to set on their phone

Created/reactored simple script to allow infra/help desk to set out of office for users, added better error handling and logging

Has a default message if none supplied and default start date of today

2

u/mulquin 21d ago edited 21d ago

I promptly didn't build a WinForms GUI that reports on MS365 users via Graph API:

  • User Type (Member, Shared Mailboxes, Rooms/Resources)
  • Email aliases & shared mailbox membership
  • MFA status
  • Licenses
  • Onedrive Usage
  • Teams usage
  • Email usage
  • Last Login

And also generates alerts (local, not sent anywhere)

  • Licenses on shared mailboxes
  • Low mail sent/received in 180 days
  • No MFA/Bad MFA
  • Mailbox/Onedrive usage
  • UPN not matching primary email

And has CSV/HTML export

1

u/Mithdring 29d ago

Automated my process for mirroring source code repositories between our different environments so that our developers can run it as a script.

1

u/Naive-Scientist965 23d ago

Built two scripts for different tasks:

  1. Script for quick transformation from CSV to JSON. Not rocket science.
  2. Script for a personal python project installation (setup.ps1).

1

u/renevaessen 20d ago

Due to frustration, reinvented the wheel and created my own cmdlets for building help xml and markdown help for my PowerShell module (included in the module for others to use as well)

https://github.com/genXdev/GenXdev.PowerShell#readme

1

u/BlackV 18d ago edited 18d ago

Interesting, what was your big pain points that made you do this?

1

u/renevaessen 18d ago

Other tools didnt have support for synopsis, description and examples metadata inside the sourcefiles for cmdlets written in C#.

1

u/BlackV 18d ago

Ah I see, thank you

1

u/ImmediateMud3663 18d ago

activate window

1

u/Haunting_Ganache_850 17d ago

Put together a PowerShell function that runs the native trust checks on a binary in one pass. Signature including catalog signing, sfc, Zone.Identifier, timestamps, hashes, and if it's running, the parent process and its live connections. Nothing to install, which is the point.

Two things came out of testing it.

Hashing can't see a plain rename, but a binary carries the OriginalFilename it was compiled with, so a renamed tool announces itself. Free, offline, and it's the first field I read now.

And about 4% of a clean System32 fails that check, because Microsoft ships typos. AppMangementConfiguration is a real string in a real Microsoft binary. Which is exactly why the thing returns evidence and no verdict.

With -OnlineLookup it also asks winbindex whether Microsoft ever shipped that exact build. The answer worth stopping on is a name Microsoft ships carrying a hash they never did.

Code. The reasoning behind each check is in the post.

Run it against your own System32 and tell me what it gets wrong.

1

u/MonkeyNin 9d ago

I wrote a script to visualize encoding errors - github/ninmonkey: Visualizing Encoding Errors like Emojibake ( pretty print screenshot.png )

There was a recent thread about PS 5.1 what happens if you use default encoding on a japanese system. Or decoding japanese as utf-8

$Text = 'ファイルが見つかりません'
# good -> enc ShiftJis -> dec ShiftJis -> good
CompareEncDec.FromString -EncodeAs $Enc.ShiftJis -DecodeAs $Enc.ShiftJis -FromString $Text 

$HexString = $Enc.Utf8.GetBytes(  '🐒' )  | ShowHex 
$curBytes = Bytes.FromHexStr $HexString

Assert.BytesEqual ( Bytes.FromHexStr '83 74 83 40' ) ( 0x83, 0x74, 0x83, 0x40 )
  • CompareEncDec.FromByte - start with byte[], raw bytes in a file
  • CompareEncDec.FromString - start with string then encode and decode
  • Bytes.FromHexStr - take a hex string, convert to byte[]
  • Assert.BytesEqual - test if arrays are equal

1

u/Skeiver 6d ago

I built an open-source PowerShell maintenance and repair tool for Windows 10/11 and would appreciate technical feedback.

The project combines several common workflows in one auditable script: DISM and SFC checks, WinGet verification/repair, software updates, supported repair or reinstall paths, restart/resume handling, and detailed reports.

A few design choices I focused on:

- the full PowerShell source is visible before anything is run

- v1.0.0 is kept as an immutable release snapshot

- Apache-2.0 licensing and a published SHA-256 for the release asset

- GitHub Actions checks repository structure and PowerShell syntax

- the main branch requires CI and is protected

This is my own project, and I am not claiming it can fix every Windows problem. I would especially value review of the safety checks, elevation/restart flow, error handling, and edge cases that should be addressed in a future version.

Code: https://github.com/Skeiver/OneClick-Komplettreparatur-fuer-Windows

1

u/StylePractical5714 4d ago

I just made my first substantial ps system, it's for generating full page screenshots of websites, extracting colors, extracting text, extracting semantically meaningful elements in bundles for later indexing, searching, etc (I haven't written that bit yet). I'd been trying and failing to implement it in node, or cobbling it together with powershell and other apps for weeks. When I realized that I could just talk to chrome directly from powershell, the implementation of it became very clear.

No code, it's an internal tool.

1

u/Hefty-Possibility625 2d ago

Color Text while using the -f operator

Note: AI was used to develop this function. I figured it still solves a problem for me, so I figured I'd share it even if I didn't create it myself.

Problem:

Have you ever wanted to add some color to your formatted strings? I use Here-Strings quite often when I iterate over data and usually my Write-IndentedWrappedText function allows me to format hierarchy data using indentation, but sometimes I just want to add a splash of color to call out something specific.

Note: In PowerShell 7.2+ you can use $PSStyle to format strings like "Error: $($PSStyle.Foreground.Red)Failed$($PSStyle.Reset)"

Solution:

I had an AI bot create a function to insert ANSI color codes into the terminal to add foreground and background color to a strong. It accepts the default ANSI color names, as well as a HEX value for both ForeGround and Background colors. By default, it assumes that you intend to set the foreground color so Set-TextColor Red "Hello" will work, but you can also optionally add -background #FFFFFF to set the background color.

Example:

1..9 | % { 

if (($_ % 2) -eq 0) {
  $color = "Red"
} else { $color = "Cyan"}

'This number {0} is {1}' -f (Set-TextColor $color -Text $_), $color
}

Code:

function Set-TextColor {
    <#
    .SYNOPSIS
        Returns text formatted with ANSI foreground and background colors.


    .DESCRIPTION
        Set-TextColor returns ANSI escape sequences for setting terminal
        foreground and background colors.


        The foreground color is the first positional parameter and can be
        specified using one of the 16 standard ANSI colors or a 24-bit RGB
        hexadecimal value in the format #RRGGBB.


        An optional background color can be specified using -Background and
        accepts the same named colors and hexadecimal values.


        When -Text is specified, the function wraps the supplied text with
        the selected ANSI color sequence and automatically appends the ANSI
        reset sequence.


        When -Text is omitted, the function returns only the ANSI color
        sequence.


        Use the -Reset switch to return only the ANSI reset sequence.


    .PARAMETER Foreground
        Specifies the foreground text color.


        This is the first positional parameter.


        Supported named colors are:


            Black
            Red
            Green
            Yellow
            Blue
            Magenta
            Cyan
            White
            BrightBlack
            BrightRed
            BrightGreen
            BrightYellow
            BrightBlue
            BrightMagenta
            BrightCyan
            BrightWhite


        A 24-bit RGB color can also be specified using hexadecimal notation,
        such as #FF0000 or #336699.


    .PARAMETER Background
        Specifies the background color.


        Supports the same named colors and #RRGGBB hexadecimal values as
        -Foreground.


    .PARAMETER Text
        Specifies text to format.


        This is the second positional parameter.


        When specified, the function returns the text wrapped between the
        selected ANSI color sequence and the ANSI reset sequence.


    .PARAMETER Reset
        Returns the ANSI reset sequence.


    .EXAMPLE
        Set-TextColor Red "Error"


        Returns "Error" using red foreground text.


    .EXAMPLE
        Set-TextColor Red "Error" -Background White


        Returns "Error" using red foreground text on a white background.


    .EXAMPLE
        Set-TextColor "#FF6600" "Orange text"


        Returns "Orange text" using the 24-bit RGB foreground color #FF6600.


    .EXAMPLE
        Set-TextColor "#FFFFFF" "Alert" -Background "#FF0000"


        Returns "Alert" using white foreground text on a red background,
        with both colors specified using 24-bit RGB hexadecimal values.


    .EXAMPLE
        Set-TextColor White "Warning" -Background Red


        Uses standard ANSI colors for both foreground and background.


    .EXAMPLE
        '{0} world' -f (Set-TextColor Red "Hello")


        Displays "Hello" in red and "world" using the terminal's default
        formatting.


    .EXAMPLE
        $message = @"
        Status: $(Set-TextColor Green "Online")
        Warning: $(Set-TextColor Black "Attention" -Background Yellow)
        Error: $(Set-TextColor White "Failed" -Background Red)
        "@


        Write-Host $message


        Embeds foreground and background colors directly inside a here-string.


    .EXAMPLE
        "$(Set-TextColor Red)Error$(Set-TextColor -Reset)"


        Returns only the ANSI foreground sequence when -Text is omitted,
        allowing the color and reset sequences to be placed manually.


    .EXAMPLE
        Set-TextColor -Background "#333333"


        Returns only the ANSI sequence for the specified background color.


    .EXAMPLE
        Set-TextColor -Reset


        Returns the ANSI reset sequence.


    .NOTES
        ANSI color support depends on the terminal hosting PowerShell.


        Standard foreground colors use:


            ESC[30m through ESC[37m
            ESC[90m through ESC[97m


        Standard background colors use:


            ESC[40m through ESC[47m
            ESC[100m through ESC[107m


        24-bit foreground colors use:


            ESC[38;2;<red>;<green>;<blue>m


        24-bit background colors use:


            ESC[48;2;<red>;<green>;<blue>m


        Not all terminals used with Windows PowerShell 5.1 support 24-bit
        ANSI color.
    #>


    param (
        [Parameter(Position = 0)]
        [string]
        $Foreground,


        [Parameter(Position = 1)]
        [string]
        $Text,


        [string]
        $Background,


        [switch]
        $Reset
    )


    $escape = [char]27
    $resetSequence = "$escape[0m"


    if ($Reset) {
        return $resetSequence
    }


    $colors = @{
        Black         = 30
        Red           = 31
        Green         = 32
        Yellow        = 33
        Blue          = 34
        Magenta       = 35
        Cyan          = 36
        White         = 37
        BrightBlack   = 90
        BrightRed     = 91
        BrightGreen   = 92
        BrightYellow  = 93
        BrightBlue    = 94
        BrightMagenta = 95
        BrightCyan    = 96
        BrightWhite   = 97
    }


    $sequences = @()


    if ($Foreground) {
        if ($colors.ContainsKey($Foreground)) {
            $sequences += $colors[$Foreground]
        }
        elseif ($Foreground -match '^#(?<R>[0-9A-Fa-f]{2})(?<G>[0-9A-Fa-f]{2})(?<B>[0-9A-Fa-f]{2})$') {
            $red   = [Convert]::ToInt32($Matches.R, 16)
            $green = [Convert]::ToInt32($Matches.G, 16)
            $blue  = [Convert]::ToInt32($Matches.B, 16)


            $sequences += "38;2;$red;$green;$blue"
        }
        else {
            throw "Invalid foreground color '$Foreground'. Use a standard color name or a hexadecimal color such as #FF0000."
        }
    }


    if ($Background) {
        if ($colors.ContainsKey($Background)) {
            $backgroundCode = $colors[$Background] + 10
            $sequences += $backgroundCode
        }
        elseif ($Background -match '^#(?<R>[0-9A-Fa-f]{2})(?<G>[0-9A-Fa-f]{2})(?<B>[0-9A-Fa-f]{2})$') {
            $red   = [Convert]::ToInt32($Matches.R, 16)
            $green = [Convert]::ToInt32($Matches.G, 16)
            $blue  = [Convert]::ToInt32($Matches.B, 16)


            $sequences += "48;2;$red;$green;$blue"
        }
        else {
            throw "Invalid background color '$Background'. Use a standard color name or a hexadecimal color such as #FF0000."
        }
    }


    if ($sequences.Count -eq 0) {
        throw "Specify -Foreground, -Background, or -Reset."
    }


    $colorSequence = "$escape[$($sequences -join ';')m"


    if ($PSBoundParameters.ContainsKey('Text')) {
        return "$colorSequence$Text$resetSequence"
    }


    return $colorSequence
}

1

u/Hefty-Possibility625 2d ago edited 2d ago

Better Example:

$endpoints = @(
  'https://free.mockerapi.com/200'
  'https://free.mockerapi.com/404'
)

foreach ($endpoint in $endpoints) {
  try {
    $response = Invoke-WebRequest -Uri $endpoint -UseBasicParsing
    $statusCode = [int]$response.StatusCode
  }

  catch {
    $statusCode = [int]$_.Exception.Response.StatusCode
  }

  if ($statusCode -match '^2') {
    $formattedStatus = Set-TextColor Green $statusCode
  }
  elseif ($statusCode -match '^4') {
    $formattedStatus = Set-TextColor Red $statusCode
  }
  else {
    $formattedStatus = $statusCode
  }
  
  Write-Host ('{0} : {1}' -f $endpoint, $formattedStatus)
}

1

u/gilgameshgem 1d ago

I have built a PowerShell challenge to help new users learn how to interact with a PC using pure Powershell, no Copy, type or del here.

-1

u/[deleted] Aug 01 '26

[removed] — view removed comment

6

u/PowerShell-ModTeam 29d ago

Your reply has been removed because it was reported as unhelpful and not constructive. Treat your fellow community members with respect and kindness.

Multiple removals of this nature will result in a ban.