Managing multiple office 365 instances with powershell scripts

I’ve migrated a lot of customers to Office 365. The web-based partner administration for Exchange, Sharepoint and Lync works well, but some things are just easier with with powershell. Here’s how I administer Office 365 instances with custom powershell scripts.

I basically create a separate PS1 file for each office365 instance pre-configured with the admin username. All I have to do to manage that instance is double click a file and enter a password and I’m ready to go. Here’s how:

[requirements]

Windows PowerShell
[download] Microsoft Online Services Sign-In Assistant BETA (v7.0)
[download] Windows Azure Active Directory Module for Windows PowerShell

[step 1] Download and install the Microsoft Online Services Sign-In Assistant BETA.

[step 2] Download and install the Windows Azure Active Directory Module for Windows PowerShell (WAADM).

[step 3] Open an instance of the WAADM PowerShell and set the execution policy to remotesigned by entering the command below and selecting Y for Yes when prompted:

Set-ExecutionPolicy remotesigned

[step 4] Copy and paste the following code into a text editor and save it as InstanceName.ps1:


#--------start script----------

param ( $Show )
if ( !$Show )
{
PowerShell -NoExit -File $MyInvocation.MyCommand.Path 1
return
}
$user = "office365admin(at)yourdomain.com"
$UserCredential = Get-Credential -Credential $user
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $session

#--------end script----------

[step 5] Right-click the PS1 file you created in [step 4] and select Open With… and then select the Windows PowerShell executable in C:WindowsSystem32WindowsPowerShellv1.0powershell.exe and check the box to Always use this application.

associate-ps1-files-with-windows-powershell

[step 7] Duplicate the PS1 scripts so you can have one file for each administrative office365 account username you have and change the following line in each of those files to match your office365 admin user:

$user = “[email protected]

Now to manage an office365 instance, simply double-click the matching PS1 file, enter the password and start issuing commands. Bam! Done!

powershell-enter-credentials-for-office365 powershell-ready-office365-commands

Comments

One response to “Managing multiple office 365 instances with powershell scripts”

  1. Michael Avatar

    Or, if you’ve got delegated admin for the tenant, you can connect directly to their Exchange online instance using your partner ID.

    https://technet.microsoft.com/en-us/library/dn705740.aspx

    There may be ways to connect to the other O365 services as well, I haven’t gotten that far yet.

Skip to content