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 2010 中的 PowerShell 新增自訂宣告到 Web App 原則
我發現這個程序比預期來得困難,然而在進行後卻覺得其實比想像的容易,因此覺得應該快速寫下來。手頭的任務是透過 PowerShell 將自訂宣告新增至 Web App 原則。一旦你開始使用 PowerShell,透過管理中心 UI,一切都很簡單 (雖然我最初用的方法是建立 New-SPClaimsPrincipal 以新增到該區域的原則)。就讓你們嘲笑一下吧,下列是我試過的各種不同方法 (都和所有我思考的不同組合相去甚遠):
#$tp = Get-SPTrustedIdentityTokenIssuer -Identity "ADFS with Roles"
#$cp = Get-SPClaimProvider -Identity "BasketballTeamProvider"
#$account = New-SPClaimsPrincipal -ClaimValue "DVK Jovenut" -ClaimType "Role" -TrustedIdentityTokenIssuer $tp
#$account = New-SPClaimsPrincipal -Identity "DVK Jovenut" -TrustedIdentityTokenIssuer $tp
#$account = New-SPClaimsPrincipal -Identity "c:0ǹ.c|basketballteamprovider|dvk jovenut" -IdentityType EncodedClaim
#$account = New-SPClaimsPrincipal -ClaimValue "DVK Jovenut" -ClaimType "https://schema.steve.local/teams" -ClaimProvider $cp.ClaimProvider
#$account = New-SPClaimsPrincipal -EncodedClaim "c:0ǹ.c|basketballteamprovider|dvk jovenut"
它們當中有許多可以成功新增宣告,但顯然不是正確的識別碼,因為原則並未實作 (例如,我授與「完全控制」權限,但具有該宣告的使用者卻無法登入)。這就是「比預期來得困難」的階段。事實證明,要讓宣告可以使用,根本不需要 New-SPClaimsPrincipal 物件。下列是可正確新增和使用宣告的 PowerShell:
$WebAppName = "https://fc1"
$wa = get-SPWebApplication $WebAppName
$account = "c:0ǹ.c|basketballteamprovider|dvk jovenut"
$zp = $wa.ZonePolicies("Default")
$p = $zp.Add($account,"Claims Role")
$fc=$wa.PolicyRoles.GetSpecialRole("FullControl")
$p.PolicyRoleBindings.Add($fc)
$wa.Update()
所以,到頭來只要以簡單字串的形式新增自訂宣告就可以了。請注意,為取得該 $account 值,我先透過管理中心新增原則,然後複製完成時其所顯示的宣告值。如果未來你們需要這麼做的話,希望這能幫助你們節省一些時間。
這是翻譯後的部落格文章。英文原文請參閱 Adding A Custom Claim to a Web App Policy via PowerShell in SharePoint 2010