Tip: Connect various M365 PowerShell modules for a demo tenant.


This is a quick tip to connect to a demo tenant using one-time storing of the password (a secured string) to a file and calling the connect command as many times as you want to test for the demo tenant.

#Execute Read-Host once and comment out 
#Read-Host "Enter password" -AsSecureString | ConvertFrom-SecureString | Out-File "C:\Temp\passwordNEW.txt"

$TenantName="CRM106438" # Change to your tenant name
$Username = $("admin@{0}.onmicrosoft.com" -f $TenantName)
$Password = cat "C:\Temp\passwordNEW.txt" | ConvertTo-SecureString
$Creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username, $Password
Connect-MicrosoftTeams -Credential $Creds 
Connect-ExchangeOnline -Credential $Creds
Connect-SPOservice -url $("https://{0}-admin.sharepoint.com" -f $TenantName) -Credential $Creds
Connect-Msolservice -Credential $Creds 
Connect-AzureAD -Credential $Creds 

About Pankaj

I am a Developer and my linked profile is https://www.linkedin.com/in/pankajsurti/
This entry was posted in powershell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s