The answer is yes you can however I couldn’t find this documented so I decided to write a post on how to create a Super Office 365 PowerShell script to get connected to all four PowerShell services in a single PowerShell session with Office 365 Education.
What PowerShell options do I have for Office 365?
You have four remote PowerShell options to help administer your Office 365 tenant:
What do I need to do to get everything setup?
You will need to configure all four Office 365 Online PowerShell sessions as shown below:
Azure Active Directory PowerShell
1) Setup Azure AD PowerShell first:
See instructions here you will need to install Sign In Assistant and the 32 or 64 bit Azure AD PowerShell module. After those two steps are completed:
Add these two lines to your super PowerShell script:
$msolcred = get-credential connect-msolservice -credential $msolcred
Exchange Online PowerShell (EOP powershell also)
Good news here is you don’t need to install anything to make Exchange Online PowerShell or Exchange Online Protection PowerShell run.
Just add two lines in your Super Office 365 Powershell script:
$ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $msolcred -Authentication Basic –AllowRedirection
SharePoint Online PowerShell
The good news for SPO powershell is you don’t need to install anything.
You can just add this to your super powershell script:
Connect-SPOService -Url https://contoso-admin.sharepoint.com –credential $msolcred
note: you need to put in the specific tenant name in place of ‘contoso’ in the script.
More on SharePoint Online powershell setup and list of cmdlets here.
Install the Lync Online PowerShell module here and run.
Add these two lines to your super powershell script:
$lyncsession=New-CsOnlineSession –credential $msolcred
See more info here.
See list of Lync Online cmdlets here.
Is there a sample script you can use to get everything in one?
Yes, follow the steps below (be sure to change ‘yourtenantname’ to your tenant name):
0. Open local PowerShell with ‘Run As Administrator’ and run Set-ExecutionPolicy RemoteSigned. This is required to allow the running of local .PS1 files within your powershell.
1. Grab sample Super PowerShell for Office 365 snippet I put together below:
$msolcred = get-credentialconnect-msolservice -credential $msolcred$ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $msolCred -Authentication Basic -AllowRedirectionImport-PSSession $ExSession$lyncsession = New-CsOnlineSession -Credential $msolcred Import-PSSession $lyncsessionConnect-SPOService -Url https://yourtenantname-admin.sharepoint.com -credential $msolcred