Create PSCredential without a password

Question!

How to create a instance in PSCredential that has no password?

Things I tried:

  1. $mycreds = New-Object System.Management.Automation.PSCredential ("username", $null) Error: Cannot process argument because the value of argument "password" is null

  2. $mycreds = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString $null -AsPlainText -Force)) Error: ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.

  3. $mycreds = New-Object System.Management.Automation.PSCredential ("username", (ConvertTo-SecureString "" -AsPlainText -Force)) Error: ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is an empty string.



Answers

Use the Get-Credential cmdlet, when the credential dialog appears, don't type a password

$cred = Get-Credential pebrian27
$cred.GetNetworkCredential() | select UserName,Password

UserName   Password
--------   --------
pebrian27
By : Shay Levy


This video can help you solving your question :)
By: admin