Author Posts

August 2, 2016 at 10:19 pm

I swear Server 2008 is the new 2003 ... I cringe when I see it now.

Anyway, I'm automating some processes for a client and their company has standardized on ... ugh ... 2008/PSv2. When writing a function under this version I noticed a curious behavior:

If I try to define a parameter of type [PSCredential] it simply "doesn't work": The parameter seems to ever load, won't tab complete, etc. That said, if I prompt for credentials in the script directly with somehting like: [PSCredential]$creds = Get-Credential then everythgin is fine.

Is it a known limitation that PSv2 can't accept PSCredentials as parameters? Or is my syntax just wrong? Do I have to request seperate username and password as securestring?

Looking for advice in "dealing with" PSv2 (aside from telling them to upgrade).

August 3, 2016 at 5:26 pm

In my testing, as yours, this first example doesn't work in PowerShell 2.0. My second example, however, did work in PowerShell 2.0.

Function Write-Cred1 {
    Param (
        [PSCredential]$Credential
    )
    $Credential
}
Function Write-Cred2 {
    Param (
        [System.Management.Automation.PSCredential]$Credential
    )
    $Credential
}

August 4, 2016 at 2:52 am

I could have sworn I tested both examples, but I will retest tonight. Thanks for being a sounding board!