付録 Q PowerShell でのすべての機能の取得方法

PowerShell を使用して、SharePoint Online のサイトおよびサイト コレクションの機能を取得することができます。以下の説明を参照してください。

SharePoint Online のサイト機能の取得

サイト機能にアクセスするには、先に SharePoint Online Client Components SDK をインストールする必要があります。Microsoft ダウンロード センターから最新バージョンSharePoint Online Client Components SDK をダウンロードすることができます。

以下のコマンドを使用して、SharePoint Online のサイト機能を取得します。

#Load SharePoint CSOM Assemblies

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

 

#Variables

$SiteURL="https://<yourtenant>.sharepoint.com"

 

#Setup Credentials to connect

$Cred= Get-Credential

$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

 

#Setup the context

$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

$Ctx.Credentials = $Credentials

 

#Get Web Level Features

Write-host "`nWeb Scoped Features:"

#Get web Features

$WebFeatures = $Ctx.Web.Features

$Ctx.Load($WebFeatures)

$Ctx.ExecuteQuery()

 

#Loop through each feature and get feature data

ForEach($Feature in $WebFeatures)

{

    $Feature.Retrieve("DisplayName")

    $Ctx.Load($Feature)

    $Ctx.ExecuteQuery()

    $Feature | Select DisplayName, DefinitionId

}

 

SharePoint Online のサイト コレクション機能の取得

以下のコマンドを使用して、SharePoint Online のサイト コレクション機能を取得します。

#Import SharePoint Online Management Shell

Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking

 

#Variables

$SiteURL="https://<yourtenant>.sharepoint.com"

 

#Setup Credentials to connect

$Cred= Get-Credential

$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

 

#Setup the context

$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

$Ctx.Credentials = $Credentials

 

#Get Site Collection Features

$SiteCollFeatures = $Ctx.Site.Features

$Ctx.Load($SiteCollFeatures)

$Ctx.ExecuteQuery()          

 

#Loop through each feature and get feature data

Write-host "`nSite Collection Features:"

ForEach($Feature in $SiteCollFeatures)

{

    $Feature.Retrieve("DisplayName")

    $Ctx.Load($Feature)

    $Ctx.ExecuteQuery()

    $Feature | Select DisplayName, DefinitionId

}