

If you need to store this password in the file then you can use the above command. It is in the text encoded format, not the original password. You can see the encrypted password with the method below. $creds = New-Object -TypeName -ArgumentList “test”,$passwdĬonnect-VIServer -Server TestvCenter.lab -Credential $creds Here, we are connecting vCenter server named TestvCenter.lab with $cred parameter. Now our password is secured and we can use it as a password in our credential. $passwd = | ConvertTo-SecureString -AsPlainText -Force This is useful when you have a password text file placed in a secure location and PowerShell need to use the password without cleartext.

You can convert the clear text password into a secure string format. Connect-VIServer -Server TestvCenter.lab -User "Testadmin". What if the password is in the clear text format, you can use the clear text password directly in the command which supports the Password parameter but the below method is not recommended as it is in the clear text format and it can cause a major security breach. It is just to see the password secure string. You don’t need to get the encrypted password with ConvertFrom-SecureString. Once your password string is secured, you can use directly it for the password. When you check this password variable, it is also in the Secure.String format and again you can retrieve the encrypted password with ConvertFrom-SecureString pipeline command.

$username,$passwd Connect-VIServer -Server TestvCenter.lab -Credential $creds $creds = New-Object -TypeName -ArgumentList $passwd = Read-Host "Enter Password" -AsSecureString You can use this password directly in the cmdlets that support the Credential parameter by creating a new PSCredential object as shown in the below example. PS C:\WINDOWS\system32> $passwd = Read-Host "Enter Password" -AsSecureString Enter Password: ******* You can see how this password looks in encrypted form and for that, you need to use ConvertFrom-SecureString command.

You can use the above variable with the credential parameter that cmdlet supports.įor example, Invoke-Command -ComputerName Test-PC -ScriptBlock. You can see the password is stored in the secure string. $cred = Get-CredentialĬredentials are stored into $cred variable. You can store this password into a variable and use it later in the command. We have one method where we can store the username and password is through cmdlet Get-Credential. There are few methods to encrypt the password as mentioned below. Many times we need to use passwords in PowerShell and need to pass it to the credential parameter and a password should be always a secure string, not a plain text.
