How to create a PSCredential in Powershell

I was writing a script to pull some process details from a remote computer and every time I had to give enter the user/pass which is quite annoying. But luckily I found the below to pass the credentials:

$pwd= ConvertTo-SecureString "YOUR PASSWORD" -AsPlainText -Force
$credObj= New-Object System.Management.Automation.PSCredential ("YOUR USERNAME", $secpasswd)

If you want to create the credential object in interactive mode then you can use the below:


$credObj= Get-Credential


There is a detailed article here