Every day we need to log into hundreds of portals, as it is important for security, there must be a way to script it, automate logins without putting our actual passwords in scripts in plain text, right? Luckily this is exactly the case! User credentials (meaning username and password combinations) can be saved in Windows credential manager where they are encrypted and only accessible by us, only under that specific user account that stores them. In this article we go through the procedure of storing a credential, for example to access Exchange Online, and we log into the portal using the stored credential, with no password prompts whatsoever 🙂
Before You Begin
As a first step we need to install the Credential Manager PowerShell module. This module does not come with PowerShell by default. You'll need to install it before jumping to the next section, which is adding a new credential to the store. Open PowerShell, and issue the following command:
Save credentials
To store a new credential we need to use the Get-Credential cmdlet to store it in memory, then the New-StoredCredential cmdlet will save it in our the encrypted credential vault of our useraccount, under [userprofile]\AppData\Local\Microsoft\Vault
Use the pre-stored credentials
In this example we import the credentials in a variable and use it to access Exchange Online
We check that the credential is available, then we proceed with the login
Connect-ExchangeOnline -Credential $cred
Troubleshooting
If the Connect-ExchangeOnline cmdlet is not recognized, install the missing module:
Comments