In one of my automation tasks I had the need to create a credential object with a $null password – an empty / NULL password. One easy way to do is, create just instantiate a new secure string object using the new() constructor from the .Net class like this:

 $Credentials = [System.Management.Automation.PSCredential]::new("User",[System.Security.SecureString]::new()) 

or using New-Object cmdlet like this

 $Credentials = New-Object System.Management.Automation.PSCredential("User",(New-Object System.Security.SecureString)) 

Both ways will generate a $null / NULL value for your password.

Leave a Comment