In this post, I’ll be showing you how to use Office 365 PowerShell cmdlets to generate SharePoint Online reports from your SharePoint Online tenant. And also, I’ll be discussing 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 at this article in 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.
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 were created manually.
3. Adding a user to the Site collection administrators group.
Before I go ahead and show the syntax for this, let me specify the variables here, so that it will be easy for us to use these in the command.
$tenant = “https://vigx-admin.sharepoint.com “--> This would be my tenant URL.
$site = “https://vigx.sharepoint.com/teams/test” This will be the SharePoint site collection URL.
$user =” [email protected]” 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 [email protected] -IsSiteCollectionAdmin $true
Check the screenshot below for reference:

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.

5. To get a report of the users 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 = “https://vigx.sharepoint.com/teams/test” This will be the SharePoint site URL
Note: It’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 from 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

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








Prasanna MuraliPosted Jul 25, 2016, 9:26 PM
Nice share
Asad AliPosted Jul 25, 2016, 9:58 AM
Good one
kalu singh raoPosted Jul 25, 2016, 1:36 AM
Nice
Vipin TyagiPosted Jul 25, 2016, 12:46 AM
Very Informative....Thanks for Sharing.