Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 36188

SharePoint Online で IE ドキュメント モードを 10 に変更するサンプル コード

$
0
0

以下のサイトに記載された IE のドキュメント モードを 10 に指定するコードが記載されております。

本投稿では、これを応用し SharePoint Online の全サイト コレクション (OneDrive for Business 個人用サイトを除く) を対象として設定を適用します。

タイトル : Display a classic SharePoint Online site in Internet Explorer 10 document mode
アドレス : https://support.office.com/en-us/article/4b4572b7-9223-45ec-8497-557a643da12a
機械翻訳 : https://support.office.com/ja-jp/article/4b4572b7-9223-45ec-8497-557a643da12a

 

事前準備

下記の内容を実施済みのクライアント環境においては、事前準備の項目を再度実施する必要はございません。

1 : SharePoint Online 管理シェルのダウンロード

サンプル スクリプトを実行するための実行環境として SharePoint Online 管理シェルをダウンロードします。

以下のリンクより最新版がダウンロード可能です。

タイトル : SharePoint Online Management Shell
アドレス : https://www.microsoft.com/ja-JP/download/details.aspx?id=35588

2 : スクリプトの実行ポリシーを変更する

1)SharePoint Online Mnagement Shell を管理者として起動します。
2) 以下のコマンドを実行し、現在の PowerShell の実行ポリシーを確認します。

Get-ExecutionPolicy

3) 以下のコマンドを実行し、PowerShell の実行ポリシーを変更します。

Set-ExecutionPolicy RemoteSigned

補足 : RemoteSigned 以上の実行ポリシー (例. Unrestricted) が指定されている場合は、指定の必要はありません。

 

コードの実行

1) 以下のコードを DisableEdgeMode.ps1 として保存します。

param(
 $adminurl,
 $username,
 $password, 
 $Disable = $true,
 $Verbose = $false
)

##the first two lines of the script load the CSOM model:
$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")

function ExecuteQueryWithIncrementalRetry($retryCount, $delay)
{
 $retryAttempts = 0;
 $backoffInterval = $delay;
 if ($retryCount -le 0)
 {
 throw "Provide a retry count greater than zero."
 }
 if ($delay -le 0)
 {
 throw "Provide a delay greater than zero."
 }
 while ($retryAttempts -lt $retryCount)
 {
 try
 {
 $script:context.ExecuteQuery();
 return;
 }
 catch [System.Net.WebException]
 {
 $response = $_.Exception.Response
 if ($response -ne $null -and $response.StatusCode -eq 429)
 {
 Write-Host ("CSOM request exceeded usage limits. Sleeping for {0} seconds before retrying." -F ($backoffInterval/1000))
 #Add delay.
 Start-Sleep -m $backoffInterval
 #Add to retry count and increase delay.
 $retryAttempts++;
 $backoffInterval = $backoffInterval * 2;
 }
 else
 {
 throw;
 }
 }
 }
 throw "Maximum retry attempts {0}, have been attempted." -F $retryCount;
}

$securepwd = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $securepwd
Connect-SPOService -Url $adminurl -Credential $cred
$siteurls = Get-SPOSite | select Url

foreach ($siteurl in $siteurls)
{
 try
 {
 $script:context = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl.Url)
 $spocred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securepwd)
 $script:context.Credentials = $spocred

if ($Disable)
 {
 #To apply script to a site collection (disable Edge) uncomment the 4 lines below:
 $featureguid = new-object System.Guid "80E47777-D21C-46E0-9139-7C7741EB4B54"
 [void]$script:context.Site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
 ExecuteQueryWithIncrementalRetry -retryCount 5 -delay 30000
 }
 else
 {
 #To apply script to a site collection (re-enable Edge) uncomment 4 lines below:
 $featureguid = new-object System.Guid "80E47777-D21C-46E0-9139-7C7741EB4B54"
 [void]$script:context.Site.Features.Remove($featureguid, $true);
 ExecuteQueryWithIncrementalRetry -retryCount 5 -delay 30000
 }
 if ($Verbose -eq $true)
 {
 Write-Output ($siteurl.Url + ",OK")
 }
 }
 catch [System.Net.WebException]
 {
 Write-Output ($siteurl.Url + ",NG," + $_)
 }
}

 

2) SharePoint Online Management Shell を起動します。
3) スクリプトを配置したフォルダーに移動し、作成した .ps1 ファイルを以下のように実行します。

.DisableEdgeMode.ps1 -adminurl https://tenant-admin.sharepoint.com -username accountname -password password

パラメータ

-adminurl ・・・ SharePoint 管理センター アドレス
-username ・・・ 各サイトに変更処理を行う管理者ユーザー
-password ・・・ 上記ユーザーのパスワード
-Disable ・・・ $true の場合、IE10 モードに変更 / $false の場合、再度 Edge モードに切り戻し (省略可 : 既定 $true)
-Verbose ・・・ $true 成功時のログも出力 / $false 成功時のログを省略 (省略可 : 既定 $false)

 

4) PowerShell 上で実行結果を確認します。

サイト コレクションの機能が有効化された場合は、以下のように URL, OK と表示されます。

成功例 (-Verbose $true の場合)

https://tenant.sharepoint.com/sites/siteA,OK

サイト コレクションの機能が有効化に失敗した場合、以下のメッセージが表示されます。

以下のメッセージが表示された場合は、スクリプトの実行アカウントがサイト コレクションの管理者として登録されているかをご確認ください。

失敗例

https://tenant.sharepoint.com/sites/siteB,NG,リモート サーバーがエラーを返しました: (401) 許可されていません

 

切り戻し

ドキュメント モードの変更を元に戻す場合は、スクリプト実行時の $Disable オプションに $false を指定して実行します。

.DisableEdgeMode.ps1 -adminurl https://tenant-admin.sharepoint.com -username accountname -password password -Disable $false

 

今回の投稿は以上です。

本情報の内容は、作成日時点でのものであり、予告なく変更される場合があります。

 



                       

Viewing all articles
Browse latest Browse all 36188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>