Freigeben über


Making credentials

The PowerShell remoting commands use the parameter -Credential. If you use a string for its value, PowerShell is smart enough to take it as a user name and automatically call a type cast that will ask for the password in a GUI window. But what if you want to enter the password as plain text from the script? (Mind you, it's not the most secure practice, although convenient for the test environments). It's far from obvious. It can be done like this:

$user = "PresidentSkroob"
$password = "12345"
$cr = New-Object System.Management.Automation.PSCredential @($user, (ConvertTo-SecureString -Force -AsPlainText $password))