PowerShell

PowerShell – Create a Credential Object with NULL Password

null

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.

One Reply to “PowerShell – Create a Credential Object with NULL Password

Leave a Reply to Sid Snot Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.