Skip to content

Instantly share code, notes, and snippets.

@BrianTJackett
Created November 15, 2019 16:14
Show Gist options
  • Save BrianTJackett/7e687931f12f2aaa4d1511c845a7959d to your computer and use it in GitHub Desktop.
Save BrianTJackett/7e687931f12f2aaa4d1511c845a7959d to your computer and use it in GitHub Desktop.
This snippet will store credentials for 2 different accounts encrypted to disk. They will then be loaded into PSCredentials as global variables. Place this in your profile for automatic loading.
New-PSDrive -Name Scripts -PSProvider FileSystem -Root <folderLocationOfScriptsGoesHere>
#read-host -AsSecureString -Prompt "Enter O365 password 1" | ConvertFrom-SecureString | set-content scripts:\O365AdminPassword1.txt
#read-host -AsSecureString -Prompt "Enter O365 password 2" | ConvertFrom-SecureString | set-content scripts:\O365AdminPassword2.txt
function Import-O365AdminCredential
{
$smtpAddress1 = "[email protected]"
$CredsFile1 = "Scripts:\O365AdminPassword1.txt"
$smtpAddress2 = "[email protected]"
$CredsFile2 = "Scripts:\O365AdminPassword2.txt"
$password1 = get-content $CredsFile1 | ConvertTo-SecureString
$password2 = get-content $CredsFile2 | ConvertTo-SecureString
$global:DemoAdminCred1 = New-Object -typename System.Management.Automation.PSCredential -argumentlist "$smtpAddress1", $password1
$global:DemoAdminCred2 = New-Object -typename System.Management.Automation.PSCredential -argumentlist "$smtpAddress2", $password2
}
Import-O365AdminCredential
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment