r/PowerShell 2d ago

Script Sharing What have you done with PowerShell this month?

15 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 12h ago

Question Recurring script maintenance

0 Upvotes

I'd honestly pay someone else to keep my voice scripts alive if it meant I never had to touch them again after a Windows update. Am I just lazy or is maintaining ur own automation actually the worst part of the whole thing?


r/PowerShell 1d ago

Information Python through PowerShell text colors are hard to read

8 Upvotes

Posting because I'm probably not the first person to lose ~4 hours trying to get to the bottom of this. My issue was: I was running python through a PowerShell window and the color of the text made error messages very hard to read.

In short: Download Windows Terminal and use that. You'll still be running PowerShell, it will just be inside a Windows Terminal window. The colors will be readable. Yes, its silly how there is now a 3rd way of running a terminal in Windows (Command Prompt, PowerShell, Windows Terminal).

So far as I know, python uses the colors that PowerShell defines for different kinds of text. I haven't yet found a way to successfully change all the text color categories in a basic PowerShell window.

  • Right clicking the top of the window and going to properties only lets you change the color of the basic text. not the problematic red and blue that is hard to read.
  • Changing the registry values at Computer\HKEY_CURRENT_USER\Console for ColorTable00 through ColorTable15 didn't change the colors used by PowerShell
  • There was an official program called color tool for changing the colors, but it appears it was last updated in 2019 and its .exe file failed to run on my Windows 10 computer.
  • I don't know if there is/isn't a way to redefine what colors python itself tries to print stuff.

If someone does know a working non-Windows Terminal way to fix ALL of PowerShell's/Python's hard to read text colors I'd be happy to hear it in the comments.


r/PowerShell 1d ago

Question Check for App updates on home PC

9 Upvotes

Afternoon,

I am trying to write a script that will let me know about updates to the apps installed on my home PC.

I saw on a Sysadmin thread about https://eucpilots.com/evergreen/ and thought it would be as simple as reading all of the installed apps and then querying each one like this:

$reg = @(

'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*' 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
GP $reg -EA 0|?{$_.DisplayName -ne $null} | Find-EvergreenApp $_.DisplayName

However when testing, the Evergreen is not expecting the App name to have spaces, so is my only option to split the string and put an asterisk at the end of the first section?

PS C:\Windows\System32> Find-EvergreenApp Telegram
Name            Application      Link
----            -----------      ----
TelegramDesktop Telegram Desktop https://desktop.telegram.org/

r/PowerShell 2d ago

Script Sharing Remixing Music with RoughDraft and PowerShell

8 Upvotes

This weekend I figured out how to remix music with PowerShell, RoughDraft, and ffmpeg.

Sample + Filter.

Rinse & Repeat.

RoughDraft + ffmpeg makes this all pretty easy.

Step 1 - Get Your Sample Source

RoughDraft includes an extension for yt-dlp. This can download media from almost anywhere. Just browse to a site with a song, set a $SongUrl variable, and download

Get-Media -MediaUrl $MediaUrl

Step 2 - Sample a Section

You can sample a section of audio or video with the -AudioTrim and -Trim filters. If we want the first few seconds of a song, we can use the AudioTrim filter, like so:

$sample = Edit-Media $song -AudioTrim -TrimStart "00:00:00" -TrimEnd "00:00:05"

Step 3 - Filter

ffmpeg is full of filters. There are hundreds of them, and RoughDraft supports a fair number.

Suppose we want to make our sample Vibrato. We can just use Edit-Media -Vibrato

$sample | Edit-Media -Vibrato

Or we could change the -PitchFactor, making it sound slower or faster while keeping the tempo intact.

$sample | Edit-Media -PitchFactor 0.81

Or we could use an Audio Compressor, with a short attack and release and a makeup to make the sounds louder

$sample | Edit-Media -Compressor -CompressorAttack 5 -CompressorRelease 10 -CompressorMakeup 2.5

Rinse and Repeat

The possibilities are endless. ffmpeg is an audio/video production tool of truly unparalleled capability.

All of that power is in your shell, in a format that's far easier to read and understand than direct filtergraph syntax. Edit-Media currently has a whopping 682 parameters to mix and match, all supporting tab completion.

This makes it easy to iterate and innovate. It took just about an hour after figuring this out to make my first little remix, just by sampling/filtering/rinsing/repeating.

The latest RoughDraft release includes a bunch of new audio filters to help assist and more will keep on coming with every release.

Hope this helps & Have Fun!


r/PowerShell 1d ago

Script Sharing Tooling with Claude and pwsh

0 Upvotes

Hey all!

I was hoping you’d could inspire me please! I currently work in a desktop/infra role in a finance company and was wondering if anyone had any cool tooling they created using Claude code? I really lack in coming up with ideas so just curious as to what other people have done and yeah, honestly I’d like to try and see if that could work for us!

I’m talking like automation for JML, dashboards, alerting, tools to help the team, tools that we can use for users to fix quick issues?

I realise I’d just be taking your ideas but I can’t really come up with anything myself!

Thanks!


r/PowerShell 3d ago

Question Add Date Taken as prefix to filename

9 Upvotes

I need some help. I have lots of photos (IMG_xxxx.jpg), and I would like to change the filenames using this convention (yyyymmdd_IMG_xxxx.jpg). This is the command line I am using in PowerShell:

Get-ChildItem -File | Rename-Item -NewName { $_.LastWriteTime.ToString("yyyyMMdd_") + $_.Name }

This seemed to work great until I realized the last write time didn't match the date taken. I want to use the date taken from the EXIF field.

I have found the GetDetailsOf command and know that Date Taken is the 12th property. How can I use this in a command line prompt in PowerShell?

Assumptions for my specifics:

  • all files are .jpg with Date Taken data
  • all files are in the current folder
  • renamed files will replace original in the current folder

This way, I don't have to worry about writing a script to determine path names or renaming to a different folder.

The code provided above works perfectly if the date I wanted was the last write time. Is there an easy way to modify this to use Date Taken instead?

TIA


r/PowerShell 2d ago

News No Homebrew Cask for Powershell

0 Upvotes

Homebrew removed the official powershell cask because the official Microsoft .pkg installer repeatedly failed macOS Gatekeeper checks. Homebrew moved everyone to a community-built formula instead, enforcing their policy to disable casks that fail Gatekeeper.

While the original removal aligned with Homebrew's policy, the underlying signing issue is resolved. Microsoft’s official macOS .pkg (tested on version 7.6.5) is now signed with a Developer ID Installer certificate (Microsoft Corporation, team ID UBF8T346G9) and fully notarized by Apple.

This alternative cask installs Microsoft's official, unmodified release file. Unlike the community formula, this package includes the embedded .NET runtime, requiring no extra dependencies.

Installation:

sh brew install --cask darkn3rd/tools/powershell-pkg


r/PowerShell 3d ago

Script Sharing I built MonitorAutoSwitch - automatically moves my laptop display to the correct side of my monitor (home vs office) based on my public IP

5 Upvotes

The problem: at home my laptop sits to the right of my ultrawide, at the office it sits to the left of the monitor. Windows kept getting confused after docking, so every arrival was alt-tabbing into Display Settings and dragging rectangles around.

What it does: a small PowerShell tool that detects where I am via my public IP and repositions the laptop display on the correct side of the main monitor. Triggers on logon, wake from sleep and display connect, plus a once-a-minute display-count watcher. Comes with a WinForms setup wizard, a system tray toggle, and a per-user installer (no admin rights, everything lives in %LOCALAPPDATA% and Task Scheduler).

The bug that took months: the first version stored absolute coordinates (X=5120) and randomly failed with DISP_CHANGE_FAILED (-1) from ChangeDisplaySettingsEx. Root cause turned out to be two-fold: the monitor sometimes runs at a non-native resolution, and a non-DPI-aware PowerShell process sees scaled coordinates - so the target position landed outside the desktop. The fix: store only "left" or "right" + a Y offset, compute the real X from the live display widths on every run, and opt the process into per-monitor DPI awareness via SetProcessDpiAwarenessContext. Also worth knowing: Windows can hand out high device numbers like \.\DISPLAY13, so don't enumerate only DISPLAY1-9.

GitHub (MIT): https://github.com/dimitrihilverda/MonitorAutoSwitch

Full disclosure: built in pair-programming style with Claude - the design decisions and months of debugging pain are mine, a good chunk of the typing was not. Feedback on the Win32 interop is very welcome.


r/PowerShell 3d ago

Question Manifest required modules not auto-importing in 5.1

8 Upvotes

Hello. I'm genuinely stumped, to the point where I'm about to abandon this side project altogether

I have a test module I'm creating using a manifest file, Template.psd1. The module depends on these other module files I created:

```

Modules that must be imported into the global environment prior to importing this module

RequiredModules = @(     'Control\ControlMessaging.psm1'     , 'Control\ControlChecklist.psm1'     , 'Control\ControlPrompt.psm1' ) ```

The are present in the subfolder "Control", which is in the same folder as the manifest and PSM1 files.

When I execute Import-Module in powershell 7.4, the module loads without bitching.

When I execute in 5.1, I get an error

Import-Module : The specified module 'Control\ControlMessaging.psm1' was not loaded because no valid module file was found in any module directory.

According to the documentation, this should be kosher: about_Module_Manifests It should auto import those modules, but it's not working.

I do need this to run in both 5 and 7. Any ideas?


r/PowerShell 4d ago

News Running a Regular Check for New Graph Permissions

11 Upvotes

Use PowerShell to Check for New Graph Permissions with a View to Updating Permissions Used by Apps.

After Microsoft released some new Graph permissions, thoughts turned to how to discover new permissions after they are released. Code is the best way to perform automatic checks, and this article explains how to use PowerShell to check a last known set (stored in SharePoint Online) against the current set. Any variations are reported to administrators via email.

https://office365itpros.com/2026/08/31/new-graph-permissions-check/


r/PowerShell 4d ago

Solved Transcript 5.1 Unexpected behaviour

3 Upvotes

Probably SOLVED:

  1. A previous

    Unlock-SecretVault

killed the transcribing

It spawns a subprocess for the credential management and when its done it sends exit code back to host which killed my transcribing by design.

3h gone

Hi,

when i am in a 5.1 shell and start a controller.ps1 script:

C:\User> C:\PSR\Controller.ps1 -TargetScript C:\Jobs\..

The Controller script uses Start-Transcript to capture the output of a $TargetScript

however. When I start the controller.ps1 script as shown here my currently forced error (Get-ADUser -xzyisks) appears in the log.

When i start

powershell.exe -File Controller.ps1 -TargetScript C:\Jobs\..

it suddenly stops capturing the invocation error output. (Expected:

A parameter cannot be found that matches parameter name 'xzyisks'.)

ai suggested some transcript buffer stuff but non of it worked.

this is the important code block:

# execute binary or script
    if ($Executable) {
        & $Executable $TargetScript
    } elseif ($Config) {
        & $TargetScript -Config $Config
    } else {
        & $TargetScript
    }
    Write-Output "execution of $TargetScript completed successfully"


    #endregion main


} catch {


    # store error so finally can dispatch the mail after the transcript is finalized
    $TerminatingError = $_
    # write the error into the transcript while it is still open
    $Host.UI.WriteLine("[ERROR] $($TerminatingError.Exception.Message)")
    try   { Stop-Transcript | Out-Null }
    catch [System.InvalidOperationException] {}


} finally {


    # transcript is already closed on error paths — only close on success path
    try   { Stop-Transcript | Out-Null }
    catch [System.InvalidOperationException] {}

Can someone explain on high level what happens..

Thanks

EDIT:

My main question is:

C:\User> C:\PSR\Controller.ps1 -TargetScript C:\Jobs\..
vs
powershell.exe -File Controller.ps1 -TargetScript C:\Jobs\..

when using start transcript..


r/PowerShell 5d ago

Solved Warning: ISESteroids Update is malicious

16 Upvotes

When I launched ISESteroids (Start-Steroids) I clicked update. Chrome notified me that the website was not-safe dummy here found the run website anyway and the Avast nightmare began ... 5 popup windows that my computer had 5 virus's , anti-virus not installed, blah blah blah .. Shutdown chrome, cleared my cookies, %temp% directory.. these popups just kept reappearing if I closed one.

reboot doesn't fix anything.. nothing in task manager helps narrow down what's launching even with chrome closed... sysinternals autoruns no help. real help.

While I built a new Veeam Agent install usb to potentially restore from yesterday (3 hour process) I started poking around in chrome and in the extensions I found something I didn't recognize and deleted it.. rebooted the computer and now its back to normal without restoring from backup.


r/PowerShell 5d ago

Script Sharing Built an open-source Windows diagnostic tool in PowerShell/WPF for my thesis — feedback welcome!

13 Upvotes

Hey everyone,

I'm currently working on my IT Bachelor’s Thesis and building Fercero USB Tool — an open-source, multithreaded Windows diagnostic and repair utility (PowerShell + WPF Dark Mode GUI).

It's still a work in progress, but current features include:

  • Hardware Scan: OS/CPU/RAM info, VRAM, and S.M.A.R.T. disk health.
  • System Repair: DISM/SFC scans, Windows Update cache reset, TCP/IP & DNS flushes.
  • Error Lookup: Integrated database for Device Manager codes (1–54) & critical system logs.

Since this is actively in development, I’d love some code reviews, testing, and feedback from the community!

https://github.com/SvetozarA00/Fercero-USB-Tool.git


r/PowerShell 5d ago

Question PrivateKey Test

6 Upvotes

Greetings

Is it possible to check if a private key is either RSA or ECDsa without trying to import them into their cng-objects catching the error?

I'm thinking of something like how

[X509Certificate2].GetContent($Import)

Is available for certificates

Neither the cng-objects nor the certificateextensions provide methods to test for the proper type


r/PowerShell 5d ago

Question PowerShell 7 ISE - A real conversation

4 Upvotes

Hi Everyone,

I think I need to have a reset on the way I introduced myself and my goal.

I am new to reddit and pretty much the entire open source community. I am an old school COBOL developer from the early 80's. I also know Visual Basic (about 15 years) and C# (about 4). I work on mainframes and z/OS on distributed systems (Linux). I maintain distributed apps for clients and sometimes on the mainframe. Not so much the mainframe anymore.

I use PowerShell every day. My shop uses PowerShell every day. We have 1000's of scripts, all written in 5.x that are years old.

They are not complex scripts, we don't have an Admin running a server farm or anything like that. They are just scripts that we use to make our jobs easier. Scanning files for codepages, finding Dupes using Hashes, things like that. When we run them, we use the old PowerShell ISE. We are used to it. It's easy, it looks good and it makes changing and running the script a smooth effortless event. The only issue is, that our shop has been slowly making us move away from 5.x to 7.x. This has been going on for years. I'm not happy because I lose my clean, crisp, no headache comfortable ISE. Yes, I said comfortable. I like it. We all do (at my shop). I tried to use the PowerShell plugin for VS Code. I did not like it. I really did not. So about a year or so ago, I decided to code my own. My goal was simple. I wanted to make a Daily Driver ISE for PS 7. Yes, I am going to share it with my co-workers once its finished and yes, I can and have asked a few of them to help me test it. I have gotten some good feedback from them. Not quite what I needed though. We are a simple shop, we do not do anything overly complicated and my co-workers are less than impressed with what I have shown them so far. It was buggy and did not have the feel of the ISE GUI. I felt that maybe if I turned to the PowerShell community for help, I could improve things. Actually make an App that we could use daily and transition from 5.x to 7.x without a blink.

I still want that.

I should not have started out asking if anyone still used the old ISE. That was the wrong approach, I acknowledge that. I should have just told you all my goal and left it at that.

I'm not asking anyone to jump on my bandwagon. My goal is simple, make something of value to more than just myself.

All I'm asking is, can you help me make it better.

If this post crosses a line, that crossing was unintentional. Let me know and I will walk away.

Regards,

-Ron


r/PowerShell 7d ago

News Microsoft To Enforce WAM for Delegated Interactive Graph Sessions

25 Upvotes

In a GitHub post, Microsoft says that interactive Graph sessions using the default Microsoft Graph Command Line Tools app will use the Web Account Manager (WAM) in the future. Some administrators use older versions of the Microsoft Graph PowerShell SDK for continued access to browser-based authentication, but this won’t be possible once Microsoft makes the server-side change to enforce WAM on an undefined future date. Teams and Exchange Online also use WAM, apparently for better security.

https://office365itpros.com/2026/08/28/interactive-graph-sessions-wam/


r/PowerShell 8d ago

Script Sharing XKCD PowerShell module

128 Upvotes

Years ago just for fun, I wrote a PowerShell module to query the API of the webcomic XKCD https://xkcd.com/. It has a Get-XKCD cmdlet to retrieve data about a specified or random comic, and had a -Open switch to then open its URL in a browser. You can also use Find-XKCD to perform keyword searches, and there's a local cache of the API output to speed this up and to reduce the need to do web calls.

Modern terminals now support the ability to render images directly, so I've just added Show-XKCD and Get-XKCD -Show.

This works in Windows Terminal, but should also work in iTerm2 and Kitty.

If it's of interest, you can download the module from the PowerShell Gallery here: https://www.powershellgallery.com/packages/XKCD/1.5.0

Or directly from GitHub: https://github.com/markwragg/Powershell-XKCD


r/PowerShell 6d ago

Information Cross-platform Brave policy debloater in PowerShell (dry-run default, won’t disable Shields)

0 Upvotes

Wrote a Brave debloater that uses official enterprise policies instead of deleting files / editing hosts.

Same script on Windows, macOS, and Linux. Preview mode unless you pass -Apply. Backs up first. -Doctor if some other tool already dumped junk in brave://policy. It refuses to turn off Shields, Safe Browsing, or updates.

.\Invoke-BraveDebloat.ps1 -Preset Extreme

.\Invoke-BraveDebloat.ps1 -Preset Extreme -Apply

Check it out: https://github.com/osfv/BraveDebloater


r/PowerShell 8d ago

News OMG, I love powershell

266 Upvotes

I've been coding for 2 decades, and I recently had a payroll system to Active Directory project to do, and went with powershell. It's done, it works great, and I was looking at the code today, and spontaneously declared "I love powershell". its a remote day, so no one looked at my funny, but I'll list 3 reasons I love it. Feel free to add more.

No confusion with =, == or ===.

1) Simple equals logic, no bizarre conventions: Do you know how many times I've had to fix code in JS where someone did if (variableName=something), which of course sets variableName to something, not compares it. Powershell's -eq and -ne is so much better then =, ==, ===, !=, or <>.

2)No line termination character: Line's don't require ; to end. Ok, that isn't a big deal, and my IDE would catch it anyway, but its just a waste of characters to terminate every line of code.

3)String composition: In other languages, mixing variables and text is something like "words " + variableName + ":/ more words" + variableName2. And then its like "Oh, is this one a + or an &...." With powershell I can just do varString = "words: $variableName :/ more words $variableName2" and it all works!

Now, its not like I make stupid syntax mistakes a ton in other languages, but in today's backend world, I'm expected to regularly code in 5-10 languages, and Powershell was amazingly easy to learn and the syntax is just clean.

I thought you Powershell vets might appreciate a newb's perspective on it, especially since its all positive.


r/PowerShell 7d ago

Question Scripting Categories in M365 Planner Standard

3 Upvotes

I have a Graph script which I use to generate ~370 plans in Standard Planner across ~350 groups. This year its been requested to add labels(tags, categories) to tasks as part of the roll out and I’m struggling with how that works in powershell. Has anyone done this successfully that can provide some tips?


r/PowerShell 7d ago

Question Issue with Active Setup + RunOnce and space in script path

1 Upvotes

I'm attempting to deploy VSCode with a baseline configuration to some high school computer labs, and am running into an odd issue.

As part of the install, I create an Active Setup registry key that creates a HKCU RunOnce key to call a short powershell script. That script copies a preset settings.json from a hidden folder on the C:\ drive to the current user's AppData folder.

The issue I'm running into is that if the path to the script contains a space, I cannot get the RunOnce key to work properly (it's not over 260 chars either).

Working Active Setup key:

REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce /v VSCodeCopy /t REG_SZ /d "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File C:\MyPath\VSCode_CopySettings.ps1"

Non-working Active Setup key:

REG ADD HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce /v VSCodeCopy /t REG_SZ /d "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File 'C:\My Path\VSCode_CopySettings.ps1'"

I have tried double quotes, single quotes, escaping quotes using \ and "", but I cannot get the script to function unless the script path has 0 spaces in it. RunOnce will execute powershell, but the terminal will just open and close rapidly.

I added a Read-Host in both halves of a try-catch block in the script to confirm what's happening, and neither causes the terminal window to wait for input.

Is there something I'm missing?

Edit: I'm combining Active Setup and RunOnce in order to not bog down the user login; the command to create an HKCU key is a string value in an Active Setup registry key, rather than being run by the install script, which has some limitations. However, it means I can guarantee that old and new users will have the script run a single time on login. I can also use a 'Version' registry value to make it happen again in the future if the initial configuration needs updated.


r/PowerShell 7d ago

Question Prank script

0 Upvotes

We have a culture of pranks here at the office. I’d like to create a PowerShell script that, when executed via a .bat file, rotates the Windows screen to portrait mode, zooms in, increases the cursor scale, inverts the colors, and installs the Egyptian Arabic language pack—all without requiring a reboot or anything like that. Is this possible?


r/PowerShell 8d ago

Question Mguser -filter or id

2 Upvotes

Trying to do a Foreach lookup - have a list of known userids I got from another command.

Trying to run something along these lines. Have a spreadsheet $wbs and headers and data for $ownerid which give valid azureids

foreach ($ownerId in $wbs)
{
Get-MgUser -Filter "id eq '$ownerid'"
}

or

get-mguser -UserId $ownerid    

in various forms but mguser keeps throwing errors. Usually along the line of Id cannot be a string.

Can Mguser not accept variables for Ids?

I've also tried doing a filter and it tells me its a date?

Get-MgUser -Filter "id  eq '$wbs.ownerid'"              
Get-MgUser_List: Invalid filter clause: The DateTimeOffset text '2022-01-21T15:59:17.5192675Z'";' should be in format 'yyyy-mm-ddThh:mm:ss

r/PowerShell 9d ago

Script Sharing Matrix Transforms in PowerShell

27 Upvotes

There are only so many ways we can move a point in space.

Luckily, these transformations are pretty standardized.

CSS calls them matrix and matrix3d. DotNet calls them [Numerics.Matrix3x2] and [Numerics.Matrix4x4].

With a bit of PowerShell magic, we can manipulate any set of points with a Matrix.

Matrix Module

The Matrix module lets us create and apply matrices in PowerShell, using CSS-compatible syntax. This means we can scale, rotate, and translate points in PowerShell.

Let's start with a simple example: Scaling

We can create a scaling matrix using [Numerics.Matrix3x2]::CreateScale (for 2d transforms) or [Numerics.Matrix4x4]::CreateScale (for 3d transforms)

Without the module, this looks like:

$vector = [Numerics.Vector3]::new(1,1,1)
$vector::Transform($vector, [Numerics.Matrix4x4]::CreateScale(1,2,3))

With the module, this becomes:

[Numerics.Vector3]::new(1,1,1) | Scale3d 1 2 3

The Matrix module includes aliases for every CSS transform.

We can move points in space exactly as we would move them in a webpage.

It allows us to use PowerShell's Object Pipeline to manipulate points in space.

This means we can construct and change 2d and 3d objects just by manipulating points.

Creating a Cube

We can create a cube using nothing but translations.

# Make a corner point
$corner = [Numerics.Vector3]::new(1,1,1)

# Make a square by translating along X and Y
$square = @(
    $corner
    $corner | TranslateX 1  
    $corner | TranslateX 1 | TranslateY 1
    $corner | TranslateY 1
)

# Make a cube by translating the square along Z.
$cube = @(
    $square
    $square |
        TranslateZ 1
)

$cube

Matrix CSS

All CSS transforms boil down to either a matrix() or a matrix3d().

Because of this, we can easily get any Matrix as it's CSS equivalent.

Matrix extends the .NET matrix classes with a .CSS property, so we can easily drop a matrix into a webpage or stylesheet.

For example:

(Scale 2 1).CSS

Will return:

matrix(2, 0, 0, 1, 0, 0)

In 3D:

(Scale3D 1 2 3).CSS

Will return:

matrix3d(1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1)

It gets better! Matrix converts some common CSS units into numbers, so:

(SkewX 10deg).CSS

Becomes:

matrix(1, 0, 0.176327, 1, 0, 0)

And

(SkewY 0.1turn).CSS

Becomes:

matrix(1, 0.7265425, 0, 1, 0, 0)

MathML and HTML

We can also get the .MathML of a given matrix. MathML is a standard representation of math and a web standard.

Even better than that, we can also get an HTML preview of a matrix.

We just take the MathML and render it twice: Once without any transformation, once with the transformation.

Run this script to see what I mean

(SkewX 10deg).html > .\skewX-10deg.html

In PowerShell, we can always use Add-Member to extend an object.

If a Matrix has a .Content property, it will render that content using it's transform.

This means we can easily do fun stuff, like backwards text:

Scale -1 1 | 
    Add-Member NoteProperty Content "<h3>Backwards</h3>" -Force -PassThru |
        Select-Object -ExpandProperty Html > .\backwards.html

Enter the Matrix

This is all a bit 🤯.

Matrix allows us to do many things, just by exposing a couple of classes in PowerShell. It allows us to manipulate points in a uniform way, and this way is used everywhere. Transform matrices are a fundamental part of 2D and 3D graphics. They can be used to model movement in multiple dimensions and are a big part of how the modern graphics work.

Now we can make matrices easily in PowerShell and convert them into multiple useful representations.

There is no spoon.

😎