Create encrypted passwords in PowerShell

The following PowerShell cmdlet will prompt you for a password as input. The input will be encrypted and saved to the root of C in a file called password.pass.

read-host -assecurestring | convertfrom-securestring | out-file C:password.pass

To read the encrypted password and create a credentials object using the following.
$pwd = get-content C:temppassword.pass | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist “domainaccount”,$pwd

The $cred object can be password cmdlets which require username/password information.

Running Powershell Scrips

By default Power Shell disables the running of scripts. To identify the current execution policy type Get-ExecutionPolicy at the power shell prompt.

To set the execution policy use Set-ExecutionPolicy followed the the desired level . For example the following will enable RemoteSigned which allows any local script to be run but only signed downloaded scripts.

Set-ExecutionPolicy RemoteSigned.

If using 64 Bit Windows 7 / Server 2008 there are two versions of Powershell, 32 Bit and 64 Bit. The execution policy is unique to each version and must be applyed individually.

32Bit: C:WindowsSysWOW64WindowsPowerShellv1.0
64Bit: C:WindowsSystem32WindowsPowerShellv1.0

Execution policy can also be defined at the following registry locations.

32Bit Client on 32Bit Windows or 64Bit Client on 64Bit Windows: HKLMSOFTWAREMicrosoftPowerShell1ShellIdsMicrosoft.PowerShell

32Bit Client on 64Bit Windows: HKLMSOFTWAREWow6432NodeMicrosoftPowerShell1ShellIdsMicrosoft.PowerShell

Set / Add the following key.

REG_SZ – ExecutionPolicy=RemoteSigned