r/PowerShell

Test-NetConnection Issue - Can Ping, Can Test, but TNC is failing

Here's my head scratcher:

I can run Test-NetConnection $server -Port $Port and it just hangs. If I run Test-Connection $server it pings fine. If I do Test-NetConnection $server -Port $Port -InformationLevel Quiet it also tests fine.

I know that this isn't a PS issue, but I don't know who or where to start pointing at to figure it out. Issue happens both in the same subnet and across the WAN

reddit.com
u/Unapolagetic_Lifer — 16 hours ago
▲ 2 r/PowerShell+1 crossposts

Folder Windows Extension

I wanted to make a windows extension but i am gettin many errors and i am scared to destroy my system.. so i wanted to ask if maybe what i was up to maybe already exists.

I was trying to create a extension where inside a folder you can do rightclick->new and then instead of text file a "text field" where it would create a text box such as the one i am using right now here inside a folder to write info about the folder. Example: i am in a folder where i put in my job applications and i wanted the info box so i can write in it "application send on 06.07.26 via email to mr. abc" and then when opening the folder id see that instantly and if they replay i can open the folder and add into the text "replayed on 08.09.26 rejected".

Is there already something like that?

reddit.com
u/Thick_Butterfly_4137 — 15 hours ago

Stop forced upgrades?

I'm just trying to open Powershell and run a command but every now and then there must be an upgrade and it forces me to upgrade and I can't do anything until I do the upgrade. Is there a way around this?

reddit.com
u/evh1972 — 1 day ago
▲ 54 r/PowerShell+1 crossposts

What's one free tool that completely change your workflow ?

​

I've been trying to improve my productivity and streamline the way I work, but there are so many free tools out there that it's hard to know what's actually worth using.

What's one free tool that had the biggest impact on your workflow?

It could be for:

\- Productivity

\- Coding

\- AI

\- Note-taking

\- File management

\- Automation

\- Design

\- Anything else

I'm especially interested in tools that save time or eliminate repetitive tasks.

What do you use, and why do you recommend it?

reddit.com
u/Manas_Patait — 3 days ago

I built a Claude Code plugin that runs PSScriptAnalyzer on each edit (real-time diagnostics)

I write a lot of PowerShell with Claude Code and got tired of finding lint issues only after the fact. So I built a plugin that runs PSScriptAnalyzer through a warm PowerShell Editor Services (PSES) daemon and feeds the result straight back into the model's context the moment a `.ps1`/`.psm1`/`.psd1` is edited -- so the mistake gets caught and corrected in the same turn. One PSES stays warm for the whole session, so each edit pays a fast pipe round-trip (warm path ~2.2s measured, guarded in CI against regressions), not a cold start.

## What it catches today (on the fly)

- **Six PSScriptAnalyzer rules surface live through PSES:** unapproved verbs, cmdlet aliases, unassigned variables (declared but never read), plaintext passwords, `$null`-on-the-wrong-side comparisons, and default values on switch parameters -- each with PSSA's own fix suggestion.

- **Plus a few always-on checks I added** for the mistakes an AI (or a careless paste) drops into PowerShell specifically, run as an AST pass before PSSA so they cost no extra parse: non-ASCII characters smuggled into a script (smart quotes, en/em dashes -- the ones that mojibake when Windows PowerShell 5.1 reads a UTF-8-without-BOM file), PowerShell-7-only syntax (`&&`, `||`, ternary, `??`) in a file that never declares `#Requires -Version 7`, and Unix/bash command names (grep, sed, awk, chmod...) dropped into a `.ps1`.

- **Straight talk on the ruleset:** PSES's live analysis set is deliberately narrower than the full Invoke-ScriptAnalyzer CLI. Notably, Write-Host (PSAvoidUsingWriteHost) is NOT surfaced on the default path. I'd rather give you the exact six than claim "the whole ruleset" and have you catch me out. If you want more, an opt-in `ruleset = base` (or your own PSScriptAnalyzerSettings.psd1) broadens the live surface -- Write-Host and the Error-severity security rules included.

## The newest piece -- native navigation

Hover, go-to-definition, and find-references now serve to Claude Code's native LSP client through an opt-in handshake shim (`nativeServe = shim`, off by default) that works around an upstream Claude Code LSP-client init-handshake bug locally, without waiting on the fix.

- **Honest caveat, because most of you are on Windows:** Claude Code 2.1.196-2.1.200 currently refuses to start the plugin's LSP server on Windows -- a launcher-level guard rejects the bare `pwsh` command before spawn ("unsafe location") -- so native nav does NOT start on Windows yet, even with the shim. It is an upstream regression (it also breaks the official pyright-lsp plugin), filed as anthropics/claude-code#73961; macOS/Linux with the real client is untested. The per-edit diagnostics loop runs through a different, unguarded path and is unaffected -- it works on every supported host.

Also opt-in, if you want them (details live in the README and its configuration reference rather than inline here): format-on-edit with a guarded write-back (`formatOnEdit = apply` -- stale-write compare-and-swap, atomic swap, BOM/EOL-preserving, and it announces itself so the agent re-reads), a "command from an uninstalled module" hint (`moduleAwareness = suggest`), and a standalone SARIF 2.1.0 / CI-scan mode (`scripts/lsp-scan.ps1`) that runs the same engine over a file or directory for GitHub code scanning -- the same analysis as the agent path, usable as a CI gate.

## Why I think it earns trust (the part I'm actually proud of)

- **Measured 0% false-positive rate on a curated correctness corpus:** 0 findings across 46 clean real-world samples, and 100% true-positive coverage (36/36 known-bad cases surface their expected rule). These aren't prose numbers -- they're recomputed from the live tool on every CI run and fail the build if the false-positive rate rises above zero or coverage drops below 100%. The expected findings are derived by running the real tool and snapshotting what it emits, so a hand-edited snapshot can't fake a pass.

- **Supply-chain posture, because a plugin that downloads and runs code should have to earn it:** PSES and PSScriptAnalyzer are version-pinned and SHA-256 verified before use, and a mismatch fails closed. The release ships a CycloneDX SBOM and a SLSA build-provenance attestation, and the release tag itself is keyless-signed via Sigstore (gitsign) through GitHub's OIDC -- no maintainer-held key in the trust path. You can verify the release yourself with `gh attestation verify`.

## A few specifics for this sub

- **Requires PowerShell 7 (pwsh) for the hooks.** Windows PowerShell 5.1 is supported only as the optional analyzer (PSES child) host -- it can't run the hooks itself.

- **Honors your repo-local PSScriptAnalyzerSettings.psd1** (the nearest one, walked up to the project root). Those settings can narrow or broaden what's reported, and they win over both the built-in set and the opt-in base ruleset.

- **Honest about onboarding:** prereqs are PowerShell 7 on your PATH plus internet on the first enabled session (PSES + PSScriptAnalyzer self-download, pinned and hash-verified). Setup is a few steps -- install pwsh if you don't have it, then /plugin marketplace add, install, enable, restart the session, and run the bundled doctor to confirm it's healthy. Not a one-liner, but the README walks it top to bottom.

**Honest status:** the inline per-edit diagnostic loop is the working surface today, on every supported host. Native navigation is the newer, opt-in bonus -- it serves through the shim on hosts where Claude Code will start the server, with the Windows launcher-guard caveat above still open upstream. The diagnostic loop does not depend on the native path at all.

GPL-3.0. Source: https://github.com/manderse21/claude-powershell-lsp

Feedback and false-positive reports welcome -- there's an issue template that feeds reports straight into the correctness corpus.

---

*Edit: reformatted for readability -- the original paste kept its hard line breaks and split every sentence mid-line. Wording is unchanged.*

reddit.com
u/Aggressive_Apple3774 — 2 days ago

Why doesn't Powershell open to the profile that I tell it to load by default?

Hey all, just had a question. So I've got a Powershell shortcut in my Open Shell menu.

I want Powershell to open to a specific profile with some settings mapped.

However, clicking on the Powershell shortcut just opens to a generic Powershell window.

If I click the drop-down menu and select the profile that I want, then it will load an administrator window with the appearance settings I've set.

Is there not a way to get this to load automatically?

u/CursedLemon — 4 days ago

Built a global-hotkey "panic button" app entirely in PowerShell (WinForms + RegisterHotKey + taskkill)

Wanted to share a project that pushes PowerShell a bit further than the usual scripting use case — a full windowed app with a tray icon, live hotkey rebinding, and a persistent config, all in one .ps1.

Technical bits that might interest people here:

  • Global hotkey via user32.dll RegisterHotKey/WM_HOTKEY, subclassed on a System.Windows.Forms.Form
  • Foreground window → owning PID via GetForegroundWindow + GetWindowThreadProcessId, then taskkill /F /T to kill the whole process tree
  • Config persisted to JSON next to the script, hotkey rebindable at runtime by capturing the next KeyDown
  • Packaged with a silent .vbs launcher so there's no console flash and no need to touch execution policy globally

Source: https://github.com/itshankkyt-rgb/panic-button

u/GalacticGalaxyyy — 4 days ago

What have you done with PowerShell this month?

A sticked post for the community to share their projects throughout the month.

Make sure to post a link to the code!

reddit.com
u/AutoModerator — 6 days ago
▲ 57 r/PowerShell+1 crossposts

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.

u/StartAutomating — 6 days ago

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!

reddit.com
u/ITZ_RAWWW — 7 days ago

Invoke-RestMethod: Problem with Body Variable Format

I am trying to convert a curl command to PoSh's Invoke-RestMethod. I typically don't have a problem with this but today, I seem to be having an issue. Curl command looks like this:

 curl https://api.domain.com/stuff/thing/items \
   -H "Authorization: Bearer $TOKEN" \
   -H "Content-Type: application/json" \
   -d '[
     { "key1": "value1", "key2": "value2" },
     { "key1": "value3", "key2": "value4" }
   ]'

To start off and make things easy, I was simply trying to do a single json entry.

$body = @"
{
    "key1": "value1",
    "key2": "value2"
}
"@ | convertto-json

Using that format I then passed it into invoke-restmethod:

Invoke-RestMethod -Uri "https://api.domain.com/stuff/thing/items" -Method post -Headers $headers -body $body

Which then spit back:

Invoke-RestMethod:                                                                                                      
{
  "result": null,
  "success": false,
  "errors": [
    {
       "code": 10026,
       "message": "filters.api.invalid_json"
    }
  ],
  "messages": []
}

I tried a few different versions of this as well without too much luck. This is the first time I've had to submit an actual key value combination to this particular API using JSON. The only other body format example I have for this particular vendor's APIs in JSON format is this:

$body = @{
    value = @(
        "value1",
        "value2",
        "value3",
        "value4"
    )
} | ConvertTo-Json

This particular endpoint didn't require a key value pair. It only required a list of strings.

Update:

Credit to /u/y_Sensei . What ended up working was this:

Single key value pair:

$body = @'
[
  {
    "key1": "value1",
    "key2": "value2"
  }
]
'@

Multi key value pair:

 $body = @'
 [
   {
     "key1": "value1",
     "key2": "value2"
   },
   {
     "key1: "value3",
     "key2: "value4"
   }
 ]
 '@

Thank you to all contributors! I appreciate it!

reddit.com
u/Khue — 6 days ago

Script to print file when it is added to folder.

Hello, I've recently been asked to make a script that prints any file in a folder. I modified one I found online before finding out that what was actually wanted was a script to make it so that any time a file is added to a folder, that file is printed.

Can I check if this is possible?

reddit.com
u/Affectionate_Air_627 — 6 days ago

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.

reddit.com
u/YellowOnline — 8 days ago

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:

https://support.microsoft.com/en-us/topic/june-23-2026-kb5095093-os-builds-26200-8737-and-26100-8737-preview-0e2a20f2-cf9e-46f8-9f08-e6996220882d

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?

u/grimson73 — 9 days ago

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-MockCalled and Assert-VerifiableMock are removed (use Should -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.

u/nohwnd — 9 days ago

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]

reddit.com
u/StartAutomating — 12 days ago
▲ 40 r/PowerShell+1 crossposts

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.

u/AdUnhappy5308 — 9 days ago