1

I have searched a lot but didn't get a perfect idea on how to connect PowerShell with Office 365 SharePoint site. Can somebody please explain me how to make my SharePoint online site PowerShell ready and what all we can do with PowerShell for SharePoint Online. I know PowerShell is very powerful for on premise, so what all functionalities are gone will also help.

Thanks for your Help!

1

You can use the SharePoint Online Management Shell to efficiently manage users, sites, and organization.

To run the SharePoint Online Management Shell cmdlets, you have to be a SharePoint Online global administrator.

First you need to connect to SharePoint online using

Connect-SPOService -Url https://contoso-admin.sharepoint.com -credential admin@contoso.com

After connecting you can leverage cmdlets as explained in below link

https://technet.microsoft.com/en-us/library/fp161388.aspx

  • Isn't it enough to be a site collection Admin? – Taran Goel Jul 2 '15 at 12:00
1

You need to Download SharePoint Online Management Shell and SharePoint Online Client Components SDK in order to work with SharePoint Online using PowerShell. Then you can write PowerShell code and execute it in SharePoint Online Management Shell. Following sample code creates a list (Document Library) in SharePoint online.

#Import the required DLL
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
#OR
#Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'

#Mysite URL
$site = 'https://yoursite.sharepoint.com/'

#Admin User Principal Name
$admin = 'admin@tenant.onmicrosoft.com'

#Get Password as secure String
#$password = Read-Host 'Enter Password' -AsSecureString
$password = ConvertTo-SecureString "YourPassword" -asplaintext -force
#Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)

#Authenticate
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin , $password)
$context.Credentials = $credentials
$listCreationInformation = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$listCreationInformation.Title = "My Documents"
$listCreationInformation.Description = "Library created through PowerShell"
$listCreationInformation.TemplateType = 101
$list = $context.Web.Lists.Add($listCreationInformation)
$context.Load($list)
$context.ExecuteQuery()

Source: SharePoint Online: Create a list using PowerShell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.