Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
SharePoint サポートチームの多田 信吾 (タダ シンゴ) です。
SharePoint の発行ページ等で、個人用ビューの設定が許可されている場合、各ユーザーがそれぞれ個別に個人用ビューに Web パーツを貼り付けることができます。
管理者が各ユーザーの個人用ビューを確認したい場合、各個人で作成しているビューであるため、UI からは確認ができません。このため、PowerShell で個人用ビューの設定を抽出する必要がありますが、PowerShell はスクリプトを実行しているユーザのコンテキストで動作するため、そのユーザーの個人用ビューしか取得できません。例えば以下のサンプルスクリプトにおいて、スクリプトを実行しているユーザーが、domain\testuser01 である場合は、domain\testuser01 の個人用ビューのみが取得されます。
$web = Get-SPWeb "https://sp2010/sub01"
$file = $web.GetFile("Pages/testpage01.aspx")
$webpartMgr = $file.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::User)
このため、以下のサンプルスクリプトのように、各ユーザーのユーザートークンを指定して SPSite のオブジェクトを生成することで、各ユーザーの個人用ビューを取得することが可能です。
以下のサンプルスクリプトでは、サイトに所属するすべてのユーザーの個人用ビューにおいて、貼られている Web パーツの情報を取得してテキストに書き出しています。
$web = Get-SPWeb "https://sp2010/sub01"
foreach($user in $web.AllUsers)
{
$site = New-Object Microsoft.SharePoint.SPSite("https://sp2010", $user.UserToken)
$web2 = $site.OpenWeb("sub01/")
$file = $web2.GetFile("Pages/testpage01.aspx")
try
{
$webpartMgr = $file.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::User)
}
catch
{
$user.LoginName + " では個人用ビューページが開けませんでした。" | Add-Content -Encoding UTF8 "C:\share\work\result.txt"
$file = $null
$site.Dispose()
$web2.Dispose()
continue
}
$user.LoginName | Add-Content -Encoding UTF8 "C:\share\work\result.txt"
foreach($webpart in $webpartMgr.WebParts)
{
$webpart.Title | Add-Content -Encoding UTF8 "C:\share\work\result.txt"
}
$file = $null
$webpartMgr = $null
$site.Dispose()
$web2.Dispose()
}
$web.Dispose()
- 参考資料
タイトル : SPSite constructor (String, SPUserToken)
アドレス : https://msdn.microsoft.com/EN-US/library/ms469253.aspx
タイトル : SPWeb.GetLimitedWebPartManager method
アドレス : https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.spweb.getlimitedwebpartmanager.aspx
タイトル : PersonalizationScope Enumeration