This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$username = "[email protected]" | |
$AESKey = Get-Content $AESKeyFilePath | |
$pwdTxt = Get-Content $SecurePwdFilePath | |
$securePwd = $pwdTxt | ConvertTo-SecureString -Key $AESKey | |
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
The synopsis goes here. This can be one line, or many. | |
This version of the template has inbuilt functions to capture credentials and store it securely for reuse | |
Avoids the need to have plaintext passwords in the script | |
.DESCRIPTION | |
The description is usually a longer, more detailed explanation of what the script or function does. | |
Take as many lines as you need. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate a random AES Encryption Key. | |
$AESKey = New-Object Byte[] 32 | |
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($AESKey) | |
# Store the AESKey into a file. This file should be protected! (e.g. ACL on the file to allow only select people to read) | |
Set-Content $AESKeyFilePath $AESKey # Any existing AES Key file will be overwritten | |
$password = $passwordSecureString | ConvertFrom-SecureString -Key $AESKey | |
Add-Content $credentialFilePath $password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$username = "[email protected]" | |
$pwdTxt = Get-Content "C:\temp\ExportedPassword.txt" | |
$securePwd = $pwdTxt | ConvertTo-SecureString | |
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$secureStringText = $secureStringPwd | ConvertFrom-SecureString | |
Set-Content "C:\temp\ExportedPassword.txt" $secureStringText |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$username = "[email protected]" | |
$password = "Password123!@#" | |
$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force | |
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList $user, $secureStringPwd |