Outputting SharePoint Online Tenant Settings using CSOM


Here is a quick script that outputs the current SharePoint Online tenant settings using CSOM with PowerShell, this is similar to using the Get-SPOTenant Cmdlet from the SharePoint Online Management Shell however could come in useful if you don't have this installed.

Simply update the value of the $Site variable, replacing "tenant" with the name of your tenant. This script requires the CSOM DLLs, the easiest way to get these is via Nuget.

#Tenant Admin URL
$Site = "https://tenant-admin.sharepoint.com"

#Add references to SharePoint client assemblies and authenticate to Office 365
Add-Type -Path "D:\CSOM\Microsoft.SharePoint.Client.dll"
Add-Type -Path "D:\CSOM\Microsoft.Online.SharePoint.Client.Tenant.dll"
$Username = Read-Host "Please enter your username"
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username,$Password)
$Context.Credentials = $Creds

#Create tenant object and output current settings
$Tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Context)
$Context.Load($Tenant)
$Context.ExecuteQuery()
$Tenant

Here is an example of the output:

TenantSettings

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Brendan Griffin - @brendankarl


Comments (2)

  1. Chen V says:

    Hi Brendan, to fetch the tenant settings we don’t need assembly “Microsoft.SharePoint.Client.Publishing.dll” and $Context.Dispose() method will help disposing the object (Best Practice). Reference : https://www.powershellgallery.com/packages/Get-xSPOTenantSetting/1.0/DisplayScript

    1. Thanks for spotting that, it that was a copy/paste error.

Skip to main content