All About Connecting to SharePoint Online using SharePoint Online PowerShell

Connecting to SharePoint Online using SharePoint Online PowerShell


Perform the following:
  • Install Windows PowerShell 3.0 from Windows Management Framework 3.0.
  • Install the SharePoint Online Management Shell from the Microsoft Download Center.
  • Click Start>All Programs>SharePoint Online Management Shell.
  • Run Connect-SPOService. For example, Connect-SPOService -Url https://contoso-admin.sharepoint.com -credential admin@contoso.com, where: Url is the URL of the SharePoint Online Administration Center.
  • Credential is the user name to which you want to grant access to the SharePoint Online Administration Center site.


Commonly faced issues when you start using Powershell for SharePoint Online.

"The specified module 'Microsoft.Online.SharePoint.Online.PowerShell' was not loaded because no valid module file was found in any directory"

This could occur because of many reason, please try the following:
  1. Run the SharePoint Online PowerShell as administrator, the prompt shall be PS  C:\windows\system32>
  2. You can trying uninstall sharepoint online powershell and reinstall it. Try to restart you PC. Verify the 32/64 bit version of your System and install appropriate version of SharePoint Online Management Shell.
  3. Check the Execution policy of the Powershell using the following command:
                Get-executionpolicy

This shall not be restricted, make it unrestricted or RemoteSigned using the following cmdlet
Set-executionpolicy unrestricted

Hopefully you have got rid of the above error now. Let's see how to connect to SP Online.
For example, my admin site is:


Before we try to connect to the SharePoint online from powershell, let set the credentials to access the admin site.

Lets use the following script to define a variable for credential like $credential

PS> $credential = get-credential

Now, following command will allow us to connect to SP Online.

PS>connect-sposervice -url https://mydemosite.sharepoint.com  -credential $credential

Error: Current site is not a tenant administration site. So SP is not allowing you to connect as the SharePoint site is not a tenant administrator. Nothing to worry about; just give the tenant admin URL as following:

Change this
To

So now the new cmdlet is:

PS>connect-sposervice -url https://mydemosite-admin.sharepoint.com  -credential $credential

You may get an error:
“Could not connect to SharePoint online”

Resolution:
This probably means; you proxy is blocking the connection. Use the following cmdlet to get rid of this.

PS>$cred = [System.Net.CredentialCache]::DefaultCredentials
PS>[System.Net.WebRequest]::DefaultWebProxy.Credentials = $cred

Now you shall be able to connect to SP Online flawlessly using the same command.

PS>connect-sposervice -url https://mydemosite-admin.sharepoint.com  -credential $credential



Try couple of commands like:


This shall list all the sites in your SharePoint online account.

Cheers….


Comments

Popular posts from this blog

SharePoint log error "Cannot find site lookup info for request Uri http://"

Visual Studio Build Issue : Build: 0 succeeded or up-to-date, 0 failed, 1 skipped

Reset your SharePoint Farm PassPhrase