I use a script made by Michel de Rooij which is updated regularly. I can recommend using this script. You can find it here. I have altered this a bit so I don’t have to add my credentials every time.
One of the safest ways I could find to add my credentials without exposing them is using the credential manager in Windows 10 or Windows Server. In the control panel you will find the Credential Manager.
You can add credentials here you can then use in PowerShell. Add a Windows Credential that you use for Authentication to Office 365. For instance a user that is also a Global Administrator in your tenant.
In PowerShell you can then reference to its name (adb_admin_cred) and store the credentials in a variable. I wrote a little function for myself to do this for me.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
function Get-adb-localCredential{ Import-Module CredentialManager $cr = Get-StoredCredential -Target 'adb_admin_cred' return $cr } #End function |
In a script I can then use the function and get the credential and connect to an Office 365 Service like Microsoft Teams or SharePoint Online.
1 2 3 4 5 |
Connect-MicrosoftTeams -Credential (Get-adb-localCredential) |