Powershell Windows Credentials
PSWinCreds is an easy-to-use PowerShell library that can be included with an application or scheduled task allowing users to save encrypted user credentials.Works with the native Microsoft Powershell PSCredential object supporting local and Windows Active Directory users.
Include the library with your script
. "C:\PSWinCreds\library.ps1"
Create a credentials file using the New-WinCreds Cmdlet, which will pop up a dialog prompting for a Username and Password.
New-WinCreds serviceaccountname
You can save the result of Get-WinCreds to a varaible to be used in your script later.
PS C:\>$WinCreds = Get-WinCreds serviceaccountname
UserName Password
-------- --------
\serviceaccountname System.Security.SecureString
I needed to have a scheduled task run a series of scripts against a VMware Environment via the PowerCLI pack. In order to use a service account, I created credential file via the library above, and then include the library with my scripts. Now when connecting to vCenter, the service account is used.
- Credential files will only work on the computer they were created on. You cannot move the generated XML file to another machine, as it will not be able to be decrypted.