How to create a instance of PSCredential that has no password? (Without manually filling out a Get-Credential
dialog with no password, this is for unattended running.)
Things I tried:
$mycreds = New-Object System.Management.Automation.PSCredential ("username", $null)
Error: Cannot process argument because the value of argument "password" is null
$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.
$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.
Typically, to create a PSCredential object, you'd use the Get-Credential cmdlet. The Get-Credential cmdlet is the most common way that PowerShell receives input to create the PSCredential object like the username and password. The Get-Credential cmdlet works fine and all but it's interactive.
The PSCredential is a placeholder for a set of credentials – it basically contains a username and a password. The PSCredential object offers a safe and convenient way to handle a username and password.
$cred = Get-Credential without asking for prompts in powershell - Microsoft Tech Community.
The first way to create a credential object is to use the PowerShell cmdlet Get-Credential . When you run without parameters, it prompts you for a username and password. Or you can call the cmdlet with some optional parameters.
Solution:
$mycreds = New-Object System.Management.Automation.PSCredential ("username", (new-object System.Security.SecureString))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With