Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create PSCredential without a password

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:

  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.

like image 957
LostInComputer Avatar asked Jul 27 '11 03:07

LostInComputer


People also ask

How do you create PSCredential?

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.

Is PSCredential secure?

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.

How do I pass credentials in PowerShell without prompt?

$cred = Get-Credential without asking for prompts in powershell - Microsoft Tech Community.

How do I pass a username and password in PowerShell?

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.


1 Answers

Solution:

$mycreds = New-Object System.Management.Automation.PSCredential                ("username", (new-object System.Security.SecureString)) 
like image 100
LostInComputer Avatar answered Oct 12 '22 00:10

LostInComputer