Thursday 25 September 2014

Powershell Store Credentials for a Script to avoid Password Prompt

#Script : To get Credential as SECURE STRING and save in Local Drive

Read-Host "Enter the password" -AsSecureString | ConvertFrom-SecureString | Out-File C:\SecureData\SecureString.txt

#Script : To Execute PowerShell script with other credentials without prompts

$Uname = "DOMAIN\ADMIN"
$Password = Get-Content C:\SecureDate\securestring.txt | convertto-securestring
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $Uname, $Password