PSCredential Tricks

09Nov14

So that i don’t forget….

When trying to add Credential functionality to a PowerShell script so that you can take credentials from the user to pass through to a cmdlet you need to add an additional decoration to the Parameter definition like this:

[parameter(Mandatory=$false)]
[System.Management.Automation.PSCredential]
[System.Management.Automation.CredentialAttribute()]
$Credential=$null

A big thanks to Dave Wyatt for helping me with this over at the PowerShell.org forums

Advertisements


The WordPress.com Blog

The latest news on WordPress.com and the WordPress community.

%d bloggers like this: