The estimated reading time 2 minutes
During my daily work I need to connect to Office 365 powershell from time to time, so I also want to automate this task to safe time and also because I’m a lazy guy. Befor using my O365 connector you should read my other articles about encrypting passwords to secure string. See my prolog working with passwords.
Now let’s introduce my new O365 connector, which uses two files to authenticate against O365.
Before we start with the connector it self; here are some basics for converting your password to an file with special aes encryption.
NOTE: everyone who has both files can reconvert it into clear text, so use a secure place to store these two files! (like keepass etc.)
SKRIPT DOWNLOAD ZIP File
Generating a random AES key in powershell:
$aeskeypath = ".\it-koehler.key" $AESKey = New-Object Byte 32 [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($AESKey) Set-Content $aeskeypath $AESKey
Password encryption with aes file
$pw = Read-Host "type in a password!"-AsSecureString $pw $key = Get-Content .\it-koehler.key $encryptpw = $pw | ConvertFrom-SecureString -Key $key #copy content to file Set-Content .\alexander.txt $encryptpw
As mentioned see my other articels about automating this step
No more kidding with passwords, so how does my connector work?
As you can see you can trigger my script with some parameters. Let’s explain them and what they’re expecting to do.
complete path to the encrypted password with aes
complete path to aes key file
– AzureAD = Connection to AzureAD (Module AzureAD required)
– ExOn = Exchange Online Connection (see manual)
– MSOL = Microsoft O365 Powershell Console (Module MSonline required)
– MSSkype = Microsoft Skype Online (Module Install required)
– MSTeams = Microsoft Teams Powershell (Module MicrosoftTeams)
username which machtes the password you encrypted and has permissions to manage your O365 environment
All parameters are required, if you forget one of them the script will ask.
NOTE: If you type in $commands and press enter after connection is established, you can see all imported commands. (does not work on exchange/skype powershell connection)
I use this script to connect really fast to O365 services via powershell.
NOTE: MultifactorAuth is not supported!
Now some “feature fu****” what the script can do.
- … checks whether the credfile and keyfile is a file or is a path to a file
- … has a verbose option to understand what it does
- … checks the module required for connection installed properly
- … imports modules
- … possible to connect two different services with one powershell
Please leave me a comment or push the “helpful” button. Looking forward to get some feedback.
Have fun with this connector.
thanks for sharing
[…] Zunächst muss natürlich zur Exchange Online PowerShell verbunden werden siehe hierzu mein Artikel O365 Connector oder diesen […]
[…] to this gmail address. (needs an active connection to Exchange Online powershell (see my article O365 connector or use this […]