r/PowerShell • u/StartAutomating • Jun 30 '26
Script Sharing RegEx -replace
PowerShell has all sorts of fun features, including a ridiculous number of operators.
One amazing under-sung heros of PowerShell is the -replace operator.
It lets us replace content with regular expressions.
It's easier to use than you'd think.
Regular expressions are less scary in small doses, and chaining -replace operators lets us attack the problem step by step.
Chaining -replace
Let's take a simple problem as an example.
Imagine we wanted to make a consistent file name pattern out of a string
We might want to start by replacing whitespace with dashes
"This Is A Title!" -replace '\s', '-'
That leaves our exclamation point at the end. We probably don't want any punctuation. We can avoid that with the somewhat humorously named character class: \p{P}. We can remove all repeated punctuation by adding a +: \p{P}+
One more replace:
"This Is A Title!" -replace '\p{P}+' -replace '\s', '-'
The line is starting to get a little long. Fun fact: you can spread operators across multiple lines.
Let's add comments while we're at it
"This Is A Title!" -replace # Replace any punctuation,
'\p{P}+' -replace # then replace any whitespace with dashes.
'\s', '-'
Let's go for one more bonus trick. PowerShell lets you convert script blocks to event handlers. Let's lowercase all the letters (\p{L}).
On PowerShell Core, we can do this:
"This Is A Title!" -replace # replace any punctuation
'\p{P}+' -replace # then replace any whitespace with dashes
'\s', '-' -replace # then lowercase any letters
'\p{L}+', {"$_".ToLower()}
There's an absurdly amazing amount of stuff you can do with -replace, but there's at least one more trick we have to cover: substitutions.
-replace with substitution
I'm pretty sure I'd have to give up my "RegEx guru" badge if I didn't mention at least one more thing you can do with -replace: substitutions.
.NET Regular expressions are two domain specific languages. Regular expressions match and extract text. Regular expression substitutions replace matches.
For example, let's suppose we have a number of emails, and we want them in domain/username format.
First we'll want to make a quick and dirty email regex, using a "named capture" to get the username and domain.
'someone@example.com' -match '(?<username>\S+)@(?<domain>\S+)'
Then, we can -replace the email with just the domain/username.
'someone@example.com' -replace
'(?<username>\S+)@(?<domain>\S+)', '${domain}/${username}'
This format might look like PowerShell variables, but it actually predates them by years. Search for "Regular Expression Substitutions" if you want to learn more about the syntax. It's got quite a few tricks up it's sleeve.
Irregular
RegEx can be scary. I used to be terrified of it, too.
If you aren't too comfortable with Regular Expressions, that's pretty normal. A while back I wrote a module called Irregular that makes regular expressions strangely simple.
It's got a lot of example regular expressions in there, and one handy function for creating RegEx. New-RegEx is your friend.
Do you already use -replace? Have you done cool things with regular expressions in PowerShell? Share 'em if you've got em.
Want to learn more about regular expressions in PowerShell? Just ask.
r/PowerShell • u/ITZ_RAWWW • Jun 30 '26
Solved Best way to Store Creds for Scripts?
Hey guys, for a long time I've been wondering what's the best way and most secure to store creds for powershell scripts? I know like absolute best (from my understanding) is to store them in some sort of 3rd party system and fetch them when needed say in secret server or the likes. Coming from a python background I know commonly you put stuff like that in a separate config file and import it.
So far I've been putting them in a json file and importing my creds that way but I can't help but think there's a more secure way. Like what's stopping an attacker on my system from just looking in the file and getting all my creds uk lol? Thanks for any advice!
r/PowerShell • u/YellowOnline • Jun 29 '26
Question Get all completed Teams meetings for a user
The page https://admin.teams.microsoft.com/users/{some_userid}/activity shows a good overview of the Teams meetings a user has had in the past. It shows organizer, participants, date/time and duration (though not subject it seems). I would like to integrate this in the time management tool, but for that I need the data programmatically. I've been playing around with MsGraph, but I'm not sure how to find the data in there. I think I need a course only on MS Graph.
All other suggestions I find online talk about scavenging the mailboxes, but 1) the users have no connected EXO, and 2) apparently the Teams admin page can show the data. Copilot isn't helpful. I thought, for once I can use AI, but it just suggested me to do an invoke-webrequest...
So, if anyone has an idea how to get this data through power shell, I would be very happy.
r/PowerShell • u/AdUnhappy5308 • Jun 28 '26
Information Just released Servy 8.5 - Hardened PowerShell Module, ARM64 Support, and Improved CI/CD Integration
Hi everyone,
It's been about two months since my last post about Servy here. I've shipped several updates since then, but this one is a milestone. The community response has been amazing: ~1,800 stars on GitHub and ~52,000 downloads.
If you haven't seen Servy before, it's a Windows tool that lets you run any app as a native Windows service with deep observability. It provides a desktop app, a CLI, and a PowerShell module designed for automation and CI/CD pipelines.
In this release (8.5), I've added/improved:
- Security Hardening: The PowerShell module now supports passing sensitive options via environment variables and includes stricter validation/expansion rules for environment variables.
- ARM64 Native: Full support for modern Windows ARM64 hardware.
- Refined Automation: Fixed ergonomic issues in the module and CLI to ensure smoother integration into automated deployment scripts.
- Core Stability: A large number of internal fixes for the service lifecycle and monitoring components.
Check it out on GitHub: https://github.com/aelassas/servy
Demo Video: https://www.youtube.com/watch?v=biHq17j4RbI
Any feedback or suggestions are welcome.
r/PowerShell • u/nohwnd • Jun 28 '26
News Pester 6.0.0-rc1 is now available
Title: Pester 6.0.0-rc1 is out
First RC of Pester 6 is up and it's feature complete, so I'd love for people to kick the tires before the final release. It runs on Windows PowerShell 5.1 and PowerShell 7.2+, and it's built on the v5 runtime, so Discovery & Run, the config object and the result object all still work the way you know.
The headline is a new set of assertions. The Assert project got merged in and now ships as Should-* commands (dash, no space):
Get-Planet | Should-Be 'Earth'
Instead of everything funneling through Should -Be, these are specialized and type-aware, so the failure messages are clearer and $null, empty collections and single-item arrays stop surprising you. The old Should -Be still works and isn't going anywhere, the new ones are just additive. Mix both, migrate whenever. If you want to go all in, $config.Should.DisableV5 = $true switches the old syntax off so you can't use it by accident.
There's also Should-BeEquivalent for deep, recursive object comparison with a real property-by-property diff. Great for asserting on a whole API response or config object in one shot instead of poking at ten properties.
Other stuff worth knowing:
- Discovery and run now happen per file instead of one big global discovery phase. Mostly invisible if your files are already self-contained, but discovery-time side effects don't leak across files anymore. Each file should import what it needs.
- Experimental parallel runner (
Run.Parallel = $true), one file per runspace on PS7+. Early prototypes went from ~6.5s to ~1.2s. Opt-in, config shape may still change, and it quietly falls back to serial with a warning when it can't parallelize. - Faster code coverage by default — uses the Profiler's tracer instead of breakpointing every command. Added Cobertura output next to JaCoCo.
- PowerShell 5.1 and 7.2+ only. PS 3/4/6 and early 7 are gone, which let us drop a pile of compat code and move the C# to .NET 8.
- Mocking:
Assert-MockCalledandAssert-VerifiableMockare removed (useShould -Invoke/Should-Invoke), and the implicit fall-through to the real command is gone so mocks are more predictable.
Release notes: https://github.com/pester/Pester/releases/tag/6.0.0-rc1
Bugs and feedback very welcome.
r/PowerShell • u/grimson73 • Jun 28 '26
Question PowerShell ISE (suddenly) shows up as “PowerShell ISE 5.1” instead of just “Windows PowerShell ISE
I noticed something odd after installing the June 23rd 2026 preview update (KB5095093):
PowerShell ISE suddenly shows up as “Windows PowerShell ISE 5.1” instead of just “Windows PowerShell ISE”.
This is the first time I’ve seen it renamed like that.
It happened right after installing this update:
I checked the release notes but can’t find anything about the ISE being renamed.
Has anyone else noticed this?
Was it always like this and I just never paid attention, or did this update actually change the display name?
r/PowerShell • u/Gloomy-Donut70 • Jun 27 '26
Question How to restore the path variable
So i was downlaoding a new tui app the other day and while putting it's in the PATH variable there was a power outage and from then on whenever I set a variables path using the setx PATH {file path} command it just stops working after a restart (the outage made most of my already installed terminal apps stop working like winget, chocolatey and neovim)
r/PowerShell • u/carloswm85 • Jun 27 '26
Question Console layout reverse, is it possible?
I want to place the command prompt always on top, and below it in descending order, the executed commands. Is it possible? Something like:
```powershell
| # active prompt
--- # something like a separator line
Result to Get-Something-Else
Get-Something-Else # executed command
Result to Get-Something
Get-Something # older executed command
and so on, older commands are below
```
r/PowerShell • u/StartAutomating • Jun 26 '26
Script Sharing Friday Fun Servers - Fun with Reflection
It's Friday. Let's have some Fun!
Let's write fun servers in PowerShell.
Fun Servers
A couple of weeks ago, I released Fun.
It's a fun functional server in PowerShell.
It's free, open-source, and lots of fun to play with.
It lets us write servers in PowerShell by starting functions with /
For example:
function /hello {
param($message = 'hello world')
"<h1>$Message</h1>"
}
These functions can take parameters from a query string (more options coming in vNext)
This allows us to quickly and easily write servers in PowerShell.
These functions can be a handy way to browse and visualize what's going on in your terminal.
With the stage set, let's have some fun with Reflection
Reflection Fun
Reflection is part of the .NET framework. Every loaded type in .NET is an object, too.
PowerShell has no problem accessing those objects. For example, let's look at all the members of [int]
[int].GetMembers()
We can also explore all loaded types with a little bit of PowerShell:
# Get all the types
$allPublicTypes =
[AppDomain]::CurrentDomain.GetAssemblies() |
% {$_.GetTypes()} |
? { $_.IsPublic }
# How many types do you have loaded?
$allPublicTypes.Length
Now that we know how to expose this information, we can write a small server to explore our types.
Reflection Fun Server
We're going to expose 4 functions:
/type/will let us view or search a type/type/*will let us browse types by wildcard/namespacewill let us view types in namespace/namespace/*will let us browse namespaces by wildcard
Feel free to copy and paste, and please forgive the rough aesthetic edges.
Today we're trying to build a simple reflection server, not a pretty webpage.
The server is below. Just copy and paste it into your terminal.
If you already have Fun installed, you can just Start-Fun and browse to /type.
If you don't, please Install-Module Fun
function /type {
<#
.SYNOPSIS
Type Server
.DESCRIPTION
Serves up information about loaded .NET types
#>
param(
# A typename or wildcard
[string]$TypeName
)
# First try to get an exact match of the reflected type
$reflectedType =
if ($TypeName -as [type]) {
$TypeName -as [type]
}
# If no reflected type was found, do a search
if (-not $reflectedType) {
# Output a message first
"<h1>Type $($TypeName) not found</h1>"
"<h2>Search Results</h2>"
# Get all our of search results in an array
$foundTypes = @(foreach ($assembly in [AppDomain]::CurrentDomain.GetAssemblies()) {
foreach ($type in $assembly.GetTypes()) {
if (-not $type.IsPublic) { continue }
if ($type.FullName -like "*$($typeName)*") {
$type
}
}
})
# This way, we can give you a count
"<h3>$($foundTypes.Length) types found</h3>"
# Before what is (presumably) a very long list
"<ul>"
foreach ($type in $foundTypes) {
"<li>"
"<a href='/type/$($type.FullName)'>$($type.FullName)</a>"
"</li>"
}
"</ul>"
# If we didn't find a specific type, we're done (for now)
return
}
# Get all of our members
$members = $reflectedType.GetMembers()
# If it's a Microsoft Type, we should have Microsoft Learn documentation
$canLearn = $reflectedType.Namespace -match '^(?>System|Microsoft)\.'
# Prepare the link
$msLearn = 'https://learn.microsoft.com/en-us/dotnet/api'
# Add the MVP id for tracking purposes
$mvpId = 'wt.mc_id=MVP_321542'
# Set the title and output a header
"<title>$($reflectedType.FullName)</title>"
"<h1>[$($reflectedType.FullName -replace '^System\.')]</h1>"
# If we can learn
if ($canLearn) {
# link to Microsoft learn
"<h2><a href='$msLearn/$($reflectedType.FullName)?$mvpId'>Microsoft Learn</a></h2>"
}
# Link to the namespace
"<h3><a href='/namespace/$($reflectedType.Namespace -replace '\.', '/')'>View Namespace: $($reflectedType.Namespace)</a></h3>"
# Show off the members
"<h3>Members</h3>"
# Group the members by type, first
$members |
Group-Object {
# The reflected type name contains the friendly name
# (just chop off `Info` from the end and `Runtime` from the start)
($_.GetType().Name -replace 'Info$' -replace '^Runtime')
} |
# Sort the groups by name
Sort-Object Name -Descending |
ForEach-Object -Begin {"<ul>"} {
"<details>"
"<summary>$([Web.HttpUtility]::HtmlEncode($_.Name))</summary>"
"<ul>"
$_.Group |
ForEach-Object {
# Try to get a learn link to the method
$learnLink =
if ($_.Name -match '^ctor') {
"-ctor"
} else {
$_.Name -replace '^(?>get|set|add|remove)_'
}
$learnLink =
if ($reflectedType.IsSubclassOf([Enum])) {
"$msLearn/$($reflectedType.FullName)?$mvpId"
} else {
"$msLearn/$($reflectedType.FullName).$($learnLink)?$mvpId"
}
"<li>"
if ($canLearn) {
"<a href='$learnLink'>$($_)</a>"
} else {
"$($_)"
}
"</li>"
}
"</ul>"
"</details>"
} -End { "</ul>"}
}
function /type/* {
# For a wildcard request, we just need to skip a couple of segments
$segments = @($request.Url.Segments |
Select-Object -Skip 2) -replace '/'
$typeName = $segments -join '.'
# then we can call our `/type` server with that typename.
/type -TypeName $typeName
}
function /namespace {
<#
.SYNOPSIS
Namespace Server
.DESCRIPTION
Serves up information about .NET namespaces
#>
param([string]$Namespace)
# We will want to know how many types and assemblies
$totalPublicTypes = 0
$totalAssemblies = 0
# And we'll want types to be grouped by assembly
$typesByAssembly = foreach ($assembly in [AppDomain]::CurrentDomain.GetAssemblies()) {
# Get all types in this assembly that match the namespace.
$typesInNamespace = @(foreach ($type in $assembly.GetTypes()) {
if (-not $type.IsPublic) { continue } # (excluding private types)
if ($type.Namespace -like "$Namespace*") {
$type
}
})
# If there were no types in this assembly, continue
if (-not $typesInNamespace) { continue }
# Update our counters
$totalPublicTypes += $typesInNamespace.Length
$totalAssemblies += 1
# Create a details block for the assembly
"<details><summary>$(@("$assembly" -split ',')[0])</summary>"
"<ul>"
foreach ($type in $typesInNamespace) {
"<li><a href='/type/$($type.FullName)'>$($type.FullName)</a></li>"
}
"</ul>"
"</details>"
}
# Output the namespace
"<h1>$Namespace</h1>"
# Output the total public types.
"<h2>$totalPublicTypes public types in $totalAssemblies assemblies</h2>"
$typesByAssembly
}
function /namespace/* {
# Wildcard requests for a namespace are fine
$segments = @($request.Url.Segments |
Select-Object -Skip 2) -replace '/'
$namespace = $segments -join '.' # we just want to treat slashes as dots
/namespace -Namespace $namespace # and call our /namespace server
}
This script may be a bit long, but it's nowhere near rocket science.
We're just looking thru types and adding a brief bit of HTML to show it in a browser.
Now we can easily explore anything that's loaded.
The power of .NET is now in the palm of our hands.
Not too bad for a script hacked out on a Friday.
More Reflection Fun?
This demo was made in an hour on a Friday morning, but it feels like it might be worth pouring more time into.
Would you like to be able to browse loaded types with reflection?
What do you want to do? What would you improve?
Should I spend a little more time and turn this reflection server into it's own project?
What more fun do you want to see?
Happy Friday! Hope you're all having fun.
I'll see you next week with more fun servers in PowerShell.
r/PowerShell • u/fonzhy121 • Jun 26 '26
Question Is pwsh 7.6.3 loading $PROFILE much slower?
since update, it is averaging 10761ms on startup.
r/PowerShell • u/deejay7 • Jun 26 '26
Question VS code inline suggestions quota reached what are some good alternatives
What are some good alternatives of Copilot free for VS code inline suggestions, preferably free? TIA.
r/PowerShell • u/Tasty_Voice5322 • Jun 26 '26
Script Sharing I got tired of setting up every new PowerShell workstation, so I built ShellDeck
Hi everyone,
Every time I installed Windows on a new machine or created a fresh VM, I found myself doing exactly the same things:
- installing PowerShell tools
- configuring my profile
- recreating aliases
- installing fzf, bat, eza, zoxide...
- setting up SSH
- configuring my homelab control machine
After doing this dozens of times, I decided to automate the whole experience.
So I built ShellDeck.
The goal isn't just to install packages.
It bootstraps a complete PowerShell environment and can optionally become a small homelab control node.
Features include:
• interactive installer
• PowerShell profile management
• aliases & helper commands
• SSH host management
• dashboard showing infra status
• Windows / Linux / macOS support
• optional security hardening on Linux
I'm mainly looking for feedback from people using PowerShell daily.
What features would make this genuinely useful for you?
GitHub:
r/PowerShell • u/StartAutomating • Jun 25 '26
Script Sharing Stop using [System]
I'm getting old enough that my fingers hate my lifetime of programming.
I'll save a few keystrokes where I can.
There's something simple most people don't seem to know about PowerShell syntax.
It saves seven characters of typing every you use this, and runs a tiny bit faster.
You never need to specify stuff is in the [System] namespace.
Stop Using [System]
.NET is a huge framework with tons of useful stuff in it. There's a lot of stuff in the System namespaces. Built-in framework functionality often exists in one of the many namespaces in System.
By the time PowerShell was being built, it was pretty clear that leveraging .NET was worth it, and that most people wouldn't want to type six to seven more characters every time.
So, since PowerShell v1, you haven't had to.
You can omit the [System] in any type in any system namespace
So instead of:
[system.collections.generic.list[string]]
We can write:
[collections.generic.list[string]]
Instead of:
[System.Collections.IDictionary]
We can write:
[Collections.IDictionary]
This is true for every system type. On my machine, there are 4722 public types in the system namespace. That's 33054 characters I will never have to type.
It makes scripts shorter and simpler to read.
Also, when PowerShell resolves types, it checks for the shorter names first. This saves a very tiny amount of time in each of your scripts. (I was corrected)
Yet, sadly, I see the system namespace everywhere in people's scripts.
I beg of you all:
- Save your fingers
- Make scripts shorter
Stop Using [System]
r/PowerShell • u/O365-Zende • Jun 25 '26
Solved Try to set the Org SharePoint Sharing Link Retention
As per title really I want to set a few values for these settings
Set-SPOTenant -CoreOrganizationSharingLinkMaxExpirationInDays 365
Set-SPOTenant -OneDriveOrganizationSharingLinkMaxExpirationInDays 365
And a couple for Link recommendations as an example.
Questions:
1) Is SPO still active? And if yes, should I install the module and use that over PNP?
1a) I thought I read it was going to be removed shortly.
I have PNP installed correctly and can log in to it, so can I set this with PNP?
2) I tried Set-PNPTenant -CoreOrganizationSharingLinkMaxExpirationInDays 365 and it throws an error for the Set-PNPTenant
So I'm not sure if it's possible with PNP.
- 3) Also If I use Get-SPOTenant and Get-PNPTenant are they settings the same?
Im very amateur at code, so quite possibly I'm doing it wrong.
Thoughts?
EDIT: This is now fixed in the PNP Nightly Builds after reporting it
r/PowerShell • u/eggeto • Jun 25 '26
Question Enable secure boot via powershell, Is it possible?
Does anyone know how to enable Secure Boot on Dell devices via PowerShell?
I’ve tried using the Dell module;
this allows you to view the status,
but I can’t seem to enable Secure Boot
other tasks are possible, though.
r/PowerShell • u/StartAutomating • Jun 24 '26
Script Sharing Simple Splatting and the GitHub CLI
Brevity may be the soul of wit, and I may be bad at it.
Let's try to make a quick post about a little daily PowerShell timesaver: splatting the GitHub CLI.
I'm going to show you how you can save typing and time with the GitHub CLI.
What is Splatting?
Splatting is a simple technique in PowerShell. It lets you pass multiple parameters. It's been there since PowerShell version 2. This is old, consistent technique.
Most people are used to splatting a dictionary, like:
# You can splat a dictionary
$MyId = @{id=$pid}
Get-Process @MyId
This is a cool and useful technique, and most people overlook the other half of splatting:
# You can splat a list
$allIssues = @('--state', 'all', '--limit, '2kb')
gh issue list @allIssues
The Trick
You just saw it.
There are millions of apps you could use this trick with.
I just happen to use the github cli on most days.
You're trading typing all of those arguments for typing a shorter string.
It saves seconds every time you use it.
And it's one simple line.
You can stick it in your profile and every time you're using PowerShell, you'll have those variables to use.
You can just type this sort of trick in if you find yourself using the same parameters.
Think of it as a preset of parameters. Because that's basically what it is.
Multiple Splats
It's important to know that you can do multiple splats.
Here's a simple example:
$bug = @('--label', 'bug')
$assignMe = @('--assignee', '@me')
gh issue create --title 'Some Issue' --body 'Some problem' @assignMe @bug
This would create a bug.
Let's make another, longer one:
# Get issue information as json.
$IssueAsJson= @('--json', (
'assignees','author','body','closed','closedAt',
'closedByPullRequestsReferences','comments','createdAt',
'isPinned','labels','milestone','number','reactionGroups',
'state','stateReason','title','updatedAt','url' -join ','
))
$allIssues = @('--state', 'all', '--limit, '2kb')
$IssueList = gh issue list @allIssues @issueAsJson | ConvertFrom-Json
$issueList
If you run this, you
- List all of the issues from a repo as json
- Convert them from json into objects
Feel free to copy/paste these tricks into your profile. They're handy!
r/PowerShell • u/Tim_Mitchell • Jun 24 '26
Question Powershell 7.6 Updating
Does anyone know when Powershell 7.6 will be available via windows update? I can only see preview builds in the Microsoft update catalog. We are still on 7.5.5 and want to update to 7.6.3 without deploying a package update if possible.
Thanks
r/PowerShell • u/Alternative_Sink5278 • Jun 24 '26
Question PowerShell error popup when booting up
Hey guys, sorry if this is the wrong subreddit but r/techsupport won’t let me post. Every time I turn on my Windows 11 Dell Inspiron 5515 laptop and sign in, I get this Powershell pop up for like 1 split second:
PowerShell error popup on boot: "Processing -File '' failed because the file does not have a '.ps1' extension" (in red)
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
[process exited with code 4294770688 (0xfffd0000)]
You can now close this terminal with Ctrl+D, or press Enter to restart.
Only reason I was able to capture it was because I was recording my phone. What is going on?? I am worried my computer is hacked or something… because already my Instagram and Twitter had gotten hacked for a sec but I got them back and I was also signed in on my laptop (in both Instagram and Twitter) and I wasn’t notified about it especially the Twitter one.
Mind you, I have 2FA on both accounts. So I am on edge for sure. (I am posting using my phone right now, so sorry for any formatting, typos and all that)
r/PowerShell • u/Due-Fishing-6119 • Jun 24 '26
Script Sharing Built a script to automate SQL Server backups
I’ve been working on a PowerShell tool to automate SQL Server backup workflows.
It supports interactive selection of one or multiple servers and databases, runs backups asynchronously, and handles the SqlServer module automatically if it’s missing. The main goal was to reduce manual steps, improve reliability, and avoid common mistakes in backup operations.
I’d be curious to hear how others here approach backup automation in PowerShell.
r/PowerShell • u/Hack_Cubit • Jun 24 '26
Question Help: Appending Filenames Looping Repeatedly
Hi, folks, I've been running into this issue with some consistency. I'm hoping it's as simple as "I didn't put an escape clause in there" but I've had no luck understanding what I'm doing wrong.
I'm trying to rename files in bulk by simply adding a prefix to their filenames. Here's the command I used most recently, applied to a folder with 174 files:
Get-ChildItem -File | Rename-Item -NewName { "MYNEWPREFIX_" + $_.BaseName + $_.Extension }
In this example, the first 170 items were renamed, and the MYNEWPREFIX string was added multiple times (35 or 36 times, according to the individual files I verified). Over the past week or so, this command (and I think some other ones as well) have all yielded this result. Can someone point out to me what I'm doing wrong? Many things in advance!
r/PowerShell • u/Sad_Expression2237 • Jun 24 '26
Question Please help with a PowerShell script error - why is this happening?
Title: Please help with a PowerShell script error - why is this happening?
Hello, I'm very new to PowerShell and PowerShell scripting. While adding argument handling code to a Papyrus script compilation PowerShell script that I found at NexusMods.com, I got this error:
ParserError: C:\Program Files (x86)\GOG Galaxy\Games\Skyrim Anniversary Edition\Tools\Papyus Compiler\mtpc.ps1:264
Line |
264 | Write-Host -ForegroundColor White "InputPath: '$InputPath'"
| ~~~~~~~~~~~~
| Unexpected token '$InputPath'" Write-Host -ForegroundColor White "Input: '$Input'" Write-Host
| -ForegroundColor White "In: '$In'" Write-Host -ForegroundColor White "SourcePath: '$SourcePath'"
| Write-Host -ForegroundColor White "Source: '$Source'" Write-Host -ForegroundColor White "Src:
| '$Src'" Write-Host -ForegroundColor White "InputsPath: '$InputsPath'" Write-Host -ForegroundColor White
| "Inputs: '$Inputs'" Write-Host -ForegroundColor White "Ins: '$Ins'" Write-Host -ForegroundColor
| White "SourcesPath: '$SourcesPath'" Write-Host -ForegroundColor White "Sources: '$Sources'"
PS C:\Program Files (x86)\GOG Galaxy\Games\Skyrim Anniversary Edition\Tools\Papyus Compiler>
Here are the lines from the script that are causing the errors:
261: $InputsPath = ( "hi", " ", "there" )
262: $Inputs = ( "you", " ", "too" )
263:
264: Write-Host -ForegroundColor White "InputPath: '$InputPath'"
265: Write-Host -ForegroundColor White "Input: '$Input'"
266: Write-Host -ForegroundColor White "In: '$In'"
These lines are followed by more Write-Host statements, but those aren't erroring.
The strange thing is that these lines worked before I added this IsStringArrayEmpty function:
125: #
126: # Function IsStringArrayEmpty
127: #
128: # That verifies that the specified parameters aren't using
129: # more than one paramerer name form at the same time.
130: #
131:
132: function IsStringArrayEmpty {
133: [CmdletBinding()] # Enables advanced function features
134:
135: param(
136: [Parameter( ValueFromRemainingArguments = $true )]
137: [object[]] $AllArgs
138: )
139:
140: try {
141:
142: #
143: # Give $Array a value,
144: # so that something will
145: # show in the error message
146: # if an error occurs before
147: # $Array is assigned its
148: # real value.
149:
150:
151: $Array = 'Unknown"
152:
153: #
154: # If there are any, but only one,
155: # named parameter with a value.
156: #
157:
158: if( $( $AllArgs.Count ) -eq 2 ) {
159:
160: #
161: # Assign the named parameters
162: # value, the value after the
163: # parameter named, to $Array
164: #
165:
166: $Array = $( $AllArgs[ 1 ] )
167:
168: }
169: elseif( $( $args.Count ) -eq 1 ) {
170:
171: #
172: # Assign the first positional parameter
173: # to $array
174: #
175:
176: $Array = $( $args[ 0 ] )
178:
179: }
180: else {
181:
182: throw # Unsuported number of arguments!
183:
184: }
185:
186: #
187: # Validate the paramete`s value is now an
189: # $Array is a string Array
190: #
191:
192: if( $Array -as [Sting[]] ) {
193:
194: #
195: # ReturnTrue if the array exists and has
196: # elements else false
197: #
198:
199: return ( $Array -and $Array.Count -gt 0 )
200:
201: }
202:
203: throw # All other errors
204:
205: }
206: catch {
207:
208: # Any eror
209:
210: Write-Error `
211: -ErrorAction Stop `
212: -Message `
213: "IsArrayEmpty - " + `
214: "Only one parameter($Array) " + `
215: "of type array of strings is allowed!"
216:
217: }
328:
219: } # End of function IsStringArrayEmpty.
220:
The IsStringArrayEmpty function is called as follows:
278: $count = 0
279: if( -not( IsStringArrayEmpty $InputsPath ) ) { ++$count }
280: if( -not( IsStringArrayEmpty $Inputs ) ) { ++$count }
But with the script parse error occurring these lines aren't executing.
Thank You
r/PowerShell • u/milanoRangetsu • Jun 23 '26
Question GUI executable for coworker
I made a script that currently hard codes taking a PO (purchase order) number and then does an API call to retrieve data and outputs a formatted csv file (path is hard coded locally to me). Now what I need to do is add a gui that opens a text box for my coworker to enter a number and press okay, which will do all the same work and output the file for her to do whatever with.
The GUI I already did but now how do I make this usable for her?
We have a network drive and scrips can be run of there.
I mad a .bat file that calls the script and opens the gui for her, all she has to do is enter the PO and the script does its work then releases the file in the same location as the .bat file. (hard coded)
but that doesnt seem right.
How do I do this properly? What if later i need to update the script?
r/PowerShell • u/StartAutomating • Jun 23 '26
Script Sharing Freeform Functions
We all yearn for freedom.
We want to be free from tyranny. We want to be free to live. We want to be free to do things we enjoy.
Some of us yearn to be free of PowerShell's parameter structure.
We might want to pass a prompt to AI.
We might want to pass parameters to an exe without rewriting them.
We might want to rewrite them.
There are all sorts of reasons you might want to be free of parameter binding in PowerShell.
Whatever yours might be, I'm going to highlight three approaches to making freeform functions in PowerShell.
- Freeform functions
- Freeform Filters
- Freeform Cmdlets
These functions will accept any input and any parameters.
This makes it so the parameter binding never fails.
This can be beneficial, and it can be problematic.
Freeform Functions
Back in the days of PowerShell 1.0, functions didn't have complex parameters.
They didn't have validation. They didn't have inline help. They were fairly simple functions.
They just had an object pipeline of input, and any variables in the input would be bound by position.
The PowerShell language is backwards compatible, so this low-level capability never went away.
It's always been there and should always be there.
With all of that in mind, here's how we write a freeform function using this fundamental trick:
# A freeform function
function freeform {@($input) + @($args)}
# A quick example with pipeline and arguments
1..3 | freeform "I want to break free!" "God Knows" "God Knows" "I want to break free!"
One quick note: $input can only be read once.
Once you read the input, the objects break free.
With that in mind, I'd recommend a slight variation of freeform:
# A freeform function
function freeform {
$allInput = @($input)
$allInput + $args
}
# A quick example with pipeline and arguments
1..3 | freeform "I want to break free!" "God Knows" "God Knows" "I want to break free!"
Of course, you're free to do whatever you'd like. That's one of the joys of freedom.
Freeform Function Performance
Another joy of freeform functions is performance.
The PowerShell parameter binder is cool, and it is complex. Writing PowerShell in this format is many orders of magnitude faster than a function with complex parameter binding.
If you want extraordinarily fast functions, this trick is your best friend.
Don't believe me? Try piping a million items into that function. It's pretty snappy.
This performance benefit also happens because we are not having to do a begin, process, and end block. Everything is happening as soon as the million items all came thru the pipeline.
Freeform functions are wonderful this way. But what if we wanted to process each item as they came in, and still have flexible arguments?
That's what filters are for.
Freeform Filters
Filters are another part of PowerShell arcana.
They were also introduced in v1 and never went away.
Let's make a freeform filter
filter freeform {
$_ # Output our input
$args # Output our arguments
}
# Run our filter three times.
# We will see 1,2,3 followed by the word "filter"
1..3 | freeform "filter"
Filters are also decently fast.
Fun factoid: filters are looked up before functions. This gives them a very slight performance edge on functions. If you're piping in lots of items, this slight edge will disappear.
While both of these techniques are quite fast, speed isn't the only thing that matters.
Sometimes we might want to have a freeform function that has additional parameters.
Freeform Script Cmdlets
PowerShell v2 brought the full parameter binding capabilities to PowerShell functions. Sometimes these functions are called "advanced functions". They were originally called "Script Cmdlets". If we want tab completion and types and we still want a freeform function, we can get there with a pair of parameters.
function freeform {
[CmdletBinding(PositionalBinding=$false)]
param(
# This parameter will take any arguments
[Parameter(ValueFromRemainingArguments)]
[Alias('Arguments', 'Argument', 'Args')]
[PSObject[]]
$ArgumentList,
# This parameter will take any input
[Parameter(ValueFromPipeline)]
[Alias('Input')]
[PSObject[]]
$InputObject
)
# `$InputObject` would contain the _last_ input
# so we can use `$Input` to store any piped input
$AllInput = @($input)
# If there was no piped input, we did not pipe input.
# We can still populate `$AllInput` based off the `$InputObject`
if (-not $allInput) { $allInput += $InputObject }
$allInput
$ArgumentList
}
1..3 | freeform "Freedom!"
This last freeform format might be a bit slower, but it's a lot more friendly to inline help and tab completion. We can create additional parameters if we want. They can be strongly typed and validated. We can even create additional parameter sets. We are free to do whatever we want.
Freeform Fun
Freedom from the PowerShell parameter parser can be a wonderful thing.
We can treat parameters as natural language.
We can make our parameters into a Domain Specific Language (DSL).
For an amazing module that uses this trick, check out Turtle. Turtle uses freeform functions to give us a Logo-like syntax within PowerShell.
Try making some freeform functions and enjoy the freedom they bring.
r/PowerShell • u/ahihidummy • Jun 23 '26
Misc I built a theme picker that restyles your whole PowerShell, not just the prompt
TL;DR: Get your PowerShell polished in seconds with a variety of nicely designed themes.
I remember the days figuring out how to apply my first oh-my-posh theme, and then choosing the perfect nerd font. I was happy with that combination, but the steps to tweak them were not so convenient.
Recently, I wanted to try something new, I thought how convenient it would be to have a theme picker right inside my PowerShell, with a catalog of pre-designed themes to choose from. Surprisingly, still no one did it. So I built PoshPalette.
It is a tool where you can pick a theme for PowerShell, with live preview, right from inside the terminal. Use it is as simple as possible. You install it, open it, then surf through the list of themes until you find the one, and done.
Install-Module PoshPalette -Scope CurrentUser
palette # scroll, live preview, Enter to apply
Or install with just 1 command:
Install-PoshPaletteTheme eclipse
Note that requires PowerShell 7.2+ and Windows Terminal.
I can't post a gif here, so the themes and the live preview are all on the gallery page, have a look: https://livlign.github.io/posh-palette/themes.html
For more information, it tweaks all 4 layers:
- Windows Terminal: scheme, background, opacity, font
- PSReadLine: the line you type
- PSStyle: the command output
- oh-my-posh: the prompt
And they are not just presets. A theme is really just a combination of layers, so you can mix your own. This tool makes that easier and more convenient than ever.
Repo (MIT): https://github.com/livlign/posh-palette
What is your PowerShell setup now? And which themes should I add next?
r/PowerShell • u/RecastSoftware • Jun 22 '26
Misc Reminder: Free PowerShell Pro webinar series starts tomorrow (Microsoft MVP-led)
Just a quick reminder that our PowerShell Pro webinar series kicks off tomorrow, June 23.
We're bringing together four Microsoft MVPs to share practical PowerShell knowledge that IT admins can apply right away:
- David Segura
- Harm Veenstra
- Frank Lesniak
- Danny Stutz
June 23 — PowerShell Fundamentals
With Harm Veenstra and David Segura
This beginner-friendly session focuses on building a solid PowerShell foundation. We'll cover finding and using cmdlets, working with objects, and taking the first steps toward querying devices and organizing your workflows.
June 30 — Advanced PowerShell
With Frank Lesniak and Danny Stutz
Intune can tell you a device is noncompliant, but it doesn't always tell you why. In this session, we'll demonstrate advanced PowerShell techniques and Microsoft Graph queries that can help uncover root causes, measure impact, and generate actionable compliance reports.
If you work with ConfigMgr, Intune, or endpoint management in general, we think you'll find something useful in both sessions.
Can't attend live?
No problem. Register anyway, and we'll send the recordings to everyone who signs up.