You can automate PowerShell login for your local and online exchange environment so you don’t have to type user name and password every time you wants to connect to Exchange PowerShell
This scrip is also helpful if you want to run some script to generate some daily reports against your exchange server from a non-exchange server.
There are multiple methods to store your password to use in a script.
I will cover Clear password and xml file method to automate login process.
In Clear password method you store password In a Powershell script in clear text and who so ever has access to that script can see the password in use for login.
In Xml file method password will be saved in encrypted form.
So first I will cover how to use the clear password method.
Below method can be used to store credential in Clear text format
Now I will show you the 2nd method for login Automation.
So let’s First Export Credential to an Xml file and then we will use the same file for authentication in our Script Later.
# Use the below code in Script to Export Credentials to file
Once the Credentials are exported to CredFile.xml we can use them to login in our login script
Use the below code in login scrip to login automatically it will use credential from the file CredFile.xml
If you want to connect to exchange online O365 you can change the server address to https://ps.outlook.com/powershell and Authentication type as Basic and use the same method to automate the login process.
I hope this article helps you to automate login process for your scrip; please comments with your feedback and suggestions.