Manage Office 365 SharePoint with Modules


Summary: Learn how to use Office 365 SharePoint Online modules to manage Office 365 SharePoint.

Microsoft Scripting Guy, Ed Wilson, is here. In a couple of days, the Scripting Wife and I will be at the Dutch PowerShell User Group in Amsterdam. If you are anywhere in the area, you should try to come and check it out. I will be making two presentations:

  • Windows PowerShell Workflow for Mere Mortals
  • Everything You Wanted to Know about DSC, but Didn’t Know Who to Ask

There will be at least two Windows PowerShell MVPs in attendance, and it will be an all-day event beginning at 08:30 on April 2, 2014. Come check it out, you will be glad you did.

     Note  This is the fifth in a series of Hey, Scripting Guy! Blog posts where I talk about
     using Windows PowerShell with Office 365.

Unfortunately, I am unable to use Windows PowerShell implicit remoting to work with SharePoint Online. This means that on my admin computer, I need to install the SharePoint Online Management Shell from the Microsoft Download Center. According to the system requirements, I need Windows PowerShell 3.0, but I am running Windows PowerShell 4.0 on my Windows 8.1 laptop. I hope that the installation package does not do a strict version check and fail. Anyway, here is the download page:

Image of screen

As far as I can tell, this is the most recent version of the SharePoint Online Management Shell. I am afraid that it will somehow lock me into some crippled version of the Windows PowerShell console, and it will not permit me to use my own Windows PowerShell profile. I click the download link, and I am presented with the following page to permit me to select the appropriate package for my system. I am offered the two choices shown here:

Image of menu

I select the 64-bit version of the package, permit pop-ups, and say it can run with Admin rights. I am presented with the following:

Image of agreement

After I accept the license agreement and click Install, the installation runs to completion. There are no options…nothing to select or choose. The installation is simple and to the point as shown here:

Image of screen

Now the issues begin. I open the Windows PowerShell console and type Get-Module –ListAvailable **. I do not see anything that looks like it might be related to SharePoint. I want to make sure, so I use **Ge-Module -ListAvailable *share*, and the only thing that comes back is related to SMBShare.

Bummer. Don’t tell me I am going to be locked into some silly SharePoint Management Shell. I look around on my desktop, but do not find any shortcuts. Hmmmmmm…

So I go to my Windows 8.1 Start page, and I scroll down to see all apps. I keep searching, and finally I find it in the location shown in the following image:

Image of menu

I click the link, and I am presented with the error message shown in the following image. Clearly, this didn’t work as planned. The error says it cannot find a SharePoint module anywhere. And, as I was afraid of, the SharePoint Online Management Shell is not really optimized for Windows PowerShell. It uses default fonts, and it does not enable QuickEdit mode. But at least, the exercise tells me what to look for.

Image of message

This time, I open the Windows PowerShell console with Admin rights, and once again I use the **Get-Module –ListAvailable **command. Only this time, I tell it a bit more about what I am look for. Here is the command I use:

Get-Module -ListAvailable *Online.SharePoint*

WooHoo! Success. As you can see in the following image, I finally found the Online SharePoint module. It is hiding in the C;\Program Files\SharePoint Online Management Shell folder. Wow, I would have never guessed that one. Luckily, Windows PowerShell ROCKS.

Image of command output

Cool. Personally, I do not like running the Windows PowerShell console with Admin rights, so I close the Administrator Windows PowerShell console, and open it with basic non-elevated rights. I now know where to look for the module, so I specify the exact path while importing the module. This command is shown here (this is a single-line command that is wrapped):

Import-Module ‘C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell’

When I press ENTER and import the module, I receive the following warning message, which states that the module contains some unapproved verbs. This means I need to look for other than the standard Get and Set types of verbs, but the module should work anyway. It is safe to simply be aware of the issue, but I can still use it.

Image of message

Now, it is time to connect to the SharePoint Online service. To do this, I use the Connect-SPOService cmdlet. The command is a bit complex, and if I was going to do this on a daily basis, I would write a function to include in my profile. More about that in a minute, but for now, here is the Connect-SPOService command:

Connect-SPOService -Url https://ScriptingGuy-Admin.SharePoint.Com -Credential (Import-Clixml C:\fso\cred.xml)

Note  Keep in mind that I stored my credentials in a Cred.xml file. For information about that, see Use PowerShell to Explore Office 365 Installation.

After I type this command, I am connected to the SharePoint Online site.

Note  How did I know the URL to use? I found it by looking on the SharePoint Admin Center web page in my Office 365 Admin portal.

Simplifying things

The preceding command is a decent amount of typing, and it is not even very intuitive. I can simplify the process by creating a function that I call Connect-SharePointOnline that will import the module, and then call the Connect-SPOService cmdlet to make the connection for me. The function is shown here:


Function Connect-SharePointOnline


 $cred = Import-Clixml C:\fso\cred.xml

 Import-Module ‘C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell’ -DisableNameChecking

 Connect-SPOService -Url https://ScriptingGuy-Admin.SharePoint.Com -Credential $cred


I place the function in my personal profile, and then whenever I want to make a connection to my SharePoint Online site, I simply call the function. I can even assign an alias if I want to make it even easier to use.

If I want to know what cmdlets are available from the SharePoint Online module, I use the Get-Command cmdlet as shown here:

Get-Command -module *SharePoint*

To find my sites, I use the Get-SPOSite cmdlet with no parameters.

If I want to find users who are associated with a site, I need to specify the site—and the URLs are a bit too much typing. Therefore, I can get the sites, and then use the Foreach-Object cmdlet to walk through the collection of sites and return users for sites. The command is shown here:

Get-SPOSite | % { Get-SPOUser -Site $_.url}

The cool thing is that I can use an expression to return the site that I am interested in, and then feed that directly to the Get-SPOUser cmdlet as shown here:

Get-SPOUser -Site (Get-SPOSite | Where URL -match ‘smbverticals’).url

Unfortunately, the Get-SPOUser cmdlet will not accept an array for the site, and the following command fails:

Get-SPOUser -Site (Get-SPOSite | Where URL -match ‘contoso’).url

But whenever I am confronted with an issue like that, I simply pipe it to the Foreach-Object cmdlet and walk through the collection. Therefore, the following command works fine for me:

Get-SPOSite | Where URL -match ‘contoso’ | % {get-spouser -Site $_.url}

This concludes Office 365 Week. Join me tomorrow when I will talk about using Windows PowerShell to change the Start page for Internet Explorer on my Microsoft Surface device.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 


Comments are closed. Login to edit/delete your existing comments

Feedback usabilla icon