You can always create a credential object manually, by entering a username and password into the prompt created by the line:
$cred = get-credential
While it's not recommended due to a lack of security, however, sometimes you just need to enter a username and password in plain text, to get a script working, or maybe just to test it out. Here's how you can do that. (Just make sure you store your script in a secure location).
Here's the code you need to use:
$domain = "YourDomain.whatever" $username = "$domain\YourUserAccount" $password = "YourPassword" | ConvertTo-SecureString -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential($username,$password)
You can now use this $cred object in any other cmdlet, such as:
$output = Add-Computer -Credential $cred -DomainName $domain
If you look at the contents of the $password variable, you will notice that it simply displays "System.Security.SecureString".
The following command will show you the actual secure string that your password was converted to:
$password | convertfrom-securestring
Which will show you something like:
This string is tied to the user account you're logged in as when you create it. If you are going to run your script under another user - then create the secure password string under THAT account, otherwise it will not work.