Introduction


This article describes how we can utilize Windows PowerShell to connect to SharePoint Online tenant and perform administrative tasks like managing users, lists, sites, site etc. To start with, we need to setup or configure our environment by downloading and installing SharePoint Online Management Shell, which is a Windows PowerShell module.



Setup Environment


First of all, we have to download SharePoint Online Management Shell from Microsoft Download Center. Browse to this link and click on Download button. You will be prompted to select 32 bit or 64 bit version of msi to download. Download any one msi and install.

Issue #1

You get an error "This application requires the following to be installed: - PowerShell 3.0"



Now wait, as the error suggests you need to install PowerShell 3.0 prior to installing SharePoint Online Management Shell. You can download and install PowerShell 3.0 from this link. (Note: You get above error only if PowerShell 3.0 is not present on system)

One installed, again try to install SharePoint Online Management Shell. 

Launch SharePoint Online Management Shell

Go to Start -> All Programs -> SharePoint Online Management Shell Folder -> Click SharePoint Online Management Shell


Issue #2

Now you get the error: "Import-Module : The specified module 'Microsoft.Online.SharePoint.PowerShell' was not loaded because no valid module file was found in any module directory."



Note: You have to start Management Shell using "Run As Administrator"

So close this and launch again as an Administrator. Navigate to location, right click and select Run as Administrator. Now its launched without error.




Now type command: Connect-SPOService

It will prompt for url (Provide URL of your SharePoint Admin tenant) OR you can also use below command-

Connect-SPOService -url "SharePoint Admin URL"



After providing URL, it will prompt for Credentials, type in User Name, Password and hit Ok.



Now you can try out some commands to check if it is working.



Examples


Get-SPOSIte - This should return all sites created under the tenant.



Get-SPOUser - This prompts for SIte url and return all users information associated to that site like Display Name, Login Name and Group



Similarly we can use other commands or scripts to perform basic or complex administrative tasks.

Well you see commands are returning results, but what about running a script. Lets take example of "EnableSideLoading.ps1" which is used to activate Developer feature on any SharePoint site. Read more on SideLoading feature here.

Issue#3

Below error appears with message "File .ps1 cannot be loaded because running scripts is disabled on this system."



So what happened here. You need to check the script execution policy for your system using below command and see what it returns:

Get-ExecutionPolicy

If it returns "Restricted", you need to set execution policy to "Unrestricted" using below command-

Set-ExecutionPolicy "Unrestricted"

On prompt, type "Y" and you get one more error



As the error describes, you have to start PowerShell as an Administrator and re-run the commands. Once done, re-run the script:



Now, our Management Shell is all set to execute PowerShell commands and scripts.



Note


You can use Get-Command cmdlet to get list of all commands.

You can also see References section to get list of all commands and their usage.




References




See Also