次の方法で共有


Can I create a single PowerShell session for Lync Online, SharePoint Online, Azure AD, and Exchange Online?

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:

  • Azure Active Directory PowerShell
  • Exchange Online PowerShell
  • SharePoint Online PowerShell
  • Lync Online PowerShell

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

image

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

Import-PSSession $ExSession

    

SharePoint Online PowerShell

You need to download and install the SharePoint Online PowerShell module here.

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.

Lync Online

Install the Lync Online PowerShell module here and run.

image

Add these two lines to your super powershell script:

$lyncsession=New-CsOnlineSession –credential $msolcred

Import-PSSession $lyncsession

See more info here.

See list of Lync Online cmdlets here.

Note: Reboot after you install all of these modules. The script won't work if you don't reboot first.

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-credential
connect-msolservice -credential $msolcred
$ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $msolCred -Authentication Basic -AllowRedirection
Import-PSSession $ExSession
$lyncsession = New-CsOnlineSession -Credential $msolcred 
Import-PSSession $lyncsession
Connect-SPOService -Url https://yourtenantname-admin.sharepoint.com -credential $msolcred

2. Save code as connect.ps1 or whatever

3. Create a shortcut to launch this such as:

powershell.exe –noexit c:\path\connect.ps1

image

and pin it to the taskbar for quick access

4. Launch your shortcut and login with Tenant Admin credentials:

image

image

4. To make sure the Super PowerShell script worked, verify you can run the following cmdlets within your single PowerShell session:

Get-msoluser (Azure AD) PowerShell:

image

Get-mailbox (Exchange Online PowerShell):

image

Get-CSactiveuserreport (Lync Online PowerShell):

image

Get-SPOactiveuserreport (SharePoint Online PowerShell):

image

Comments

  • Anonymous
    January 01, 2003
    thanks
  • Anonymous
    June 06, 2014
    I was asked by several customers what are some of the new SKU names they can use and where can they find
  • Anonymous
    August 29, 2014
    Very nice! Only comment is that it should include closing sessions as needed (i.e. for exchange, Lync) and possibly the disconnect from the SharePoint online service.