
Most SharePoint administration functions are performed through the graphical portal interface. However, if you frequently perform the same tasks, you can automate them using PowerShell. Administrators can use PowerShell to manage various tasks in SharePoint. Microsoft provides separate sets of cmdlets for managing on-premises SharePoint and SharePoint Online. The number of PowerShell cmdlets for SharePoint Online is less than for the on-premises version of SharePoint.
Installing SharePoint Online Management Shell
To connect to SharePoint Online, you need to install SharePoint Online Management Shell. This PowerShell module allows you to manage SharePoint Online subscription in the Office 365. To install this module, PowerShell 3.0 (included in Windows Management Framework 3.0) must be installed on your computer. Download SharePoint Online Management Shell here:
https://www.microsoft.com/en-US/download/details.aspx?id=35588
Depending on your OS, you need to download 32 or 64 bit MSI distribution.
Installation of the module is quite simple. Just follow the instructions of the installation wizard.
After the installation is complete, you can start the SharePoint Online Management Shell from the Start menu, or import the SharePoint PowerShell module into your PoSh session:
Import-Module Microsoft.Online.SharePoint.PowerShell
SharePoint Online Management Shell Commands
A complete list of available commands of the module Microsoft.Online.SharePoint.PowerShell.dll can be displayed in the way like this:
Get-Command –Module Microsoft.Online.SharePoint.PowerShell
Alternatively, you can display all available SharePoint Online cmdlets using the command:
Get-Command *-SPO*
The most frequently used cmdlets are listed below:
- Add-SPOUser
- Connect-SPOService
- Disconnect-SPOService
- Get-SPOExternalUser
- Get-SPOSite
- Get-SPOSiteGroup
- Get-SPOTenant
- Get-SPOUser
- New-SPOSite
- New-SPOSiteGroup
- Remove-SPOSite
- Remove-SPOSiteGroup
- Remove-SPOUser
- Set-SPOUser
- Set-SPOUser
- Test-SPOSite
- Upgrade-SPOSite
Now you can connect to SharePoint using the Connect-SPOService cmdlet. If you are connecting to SharePoint Online, you need to specify the tenant URL and admin account name.
Connect-SPOService –Url https://theitbrostenant.sharepoint.com –Credential admin@theitbrostenant.onmicrosoft.com
You can check the version of SharePoint as follows:
Get-SPFarm | Select BuildVersion
To list all site collection use the Get-SPOSite cmdlet.
Using the Get-Member cmdlet, you can define the properties and methods of any object. For example, using the following command you can see all the properties of the SPSite object:
Get-SPSite | Get-Member
To remove a site collection, use the Remove-SPOSite cmdlet
Remove-SPOSite -Identity theitbrostenant.sharepoint.com/sites/SiteCollectionName –NoWait
To create multiple sites from a CSV file in the following format:
Name,URL,Owner,StorageQuota,ResourceQuota,Template First Site,https://theitbrostenant.sharepoint.com/sites/site1,user1@theitbros.com,1024,300,STS#0 Corporate Blog, https://theitbrostenant.sharepoint.com/sites/blog,user2@theitbros.com,512,100,BLOG#0
Use the following script:
Import-Csv .\SitesToAdd.csv| % {New-SPOSite -Owner $_.Owner -StorageQuota $_.StorageQuota -Url $_.Url -NoWait -ResourceQuota $_.ResourceQuota -Template $_.Template -Title $_.Name}
Get the list of groups:
Get-SPOSite | ForEach-Object {Get-SPOSiteGroup -Site $_.Url} |Format-Table
Get a list of all users:
Get-SPOSite | ForEach-Object {Get-SPOUser -Site $_.Url}
Add new Site Collection administrator:
Set-SPOUser -Site {Corporate Blog} -LoginName root@theitbros.com -IsSiteCollectionAdmin $true
To remove a user from the Site Collection Administrator group:
Remove-SPOUser -LoginName root@theitbros.com -Site {Corporate Blog}
Available templates can be viewed with the command:
Get-SPWebTemplate
List of installed components:
Get-SPFeature -Limit ALL | Where-Object {$_.Scope -eq "SITE"}
List of available site templates:
Get-SPWebTemplate | where {$_.Title -match "business"}
List of running SharePoint services:
Get-Service | Where-Object {$_.DisplayName -like "Sharep*"}
Check the content database for errors:
Test-SPContentDatabase -name WSS_Content –webapplication http://blog
The post Using PowerShell Commands for SharePoint Online Management Shell appeared first on TheITBros.