Get-xSPOTenantSetting.ps1


<#PSScriptInfo
 
.VERSION 1.0
 
.GUID e5ac2874-6e29-4a38-b549-76e48f636044
 
.AUTHOR Chendrayan Venkatesan
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS SharePointOnline CSOM PowerShell
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES Microsoft.SharePoint.Client.dll, Microsoft.Online.SharePoint.Client.Tenant.dll
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 Get-xSPOTenantSetting retrieves all the SharePoint online Tenant properties. This function allows to select the properties required with tab completion.
 
#>
 
 param 
 (
     # SharePoint Online Url
     [Parameter(Mandatory)]
     [Uri]
     $Url,

     # SharePoint Online Admin Credential
     [Parameter(Mandatory)]
     [System.Management.Automation.CredentialAttribute()]
     [pscredential]
     $Credential
 )
Import-Module 'C:\Program Files\NuGet\Packages\Microsoft.SharePointOnline.CSOM.16.1.5312.1200\lib\net45\Microsoft.SharePoint.Client.dll'
Import-Module 'C:\Program Files\NuGet\Packages\Microsoft.SharePointOnline.CSOM.16.1.5312.1200\lib\net45\Microsoft.Online.SharePoint.Client.Tenant.dll' 
function Get-xSPOTenantSetting
{
<#
.SYNOPSIS
    Get SharePoint Online Tenant Settings
.DESCRIPTION
    Get-xSPOTenantSetting retrieves all the SharePoint online Tenant properties.
    This function allows to select the properties with tab completion.
.EXAMPLE
    C:\PS> Get-xSPOTenantSetting -Url https://contoso-admin.sharepoint.com -Credential Chendrayan@contoso.onmicrosoft.com
    Get all the properties of the given SharePoint Online Tenant site
.EXAMPLE
    C:\PS> Get-xSPOTenantSetting -Url https://contoso-admin.sharepoint.com -Credential Chendrayan@contoso.onmicrosoft.com | Select <Tab>
    Get selected the properties of the given SharePoint Online Tenant site
.EXAMPLE
    C:\PS> Get-xSPOTenantSetting -Url https://contoso-admin.sharepoint.com -Credential Chendrayan@contoso.onmicrosoft.com | GM
    Get all the methods and properties.
.INPUTS
    Inputs (if any)
.OUTPUTS
    Output (if any)
.NOTES
    To check the Tenant properties use help Get-xSPOTenantSetting -Online
#>

    [Outputtype('Microsoft.Online.SharePoint.TenantAdministration.Tenant')]
    [CmdletBinding(ConfirmImpact="High",HelpUri="https://msdn.microsoft.com/en-us/library/microsoft.online.sharepoint.tenantadministration.tenant_properties.aspx")]
    param 
    (
        # SharePoint Online Url
        [Parameter(Mandatory)]
        [Uri]
        $Url,

        # SharePoint Online Admin Credential
        [Parameter(Mandatory)]
        [System.Management.Automation.CredentialAttribute()]
        [pscredential]
        $Credential
    )

    process
    {
        try 
        {
            $SPOClientContext = [Microsoft.SharePoint.Client.ClientContext]::new($Url)
            $SPOClientContext.Credentials = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($Credential.UserName,$Credential.Password)
            $SPOTenant = [Microsoft.Online.SharePoint.TenantAdministration.Tenant]::new($SPOClientContext)
            $SPOClientContext.Load($SPOTenant)
            $SPOClientContext.ExecuteQuery()
            $SPOClientContext.Dispose()
            $SPOTenant
        }
        catch
        {
            $_.Exception.Message
        }
    }
}