If teh password comes from a secure pipeline variable, the password is still a string within the pipeline and cannot be received and implicitly converted to SecureString. So teh param definition has to be String and the password then to be converted to SecureString in the script:
1
2
3
4
5
6
7
# Parameter[Parameter(Mandatory=$true)][SecureString]$Password#Convert to SecureString$SecurePassword=ConvertTo-SecureString$env:PASSWORD-AsPlainText-Force$Credential=New-Object-TypeNameSystem.Management.Automation.PSCredential-ArgumentList$Username,$SecurePassword