r/PowerShell • • 14d ago

Script Sharing What have you done with PowerShell this month?

18 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 • • Oct 01 '26

Script Sharing What have you done with PowerShell this month?

22 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 • • 1d ago

Question Good powershell profile tips

61 Upvotes

I’ve been having way too much fun customizing my PowerShell profile lately. 😂
Here’s what I’ve got so far:
root — Prompts for my Domain Admin credentials and launches a new elevated PowerShell session.
Green errors — Because Don Jones taught me that errors don’t have to be angry red.
Custom prompt — Shows my current path and the time, so I can tell how long commands took.
save-clip — My homemade clipboard vault! Password-encrypts whatever’s on my clipboard and saves it to a file. Even works with images.
Admin indicator — Makes it obvious when I’m running elevated.
Extended scrollback — Because nothing hurts quite like scrolling up to find something important, only to discover PowerShell already ate it. 😭
record — My next addition! A one-word shortcut to start a PowerShell transcript, timestamp the log file, and record my session. Maybe a stoprecord companion too.
I’m starting to think my PowerShell profile is becoming its own operating system.
What other clever functions, shortcuts, or quality-of-life improvements have you all added to yours? I’m looking for ideas worth stealing. 😂


r/PowerShell • • 19h ago

Script Sharing Creating as PS7 ISE

0 Upvotes

For my techie Friends.
I've been busy with a little pet project this week. I've always wanted a PowerShell ISE that could run PowerShell 7. So with a little help from OpenCode, I built one.

It's able to run a script I use for maintenance on my own machine.

https://github.com/haplopeart/PS7_ISE

It doesn't have everything yet. I'm sure there are still bugs; I will keep testing it. I will also keep evolving it toward parity with the original PowerShell ISE. I never looked to see if anyone had done something similar. I just saw it as a personal challenge. I personally find running PowerShell scripts in VS Code a little overkill; I wanted something simple.

Potential Adds, changes:

  1. Versions for running PowerShell on Linux and MACOS

  2. Update to add the Commandlet reference pane the original has.

  3. Update to run PS 7.7.0; it was released while I was working on this.

  4. Status Bar for Cursor Position

  5. Line Numbers in the Editor Window


r/PowerShell • • 1d ago

Question Automating STIG CKL comparisons with PowerShell

6 Upvotes

I'm trying to automate of our monthly STIG review process.

The monthly STIG batch processing is already handled. What i'd like to automate next is comparing the new CKL files against a known good golden base and generating a report showing only the controls that changed.

The goal is to avoid manually opening large numbers of CKL files in STIG Viewer just to find a handful of differences.

I'm currently looking at parsing the CKL XML with PowerShell but before I build something from scratch I wanted to see if there are existing PowerShell modules or tool that can compare CKLs or generate useful diff reports.

Has anyone automated something similar? What approach or tooling worked for you?


r/PowerShell • • 3d ago

News Powershell collection for IT Admins and not only

161 Upvotes

Over the last few months, I’ve been working on a number of PowerShell projects and automation scripts. Most of them focus on system administration, Microsoft 365, networking, monitoring, and general IT automation tasks.

I’ve published several of them on my GitHub if anyone would like to take a look:

https://github.com/karanikn?tab=repositories

I’m always looking for ways to automate repetitive work and make day-to-day administration a little easier.

If you have any ideas for improvements, new features, or changes, I’d love to hear them. And if you happen to spot any bugs, issues, or areas that could be improved, I’d really appreciate your feedback when you have the time.


r/PowerShell • • 1d ago

Question why is it allways starting on system32?! it should start on the desktop...

0 Upvotes

here is the config:

{

"$help": "https://aka.ms/terminal-documentation",

"$schema": "https://aka.ms/terminal-profiles-schema",

"actions": [],

"alwaysShowNotificationIcon": true,

"centerOnLaunch": true,

"copyFormatting": "none",

"copyOnSelect": false,

"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

"keybindings":

[

{

"id": "Terminal.CopyToClipboard",

"keys": "ctrl+c"

},

{

"id": "Terminal.FindText",

"keys": "ctrl+shift+f"

},

{

"id": "Terminal.PasteFromClipboard",

"keys": "ctrl+v"

},

{

"id": "Terminal.CloseWindow",

"keys": "ctrl+f"

},

{

"id": "Terminal.DuplicatePaneAuto",

"keys": "alt+shift+d"

},

{

"id": "Terminal.OpenSettingsUI",

"keys": "ctrl+m"

}

],

"launchMode": "focus",

"newTabMenu":

[

{

"type": "remainingProfiles"

}

],

"newTabPosition": "afterLastTab",

"profiles":

{

"defaults":

{

"adjustIndistinguishableColors": "indexed",

"antialiasingMode": "cleartype",

"colorScheme": "One Half Dark",

"experimental.retroTerminalEffect": false,

"font":

{

"face": "JetBrainsMono Nerd Font"

},

"opacity": 0,

"padding": "15",

"startingDirectory": "C:\\Users\\maxsu\\Desktop",

"useAcrylic": false

},

"list":

[

{

"backgroundImage": null,

"backgroundImageOpacity": 0.07,

"colorScheme": "Ottosson",

"commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",

"font":

{

"face": "JetBrainsMono Nerd Font"

},

"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

"hidden": false,

"name": "Windows PowerShell",

"opacity": 0,

"scrollbarState": "hidden",

"startingDirectory": "C:\\Users\\maxsu\\Desktop",

"useAcrylic": true

},

{

"commandline": "%SystemRoot%\\System32\\cmd.exe",

"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",

"hidden": false,

"name": "\u041a\u043e\u043c\u0430\u043d\u0434\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430",

"opacity": 100,

"startingDirectory": "C:\\Users\\maxsu\\Desktop",

"useAcrylic": false

},

{

"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",

"hidden": false,

"name": "Azure Cloud Shell",

"source": "Windows.Terminal.Azure"

},

{

"guid": "{6cff44b8-d193-55cd-b6c4-1c4f7101be95}",

"hidden": false,

"name": "Developer Command Prompt for VS 2022",

"source": "Windows.Terminal.VisualStudio"

},

{

"guid": "{5e05125c-0fdd-503e-8586-c85e104b19de}",

"hidden": false,

"name": "Developer PowerShell for VS 2022",

"source": "Windows.Terminal.VisualStudio"

}

]

},

"rendering.graphicsAPI": "direct3d11",

"schemes":

[

{

"background": "#18181B",

"black": "#18181B",

"blue": "#E5E7EB",

"brightBlack": "#4B565C",

"brightBlue": "#E5E7EB",

"brightCyan": "#E5E7EB",

"brightGreen": "#E5E7EB",

"brightPurple": "#E5E7EB",

"brightRed": "#E5E7EB",

"brightWhite": "#E5E7EB",

"brightYellow": "#E5E7EB",

"cursorColor": "#E5E7EB",

"cyan": "#E5E7EB",

"foreground": "#E5E7EB",

"green": "#E5E7EB",

"name": "Monochrome",

"purple": "#E5E7EB",

"red": "#E5E7EB",

"selectionBackground": "#18181B",

"white": "#E5E7EB",

"yellow": "#E5E7EB"

}

],

"showTabsInTitlebar": true,

"tabSwitcherMode": "mru",

"tabWidthMode": "compact",

"theme": "system",

"themes":

[

{

"name": "Monochrome",

"tab":

{

"background": "#18181BFF",

"iconStyle": "default",

"showCloseButton": "always",

"unfocusedBackground": null

},

"tabRow":

{

"background": "#E6E9EFFF",

"unfocusedBackground": "#DCE0E8FF"

},

"window":

{

"applicationTheme": "light",

"experimental.rainbowFrame": false,

"frame": null,

"unfocusedFrame": null,

"useMica": false

}

}

],

"useAcrylicInTabRow": true

}


r/PowerShell • • 4d ago

Question PowerShell 7.7 - All users profile script location

77 Upvotes

Starting with PowerShell 7.7 it is now a windows app and if you install it with Add-AppxPackage, then it will live in "C:\Program Files\WindowsApps\Microsoft.PowerShell_7.7.0.0_x64__8wekyb3d8bbwe"

On previous versions I had profile.ps1 live in "C:\Program Files\PowerShell\7"
However not only do I suspect the bin directory will change with each new version, it is now read-only for everything except system, you can't put any files in there without hacking it with system privileges.
Where do they expect us to put all user scripts now?


r/PowerShell • • 3d ago

Solved Using Exchange Custom Attributes for Groups Through the Microsoft Graph

5 Upvotes

Microsoft has released limited Graph support for accessing Exchange custom attributes in groups synchronized from on-premises environments. Not every type of Entra group is available on-premises, so we’re really talking about distribution groups and security groups. In any case, real-only access to the fifteen custom attributes is available via Graph API and the Get-MgGroup cmdlet. Now it’s up to you to do something inventive with the information.

https://office365itpros.com/2026/11/12/custom-attributes-graph/


r/PowerShell • • 2d ago

Script Sharing ADSearch - User/Computer comparison tool

0 Upvotes

This Active Directory toolkit offers user/computer OU comparisons using fuzzy Levenshtein matching to determine if the computer is in an OU that matches the user's OU (if similar State/Site/Facility path). Designed for IT audits and continual asset management.

ADSearch/README.md at main · Contoso-Administrator/ADSearch


r/PowerShell • • 4d ago

Script Sharing Now its time - my new tool 'GSAClientDiagnosticsToolkit' is out!

18 Upvotes

I work Global Secure Access, the Product Team at Microsoft too, and I use it every day. Over time I got tired of manually checking the same things whenever a client wouldn't connect (DNS issues, certificates, stale forwarding profiles, proxies...). So what did I do? 🤔

I built a PowerShell module that runs them all in one go ofc! And the nice part is it's open source, Windows PowerShell 5.1+ (Windows only for now), but who knows whats come later 😉

And to be fair, this is not a weekend project. It is a collection of checks I have built up over time - on and off for almost a year - every time I (or someone in the community) ran into a new GSA problem and thought "this should be a check".
Original it started as a single connectivity script, and has since been converted to a proper module with a `Public`/`Private` structure, a Pester test suite, and 35 exported functions - all orchestrated by one command:

Invoke-GSAClientConnectivityCheck

And the good part is, it's open source and build in PowerShell!

What it can do:
> `Invoke-GSAClientConnectivityCheck` runs everything and prints a pass/warn/fail summary
> Local checks: service health, Entra device/PRT status, cached forwarding profile (registry + timestamp), proxy detection, Secure DNS, IPv6, event log, DNS/TLS/mTLS to the edge
> Private Access: checks whether a target FQDN/IP + port + protocol is allowed by the cached profile, and whether it actually goes through the tunnel (synthetic 6.6.x.x + private DNS resolver) and assignments
> mTLS auth certificate: check, backup, and a guarded repair (always backs up first and needs two confirmations before deleting)
> Graph-based tenant checks: forwarding profile assignment, Private Access app segments, and Intelligent Local Access private networks with public probe FQDNs/DNS servers. That last one can make GSA bypass Private Access traffic for users who were never on the corporate network
> Real-world edge cases: Cisco VPN split-DNS REFUSED lookups, home subnets overlapping Private Access IP rules, hosts-file overrides of the tenant DNS names
> It also lists the GSA service principals you should exclude in App Protection policies and checks whether they exist in your tenant
> ...and more. 35 exported functions, Pester tests, and every check can run on its own!

How to install you may think? 🤔

Install-Module GSAClientDiagnosticsToolkit -Scope CurrentUser -AllowPrerelease

or clone it from GitHub.

It's a pre-release, so I'd like to hear:

  1. What GSA problems have you hit that a check like this should catch?

  2. Anything that gives false positives in your environment?

GitHub: michaelmsonne/GSAClientDiagnosticsToolkit: A PowerShell module that runs connectivity, proxy, health probe, mTLS diagnostic checks for the Microsoft Global Secure Access (GSA) Client, validate Service Principals and more!

Write-up with screenshots and more can you find on my blog: GSAClientDiagnosticsToolkit is here: a PowerShell module to find out why Global Secure Access isn't working on your device · Michael Morten Sonne | Microsoft MVP

(Disclosure: I'm the author. It's a free community project, not a Microsoft-supported tool)

#Microsoft #MVP #MVPBuzz #GSA #Community #Identity


r/PowerShell • • 3d ago

Question I'm a sysadmin and I made a cartoon about our basement because therapy is expensive

3 Upvotes

Five IT people. One windowless basement. 14,000 users who keep breaking things.

I work in IT and started turning the stuff we all live through into a little animated sitcom. Episode 1, "The Ticket", is up now. If you've ever closed a ticket that said "it doesn't work" with zero other info, this one's for you.

The cast:

- Lasse – network (it's always DNS)
- Pia – support (has heard every excuse)
- Micke – sysadmin (has rebooted things you wouldn't believe)
- Kalle – security (trusts no one, especially McAfee)
- Svenne – hardware (has seen what's inside your laptop)

The channel is about 15 minutes old, so be gentle 😅

https://www.youtube.com/@TheITCrewToons

Which of your worst tickets should become an episode? I'm genuinely taking requests.


r/PowerShell • • 4d ago

Information I built a Cyberpunk 2077 style shell for Windows using PowerShell and WPF

1 Upvotes

Hey everyone,

I wanted to share a project I've been working on: Night City OS. It's a fully functional Windows shell replacement inspired by Cyberpunk 2077.

It's written entirely in PowerShell and WPF, and it uses WebView2 for the embedded Chromium browser and a built-in AI chat (DeepSeek).

Features:

  • Custom WPF interface with neon/dark theme

  • Built-in file manager and system monitoring

  • Embedded browser (WebView2)

  • AI chat integration

  • Autostart and "replace desktop" modes

It's completely open-source. You can check it out here: https://github.com/kisllik/Cyberdeck

If you like it, you can support the project via the link in the README. Let me know what you think!


r/PowerShell • • 5d ago

Question PowerShell Editor Services on Linux, how to get completions that are Windows-specific?

8 Upvotes

For example, I'm not getting completions for Get-CimInstance and bunch of other Windows-specific modules.


r/PowerShell • • 6d ago

Question Importing specific rows from a .xslx-file to a .csv file

12 Upvotes

This is probably the most simple thing ever so apologies.

So I have an Excel worksheet and I want to import the data from specific rows, if column D in those rows has a certain value in it.

So using ImportExcel what I have is:

import-excel -path "filelocation" -WorksheetName "Worksheetname" | export-csv -path "exportlocation" -NoTypeInformation

What would be the missing bit to get the specific info I'm looking for? Again, I'm sorry for asking for what is probably a very simple solution.


r/PowerShell • • 7d ago

Script Sharing ConsoleMonster - For those living in Terminal

13 Upvotes

I've something new for you today. I've rebuild my old ConsoleMonster module that used to be Spectre+Termina.GUI wrapper into completely new PowerShell/.NET library. I never really thought of bringing it back as PwshSpectreConsole was doing quite a good job, however I had a larger need for some of my new projects so here it is.

This starts with a different idea of having:

  • Everyday use with 1 cmdlet when you just want to chill in terminal (Enable-ConsoleFormatting)

  • Monster when you want to give your modules/libraries new ways to build TUI

PowerShell is the first-citizen here and a lot of power went into it to make daily life of living in console much nicer. It supports both PowerShell 5.1 (yes all my modules will continue to do so), and PowerShell 7.4+

ConsoleMonster 2.X is a Codex & Claude baby. I don't code since a year now so everything I do is AI.

The website has all sort of demos: https://consolemonster.dev/demos

Each demo has PowerShell code, C# code and C# Fluent depending on what you're building and how you want it.

The library also uses my other projects to deliver charting & markdown in terminal:

The module/library has really fancy features like console recordings and things that could be used in demos/websites and PowerPoint. The demos on the website are all dog-fooding so all the recordings you see there are real.

There are no external dependencies (aside my own mentioned above - opt-in) to it. It's interactive, with mouse support, thread safe and of course multi-platform. It has auto-fallbacks depending on what terminal you're usin so macos, linux, and windows all should work just fine.

I'm sure there are bugs and issues - but that's why there is Issues/PR section on GitHub. I've made sure the documentation is quite large and easy to follow, but if something is not clear or too complex let me know. We can always improve API.

Happy to hear your thoughts


r/PowerShell • • 6d ago

Question scripts don't work

0 Upvotes

I get this error when running a script. I'm not tech savvy at all, and I couldn't find an answer anywhere. Please help. The error:

irm : 404: Not Found

At line:1 char:2

+ irm (imagine a link here, can't type it for reddit auto-filters) ...

+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException

+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand


r/PowerShell • • 8d ago

Script Sharing Enjoy a,fun game of Minesweeper

21 Upvotes

I got bored the other night after work and killed the time making Minesweeper. There wasn't a lick of AI help here, just old man brain and an appreciation for bitwise operators. Fully functional Minesweeper in less than 200 lines of PowerShell. Enjoy!

Default board is 9x9 with 10 mines like classic minesweeper. You can change the size by updating the variables, but I don't have logic in there to make sure the board will work. That's on you.

Controls: Up/down/left/right arrows = move Spacebar = sweep the cell F = set flag

function CalculateProximity {
    for ($col = 0; $col -lt $Script:field.GetLength(0); $col++) {
        for ($row = 0; $row -lt $Script:field.GetLength(1); $row++) {
            #This is a mine. Set proximity to -1 and continue to next cell.
            if ($Script:BIT_MINE -eq ($Script:field[$col, $row] -band $Script:BIT_MINE)) {
                $Script:proximitymap[$col, $row] = -1
                continue
            }
            $proximity = 0
            for ($tempX = $col - 1; $tempX -le $col + 1; $tempX++) {
                for ($tempY = $row - 1; $tempY -le $row + 1; $tempY++) {
                    #out of bounds, skip
                    if ($tempX -lt 0 -or $tempY -lt 0) { continue }
                    if ($tempX -ge $Script:field.GetLength(0) -or $tempY -ge $Script:field.GetLength(1)) { continue }
                    #skip the current [col,row] cell itself, only calculate cells around it
                    if ($tempX -eq $col -and $tempY -eq $row) { continue }
                    if ($Script:BIT_MINE -eq ($Script:field[$tempX, $tempY] -band $Script:BIT_MINE)) { $proximity++ }
                }
            }
            $Script:proximitymap[$col, $row] = $proximity
        }
    }
}

function DrawFullField() {
    Clear-Host
    $text = [string]::new("#", $Script:field.GetLength(0))
    for ($i = 0; $i -lt $Script:field.GetLength(1); $i++) {
        $Host.UI.RawUI.CursorPosition = [System.Management.Automation.Host.Coordinates]::new(0, $i)
        $Host.UI.Write($text)
    }
    UpdateUI
}

function Sweep($CursorPos, [switch]$isRoot) {
    $Host.Ui.RawUI.CursorPosition = $CursorPos
    $val = $Script:field[$CursorPos.X, $CursorPos.Y]

    #swept previously or there is a flag set, exit
    if ($SCRIPT:BIT_SWEPT -eq ($val -band $SCRIPT:BIT_SWEPT)) { return $false }
    if ($Script:BIT_FLAG -eq ($val -band $Script:BIT_FLAG)) { return $false }

    #mine is here.
    if ($Script:BIT_MINE -eq ($val -band $Script:BIT_MINE) -and $isRoot.IsPresent) {
        $Host.UI.Write("*")
        $Host.UI.RawUI.CursorPosition = $CursorPos
        return $true
    }
        
    #Mark this cell as swept
    $Script:field[$CursorPos.X, $CursorPos.Y] = $Script:field[$CursorPos.X, $CursorPos.Y] -bor $SCRIPT:BIT_SWEPT    

    #Get the mine proximity on this cell. 0 = no mine. Positive = Mines Nearby. Negative = This cell is a mine.
    $proximity = $Script:proximitymap[$CursorPos.X, $CursorPos.Y]
    if ($proximity -ge 0) {
        $Script:UncheckedCells--
    }
    #Proximity > 0, write the number of nearby mines. 0, sweep through all adjacent cells that are also empty opening the field
    if ($proximity -gt 0) {
        $Host.UI.Write([System.ConsoleColor]::Yellow, [System.ConsoleColor]::Black, $proximity)
        $host.UI.RawUI.CursorPosition = $CursorPos
        return $false
    }
    elseif ($proximity -eq 0) {
        $Host.UI.Write(" ")
        $host.UI.RawUI.CursorPosition = $CursorPos
        for ($x = $CursorPos.X - 1; $x -le $CursorPos.X + 1; $x++) {
            for ($y = $CursorPos.Y - 1; $y -le $CursorPos.Y + 1; $y++) {
                #out of bounds, skip
                if ($x -lt 0 -or $y -lt 0) { continue }
                if ($x -ge $Script:field.GetLength(0) -or $y -ge $Script:field.GetLength(1)) { continue }
                #already swept or flag set, skip
                if ($SCRIPT:BIT_SWEPT -eq ($Script:field[$x, $y] -band $SCRIPT:BIT_SWEPT)) { continue }
                if ($Script:BIT_FLAG -eq ($Script:field[$x, $y] -band $Script:BIT_FLAG)) { continue }

                $null = Sweep -CursorPos ([System.Management.Automation.Host.Coordinates]::new($x, $y))
            }
        }
        $host.UI.RawUI.CursorPosition = $CursorPos
        return $false
    }
}

function UpdateUI {
    $Column = $Script:field.GetLength(0) + 3
    $UICoordinates = [System.Management.Automation.Host.Coordinates]::new($Column, 0)
    $Host.UI.RawUI.CursorPosition = $UICoordinates
    Write-Host ("Unchecked Cells: {0:D3}" -f $Script:UncheckedCells) -NoNewline
    $UICoordinates.Y++
    $Host.UI.RawUI.CursorPosition = $UICoordinates
    Write-Host ("      Flags Set: {0:D3}" -f $Script:FlagsSet) -NoNewline
    $UICoordinates.Y++
    $Host.UI.RawUI.CursorPosition = $UICoordinates
    Write-Host ("Remaining Mines: {0:D3}" -f $Script:RemainingMines) -NoNewline
}

function GameOver {
    for ($x = 0; $x -lt $Script:field.GetLength(0); $x++) {
        for ($y = 0; $y -lt $Script:field.GetLength(1); $y++) {
            $Host.UI.RawUI.CursorPosition = [System.Management.Automation.Host.Coordinates]::new($x, $y)
            switch (($Script:field[$x, $y] -band ($Script:BIT_MINE + $Script:BIT_FLAG))) {
                ($Script:BIT_MINE + $Script:BIT_FLAG) { $Host.UI.Write([System.ConsoleColor]::White, [System.ConsoleColor]::Green, 'F'); break; }
                ($Script:BIT_MINE) { $Host.UI.Write([System.ConsoleColor]::Black, [System.ConsoleColor]::Red, '*'); break; }
                ($Script:BIT_FLAG) { $Host.UI.Write([System.ConsoleColor]::Cyan, [System.ConsoleColor]::Magenta, 'X'); break; }
            }
        }
    }
}

#---Enter Script Here. Edit these three variables to change game size/difficulty
$columns = 9
$rows = 9
$mines = 10

$SCRIPT:BIT_MINE = 1
$SCRIPT:BIT_FLAG = 2
$SCRIPT:BIT_SWEPT = 4

$Script:field = [int[, ]]::new($columns, $rows)
$Script:proximitymap = [int[, ]]::new($columns, $rows)

$Script:UncheckedCells = $field.Length
$Script:RemainingMines = $mines
$Script:FlagsSet = 0
$filledMines = 0
while ($filledMines -lt $mines) {
    $posX = Get-Random -Maximum $columns
    $posY = Get-Random -Maximum $rows
    if ($Script:field[$posX, $posY] -ne 1) {
        $Script:field[$posX, $posY] = 1
        $filledMines++
    }
}
CalculateProximity
DrawFullField

$over = $false
$win = $false
$CursorPos = [System.Management.Automation.Host.Coordinates]::new(0, 0)
$Host.UI.RawUI.CursorPosition = $CursorPos
while (-not $over -and -not $win) {
    [Console]::CursorVisible = $true
    $nextKey = [Console]::ReadKey($true)
    [Console]::CursorVisible = $false
    switch ($nextKey.Key) {
        'RightArrow' { if ($CursorPos.X -lt $columns - 1) { $CursorPos.X++ }; $Host.UI.RawUI.CursorPosition = $CursorPos; break; }
        'LeftArrow' { if ($CursorPos.X -gt 0) { $CursorPos.X-- }; $Host.UI.RawUI.CursorPosition = $CursorPos; break; }
        'UpArrow' { if ($CursorPos.Y -gt 0) { $CursorPos.Y-- }; $Host.UI.RawUI.CursorPosition = $CursorPos; break; }
        'DownArrow' { if ($CursorPos.Y -lt $rows - 1) { $CursorPos.Y++ }; $Host.UI.RawUI.CursorPosition = $CursorPos; break; }
        'SpaceBar' { $over = Sweep -CursorPos $CursorPos -isRoot; break; }
        'F' {
            if (-not ($BIT_SWEPT -eq ($Script:field[$CursorPos.X, $CursorPos.Y] -band $Script:BIT_SWEPT))) {
                $Script:field[$CursorPos.X, $CursorPos.Y] = $Script:field[$CursorPos.X, $CursorPos.Y] -bxor $Script:BIT_FLAG
                if ($Script:BIT_FLAG -eq ($Script:field[$CursorPos.X, $CursorPos.Y] -band $Script:BIT_FLAG)) {
                    $Host.UI.Write([System.ConsoleColor]::Cyan, [System.ConsoleColor]::Black, "F")
                    $Script:FlagsSet++
                    $Script:UncheckedCells--
                    if ($Script:RemainingMines -gt 0) {
                        $Script:RemainingMines--
                    }
                }
                else {
                    $Host.UI.Write("#")
                    $Script:FlagsSet--
                    $Script:RemainingMines++
                    $Script:UncheckedCells++
                }
                $Host.UI.RawUI.CursorPosition = $CursorPos
            }
            break
        }
    }

    UpdateUI
    $Host.UI.RawUI.CursorPosition = $CursorPos

    if ($Script:UncheckedCells -eq $Script:RemainingMines) { $win = $true }
}

if ($win) {
    $Host.UI.RawUI.CursorPosition = [System.Management.Automation.Host.Coordinates]::new(0, $rows + 2)
    $Host.UI.Write("YOU WIN!")
}
elseif ($over) {
    GameOver
    $Host.UI.RawUI.CursorPosition = [System.Management.Automation.Host.Coordinates]::new(0, $rows + 2)
    $Host.UI.WriteLine("GAME OVER")
    [Console]::CursorVisible = $true
}

r/PowerShell • • 7d ago

Script Sharing I modernized a classic DOS-era file-transfer batch tool in PowerShell 7 (USB splitting, FTP, OneDrive, Dropbox, ISO) – feedback welcome

0 Upvotes

Hi all,

I've been working on Llevar, a PowerShell 7 rewrite of LLEVAR.BAT, a classic batch tool by Alex Soft (Alejandro Nacir) for moving big folders around when plain copy isn't enough.

What it does

  • Compresses and splits data into blocks (for USB sticks, floppies, or size-limited targets)

  • Transfers between local paths, UNC shares, FTP/FTPS, OneDrive and Dropbox

  • Can generate an ISO instead of writing to USB

  • Interactive menu (and plain parameters for scripting)

Quick try

.\Llevar.ps1 -Source "C:\Data" -Target "D:\Backup" -Compress -Split

The core idea: path detection + a dispatcher

Every source/destination is classified by a tiny set of validators:

function Test-IsFtpPath     { param([string]$Path) return ($Path -match '^ftp://|^ftps://') }
function Test-IsOneDrivePath{ param([string]$Path) return ($Path -match '^ONEDRIVE:') }
function Test-IsDropboxPath { param([string]$Path) return ($Path -match '^DROPBOX:') }
function Test-IsUncPath     { param([string]$Path) return ($Path -match '^\\\\') }

Then a single dispatcher routes each origin→destination pair to the right function (abridged):

function Invoke-TransferDispatcher {
    param($Llevar, [bool]$ShowProgress = $true, [int]$ProgressTop = -1)

    $tipoOrigen  = $Llevar.Origen.Tipo
    $tipoDestino = $Llevar.Destino.Tipo
    $route = "$tipoOrigen→$tipoDestino"

    $result = switch ($tipoOrigen) {
        "Local" {
            switch ($tipoDestino) {
                "Local"    { Invoke-LocalToLocal -Llevar $Llevar ... }
                "FTP"      { Invoke-LocalToFtp   -Llevar $Llevar ... }
                "OneDrive" { Invoke-LocalToCloud -Llevar $Llevar -CloudType "OneDrive" ... }
                "USB"      { Invoke-LocalToUSB   -Llevar $Llevar ... }
                "ISO"      { Invoke-LocalToISO   -Llevar $Llevar ... }
                default    { throw "Unsupported combination: Local→$tipoDestino" }
            }
        }
        "FTP" { ... }   # same pattern for FTP, OneDrive, Dropbox and UNC sources
    }
}

Requires PowerShell 7+ on Windows 10/11.

Repo: https://github.com/javiprieto89/Llevar (there's an animated demo of the menu at the top of the README)

Disclosure: parts of this project were developed with the help of AI tools (Claude).

I'd really like feedback on:

  1. Which destination would be most useful next (SFTP? S3? Google Drive?)

  2. Anything that breaks in your scenario

  3. Would you use it as a PowerShell Gallery module?

If it's useful, a star helps others find it. Thanks!


r/PowerShell • • 7d ago

Script Sharing A Journey from CCleaner to FreeWinly: Automated Windows Administration in Pure PowerShell

0 Upvotes

My CCleaner license ran out and I had to pay again to manage multiple of my win-pcs, or so I thought.

Then I remembered playing around with winget and the Windows Event Log via cli and I wandered into the rabbit hole of what's already available in PowerShell tooling.

Don't get me wrong. The last year or two I loved having CCleaner just taking care of my PCs. It was a great offer I've been glad to use, but not everything was flawless.

I found myself uninstalling CCleaner to give me the right incentive to push through the next exercise of figuring it out. Just to figure out that uninstalling CCleaner wasn't so easy. It crashed multiple times and didn't finish uninstalling, had to be cleaned up manually, then all of my suspended startup apps stopped working. My exe was not found, but it clearly was in the right folder.

Luckily, I figured out that CCleaner hijacked app launches via the Debugger value in Image File Execution Options (IFEO) and left orphans behind. After removing those registry entries I was able to start Steam again. Not that I've time to play on Steam that much anymore, but I keep Cyberpunk, Nioh 3 and NFS installed and updated at all times 😄

Why not make a script for exactly this repair job?

The idea was born and over the next weekends and most of my spare time I figured out software updates via winget and how to handle applications that work better with native app updates than using winget.

Browser, app, and network cache cleanup were also something on my mind, and while checking my disk I found gigabytes of old install files from windows updates that were just using up space on my fast and very expensive SSD. Since I don't want to lose the performance benefits of caching, adding a file-age-filter made a lot of sense to me.

Trim and DISM were just easy to add and the DISM Component Store cleanup (/StartComponentCleanup) to purge superseded updates cleaned up some highly appreciated space.

And while I was at it, why not add hardware and driver scans, which especially come in handy for my ROCm hardware, which I love to see improving with each update.

A TUI launcher, scheduling capabilities e.g. over start menu start-up folder or via task scheduler and a standard and expert view for all the configuration, which is stored in a config.json next to the cmd.

I've designed this whole tool modular so everyone can drop in custom scripts without affecting future updates of the core engine.

Of course this is all written in native PowerShell and CLI supported, and the cherry on top is an LLM skill, so that anyone can use their LLM to analyze their PC checking the logs of this tool without giving the LLM a ton of permissions. I know there are still a lot of people not putting that much trust into LLMs, so the standard version does not contain this LLM skill. It's considered an opt-in.

As a side note on AI disclosure: While heavily AI-augmented during creation, all the core architecture, feature ideas, modular concepts, and TUI design came directly from human taste and vision. Letting AI assist with bug hunting, refactoring, and running security audits across different personas was a great workflow enhancement that I would recommend to any project. All code runs on native PowerShell 5.1/7+.

I would love to see community feedback on this project and of course a few stars on github if you really like it. It's open source with MIT License, so everyone can just analyze everything and there is no hidden code or script execution, just plain and simple PowerShell.

If you are interested in the details or the repo, check out FreeWinly: https://github.com/LycosLane/freewinly


r/PowerShell • • 8d ago

Script Sharing I have a PhD-level background in static analysis, but I spent my week fighting PowerShell Runspaces just to delete duplicate memes.

3 Upvotes

As someone who usually deals with static analysis and abstract interpretation, I should know better. I should know that PowerShell is a single-threaded environment. I should know that building GUIs in PowerShell is an "obtuse mess".

But I also have 200GB of duplicate photos and videos, and I refuse to use a CLI for that.

So I present to you: **Duplicate Finder PRO**. A full WinForms GUI built entirely in PowerShell. Yes, I know. I hate myself too.

Here is a breakdown of my descent into madness:

* **The "Single-Thread" Trauma:** The first version froze every time I clicked a button. I had to learn the dark arts of `[runspacefactory]::CreateRunspace()` and `[System.Collections.Concurrent.ConcurrentQueue]` to stop the UI from hanging. If you've ever seen your PowerShell GUI go "Not Responding", you know my pain.

* **The PS2EXE Struggle:** I wanted a single portable EXE. I spent hours fighting with `$PSScriptRoot` returning empty strings inside the compiled EXE. I think I cried a little.

* **The Cache:** It uses a two-step detection (File Size + SHA-256) and saves a CSV cache. The second time you scan, it skips the hashing entirely. Because if I'm going to sin against god by making a PowerShell GUI, I might as well make it fast.

It works. It has a progress bar and a preview window where you can double-click to compare files side-by-side.

I'm sharing it here because I need validation, but also because I want to know: **What is the biggest cardinal sin you've ever committed in PowerShell just to avoid using the terminal?**

You can download the portable EXE and roast my UI here:

👉 https://github.com/lucanegrianalyst/duplicate-finder-pro/releases/latest

Please be gentle. I'm just an analyst trying to find my duplicates.

***AI Disclosure:** I used an AI to help me structure this post and fix my English, but the PowerShell code, the Runspaces, and the tears are 100% mine.*


r/PowerShell • • 9d ago

Information Wanted: Awesome PowerShell Modules

43 Upvotes

Hey r/powershell! I've just published an Awesome PowerShell Modules list (using the awesome-lists format) in GitHub:

- https://github.com/markwragg/awesome-powershell-modules#readme

I used AI to assist with the curation, but it was built from a combination of my personal experience with many of the modules, as well as a scan of modules mentioned on the PowerShell Podcast, PowerShell Weekly newsletter, Powershell.news and some previous PowerShell related Awesome lists that I found.

I've tried to review as many of the modules as I could, but if anyone finds that there's a module listed that is no longer working please let me know. As a general rule, the list attempts to only include modules that are still actively being developed, or are feature complete. Modules where the GitHub repo has been archived (or appear largely abandoned), are intentionally excluded.

If you know of (or are the maintainer of) a module that you'd like included, please feel free to either let me know here or raise a PR. Ideally the module should make someone want to say "wow that's awesome" :), must be published in the PowerShell Gallery and be at least 30 days old.

There's a couple of PowerShell scripts under /scripts in the repo which you can use against the list. One returns all of the modules, their URLs, author and number of downloads. The other aggregates by author. The latter reveals that I put my own modules on the list 8 times, but hey It's my list and I'll use it to shamelessly self promote if I want to 😂.


r/PowerShell • • 9d ago

Information Give me your biggest syntax highlighting complaints! I'm working on improving VS Code's syntax highlighting (including support for non-Verb-Noun function names)

11 Upvotes

Tl;dr - I'm working on improving VS Code's syntax highlighting for PS so tell me what issues you encounter. Please include a code sample and what theme you're using.


I've seen a bit of discussion recently about the state of VS Code's syntax highlighting for PowerShell. I looked into it a bit and yeah, it's not ideal. The official repository pretty inactive. Last commit was 6 months ago, last significant activity was years ago. I opened an issue a week ago because the main branch doesn't even pass all of it's own tests, and an accompanying PR to fix it, but no movement on that yet. So I've taken things a bit into my own hands for now and hopefully when the maintainers get around to it, they'll be able to take some of the stuff I'm working on upstream.

So far I've switched the testing framework away from using Atom (an editor that's EOL since 2022) to a modern harness around VS Code's tokenizer/regex engine, a little bit of CI, several new unit tests for better regression testing, and these new features in the syntax grammar so far:

  • Highlighting for null operators (??, ??=, ?., ?[])

  • Highlighting for variable names with question marks in them (e.g. $whyIsThis?Possible = "idk")

  • Highlighting for function names that don't use the Verb-Noun naming convention (e.g. DoSomething instead of Invoke-Something)

This is very much still WIP. I've got more tests I want to write and a few new features I want to add, but please let me know what issues you have with PS syntax highlighting and I will look into them.

GitHub repo here; Overview of updates with images here.


r/PowerShell • • 10d ago

Misc Microsoft Graph documentation really is bad

112 Upvotes

Despite its reputation for poor documentation, I decided to give the Microsoft Graph PowerShell module a try for a few basic license related tasks. I reviewed the Microsoft Graph PowerShell SDK overview page and clicked Get-started only to be greeted by 404 - Page not found.

Feels like they've completely given up on documentation, huh