我有一个包含大量子网站的SharePoint网站。 在一些网站和子网站上有一个名为" a-team"的广告组。
小组" a-team"必须再也无法访问。一个名为" c-team"已经被创造了。 我的问题是要取代" a-team"与" c-team"在所有网站/子网站上,其中" a-team"是。 没有" a-team"的网站/子网站关闭没有得到" c-team"加入。
现在代码添加" c-team"所有网站/子网站的女巫都是错的。它关闭只会添加组,如果组" a-team"在网站/子网站上。 没有" a-team"的子网站关闭没有得到" c-team"添加。
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$siteUrl = "http://MyTest.demosite.net/sites/EAL"
$permissionLevel = "Design"
$domainGroup = "c:0+.w|s-1-5-21-3475484702-42583850-3077926241-3108" # a-team
$domainGroupAdd = "c:0+.w|s-1-5-21-3475484702-42583850-3077926241-3110" # c-team
$spSite = new-object Microsoft.SharePoint.SPSite($siteUrl)
$firstTime = "true";
$myRole;
foreach ($web in $spSite.AllWebs){
## Finding role ##
$roles = $Web.RoleDefinitions;
$roleAssignments = $web.RoleAssignments;
if ($firstTime -eq "true")
{
for($k = 0; $k -lt $roles.Count; $k++){
Write-Output $web.Url
$role = $roles[$k]
if( $role.Name -eq $permissionLevel)
{
$myRole = $role; # Role fundet
}
}
$firstTime = "false";
}
## Adding group "c-team" to site ##
if($roleAssignment.Member.SystemUserKey -eq $domainGroup){
Write-Host -ForegroundColor White -BackgroundColor Green "Found the right type " $role.Name;
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($domainGroupAdd, "", "", "");
$assignment.RoleDefinitionBindings.Add($myRole);
$roleassignments = $web.RoleAssignments;
$roleassignments.Add($assignment);
Write-Output $web.Url;
}
$web.Dispose();
}
$spSite.Dispose();
在:
http://MyTest.demosite.net/sites/EAL" - Site permissions: "a-team", admin
http://MyTest.demosite.net/sites/EAL/Test1" - Site permissions: "a-team", admin
http://MyTest.demosite.net/sites/EAL/Test2" - Site permissions: admin
http://MyTest.demosite.net/sites/EAL/Test3" - Site permissions: "a-team", admin
http://MyTest.demosite.net/sites/EAL/Test4" - Site permissions: admin
After:
http://MyTest.demosite.net/sites/EAL" - Site permissions: "c-team", admin
http://MyTest.demosite.net/sites/EAL/Test1" - Site permissions: "c-team", admin
http://MyTest.demosite.net/sites/EAL/Test2" - Site permissions: admin
http://MyTest.demosite.net/sites/EAL/Test3" - Site permissions: "c-team", admin
http://MyTest.demosite.net/sites/EAL/Test4" - Site permissions: admin
答案 0 :(得分:0)
我找到了解决方案。 在sharepoint中替换组:
首先添加新的,然后删除旧的。
$siteUrl = "http://MyDemosite.demosite.net/sites/EAL"
$permissionLevel = "Design"
$oldGroupName = "eal\a-team"
$newGroup = "c:0+.w|s-1-5-21-3475484702-42583850-3077926241-3109"
$spSite = new-object Microsoft.SharePoint.SPSite($siteUrl)
$firstTime = "true";
$myRole;
foreach ($web in $spSite.allwebs)
{
$roles = $web.RoleDefinitions;
if ($firstTime -eq "true")
{
for($k = 0; $k -lt $roles.Count; $k++)
{
Write-Output $web.Url
$role = $roles[$k]
if( $role.Name -eq $permissionLevel)
{
$myRole = $role;
}
}
$firstTime = "false";
}
foreach ($name in $web.RoleAssignments.member.displayname)
{
if($name -eq $oldGroupName)
{
Write-Host -ForegroundColor White -BackgroundColor Green "Found the right type " $role.Name
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($newGroup, "", "", "");
$assignment.RoleDefinitionBindings.Add($myRole);
$roleassignments = $web.RoleAssignments;
$roleassignments.Add($assignment);
Write-Output $web.Url;
}
}
$web.Dispose();
}
$spSite.Dispose();
并删除所有网站上的群组/用户:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$siteUrl = "http://mydemosite.demosite.net/sites/eal"
$RemoveGroup = "eal\b-team"
$spSite = new-object Microsoft.SharePoint.SPSite($siteUrl)
foreach ($web in $spSite.allwebs)
{
## Remove user/group
foreach ($user in $web.SiteUsers)
{
if ($user.DisplayName -eq $RemoveGroup)
{
$web.siteusers.Remove($user)
Write-Host -ForegroundColor White -BackgroundColor Green "Found the right user "
}
}
$web.Dispose();
}
$spSite.Dispose();