PowerShell Credential Module
The MrACredential PowerShell is a collection of functions to save and import encrypted credential objects from disk.
PS C:\> Get-Command -Module MrACredential CommandType Name Version Source ----------- ---- ------- ------ Function Import-Credential 1.0 MrACredential Function New-EncryptionKey 1.0 MrACredential Function Save-Credential 1.0 MrACredential
Install the MrACredential PowerShell module from the PowerShell Gallery.
Install-Module MrACredential
Generate a new encryption key, and save it to C:\Keys\AutomationLogon.key.
New-EncryptionKey | Out-File C:\Keys\AutomationLogon.key
Lock down the key file using NTFS permissions to only the accounts or groups that should be able to use the account.
Save the automation account credential to disk using the encryption key you just made.
Save-Credential -CredentialFilePath C:\Credentials\AutomationLogon.xml -EncryptionKeyPath C:\Keys\AutomationLogon.key
Once these two files are saved to disk and secured you can import the encrypted credential for your automation processes.
$Credential = Import-Credential -CredentialFilePath C:\Credentials\AutomationLogon.xml -EncryptionKeyPath C:\Keys\AutomationLogon.key
Now you can use the imported credential with your processes.
Get-WmiObject -ClassName win32_operatingsystem -ComputerName Server01 -Credential $Credential
Or you can make it a default credential for your session.
$PSDefaultParameterValues['*:Credential']=$Credential