Monday, July 25, 2016

Part 1: Useful Office 365 cmdlets to generate SharePoint Online reports and also for SharePoint Online site administration:

In this post I’ll be showing you how to use Office 365 PowerShell cmdlets to generate useful SharePoint Online reports from your SharePoint Online tenant and also I’ll be discussing on certain useful cmdlets that can be used for SharePoint Online site administration. Let’s get started.

Note: Before we get started, please ensure that you’ve configured your PC to run SharePoint Online (Office 365) cmdlets. If not, please take a look on this article which I’ve already written about how to configure that. Also make sure that you’re a member of the SharePoint Online administration role in Office 365.

1. Get-SPOSite -Detailed

This command will give a detailed list of all the site collections in your SharePoint Online tenant as shown in the screenshot below.

1.png

2. To get a list of SharePoint groups in your tenant.

Syntax:   Get-SPOSite | ForEach-Object {Get-SPOSiteGroup -Site $_.Url} |Format-Table 

Running this command will generate the results as shown in the image below. Also please note that this command will display the default SharePoint groups as well as the custom SharePoint groups that was created manually.

2.png

3.png

3. Adding a user to the Site collection administrators group.

Before I go ahead and show the syntax for this, let me go ahead specify the variables here so that it will be easy for us to use that in the command.

$tenant =  “http://ift.tt/29gjiLo “–>This would be my tenant URL

$site = “http://ift.tt/2ao9Ya3” –>This will be the SharePoint site collection URL

$user =” kamaleshg@vigx.onmicrosoft.com” –> This will be the UPN for the user who will be added as the SCA.

Since we have already specified all the variables, let’s go ahead and run the syntax.

Syntax:  Set-SPOUser -Site $site -LoginName kamaleshg@vigx.onmicrosoft.com -IsSiteCollectionAdmin $true

Check the screenshot below for reference:

4.png

5.png

So this will add the user to the SCA group of  a site collection.

4. To get the list of users in my SharePoint Online Tenant:

Syntax:  Get-SPOSite | ForEach-Object {Get-SPOUser -Site $_.Url} 

Running this command will display the results as shown in the screenshot below.

replace.PNG

 5.To get a report of the user’s in a site, their display names, permission levels and other properties:

Before I go ahead and execute the command for this, let me specify the $site variable for the site in question.

$site = “http://ift.tt/2ao9Ya3” –>This will be the SharePoint site URL

NoteIt’s not necessary that you need to keep specifying the variables every time in a command unless you’re planning to use a different value apart to the one specified for that variable. PowerShell will automatically store it for you till the session is live.

Syntax:  Get-SPOUser -Site $site | select * | Format-table -Wrap -AutoSize | Out-File G:\UsersReport.txt -Force -Width 360 -Append

8.png

Running this command will generate a report as shown in the screenshot below.

6. To get a report of the all user’s in your SharePoint Online Tenant, their display names, permission levels and other properties

$tenant =  “http://ift.tt/29gjiLo “–> This would be my tenant URL

Syntax:

Get-SPOSite | ForEach-Object {Get-SPOUser -Site $_.Url} | Format-Table -Wrap -AutoSize | Out-File G:\UsersReport.txt -Force -Width 360 -Append

10.png

Note: PowerShell might throw you some errors while running this command but that can be safely ignored.

Running this command will generate a report as shown below.

11.png

If you want to export the result to a CSV file, try running the below mentioned command.

Command 1 : For setting the headers in the CSV file

“Display Name`tLoginName`tGroups” | Out-File C:\UsersReport.csv

 12.png

Command 2: Once you’re done executing the first line, run the below syntax to get the report in the form a CSV file.

Syntax:

Get-SPOSite | ForEach-Object {Get-SPOUser -Site $_.Url -ErrorAction SilentlyContinue | %{ $_.DisplayName + “`t” + $_.LoginName

 + “`t” + $_.Groups | Out-File c:\UsersReport.csv -Force -Append}}

13

This will generate a CSV file as shown in the image below,

14.png

 7. To create a new SharePoint Group in a site collection.

Before I mention the syntax, let’s specify the necessary variables.

$tenant = “http://ift.tt/29gjiLo” –>Tenant URL

$site = “http://ift.tt/2ao9Ya3 “–> Site collection URL

$group = “Test Site Owners2” –>SharePoint Group Name

$level = “Full Control” –> Permission level

Syntax:

New-SPOSiteGroup -Group $group -PermissionLevels $level -Site $site

15.png

Running the above command will create a new SharePoint Group in the targeted site collection and will give the results as shown below.

16.png

8. To create an inventory of all the SharePoint site collections in your Tenant which has the information of the Site Name, URL, Quota, compatibility level and other information etc.… and to export the results to a CSV file:

Syntax:

Get-SPOSite -Detailed | Export-CSV -LiteralPath G:\SiteInventory.csv -NoTypeInformation

17.png

Running this command will generate a CSV file in specified path as shown in the image below.

18.png

 9. To get your SharePoint Online Tenant information

Syntax: Get-SPOTenant

This will give the complete tenant information as shown in the image below.

19.png

  1. To get the list of site templates in your SharePoint Online tenant

SyntaxGet-SPOWebTemplate

Running this command will give the list of site templates in SharePoint Online as shown below

20.png

This concludes part 1 of this article, I’ll be creating part 2 of this article where I’ll be taking you through few more SharePoint Online PowerShell cmdlets that can help us to generate useful reports and also for site administration.

Thanks for reading this post.

Happy SharePointing!!!  


by Vignesh Ganesan via Everyone's Blog Posts - SharePoint Community

No comments:

Post a Comment