Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
January 19, 2023

Coding Confirmed Commands

Let’s pick up where we left off in the last article. We’ve been looking at adding support for -WhatIf and -Confirm to your PowerShell commands. You get these parameters for free simply by telling PowerShell you want them.

[cmdletbinding(SupportsShouldProcess)]

That’s it. Any command in your function that also supports this attribute will automatically inherit the parameter setting. I showed you this last time with -WhatIf. Coding for confirmation is a little more complicated as it involves another cmdletbinding attribute. But let’s start with something simple.

Here’s a sample function that creates a new folder. Presumably, I want to run additional commands after the folder is created with New-Item. This cmdlet recognizes SupportsShouldProcess.

Want to read the full issue?
GitHub Bluesky LinkedIn About Jeff
Powered by Buttondown, the easiest way to start and grow your newsletter.