当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 将用户从一个 SharePoint 组复制到另一个 SharePoint 组

作者:精品下载站 日期:2024-12-14 13:46:08 浏览:14 分类:玩电脑

使用 PowerShell 将用户从一个 SharePoint 组复制到另一个 SharePoint 组


最近,我需要将用户从一个 SharePoint 组复制到另一个组。不幸的是,SharePoint 不支持嵌套组,并且简单地重命名组对我们没有帮助!好吧,没有直接的方法将用户从一个组复制到另一个组,但无需重新输入每个用户 ID,您可以使用此技巧来节省复制移动 SharePoint 用户的时间:

  • 转到网站操作>>网站设置
  • 单击“用户和权限”组下的“人员和组”
  • 从源组中选择所需的用户。单击“操作”菜单中的“向用户发送电子邮件”。

    [玩转系统] 使用 PowerShell 将用户从一个 SharePoint 组复制到另一个 SharePoint 组

  • 这将启动默认的电子邮件客户端,例如 Outlook。现在您可以复制这些 ID。
  • 前往目标 SharePoint 组 >> 添加用户并粘贴这些复制的 ID。

在 SharePoint 组之间复制或移动一些用户时,上述方法可能相对更简单。使用脚本化的方式批量复制多个用户不是更好吗?

用于将用户从一个 SharePoint 组复制/移动到另一个 SharePoint 组的 PowerShell 脚本:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Input variables
$WebURL = "https://sharepoint.crescent.com/sites/Operations/"
$SourceGroupName="Operations Members"
$TargetGroupName="Operations Owners"

#Get the Web
$web = Get-SPWeb $WebURL

#Get the Source and Target Groups
$SourceGroup = $web.groups | where {$_.name -eq $SourceGroupName }
$TargetGroup = $web.groups | where {$_.name -eq $TargetGroupName }

#Iterate through each users in the source group
foreach ($user in $SourceGroup.users)
{
    $TargetGroup.AddUser($user)
    Write-Host "Copied $user from $SourceGroup to $TargetGroup"
    #To move users, Just remove them from source group
    #$SourceGroup.RemoveUser($user)
}

使用 PowerShell 将用户从一个 SharePoint 网站集复制到另一个 SharePoint 网站集:

上述脚本在同一网站的 SharePoint 组之间复制用户。我们可以在不同网站集中的组之间复制用户吗?为什么不?让我们稍微更改一下上面的脚本,将用户从一个 SharePoint 网站组复制到另一个。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Input variables
$SourceWebURL = "https://sharepoint.crescent.com/sites/Operations/"
$TargetWebURL = "https://sharepoint.crescent.com/sites/Marketing/"
$SourceGroupName="Operations Members"
$TargetGroupName="Marketing Members"

#Get the Webs
$SourceWeb = Get-SPWeb $SourceWebURL
$TargetWebURL= Get-SPWeb $TargetWebURL

#Get the Source and Target Groups
$SourceGroup = $SourceWeb.groups | where {$_.name -eq $SourceGroupName }
$TargetGroup = $TargetWebURL.groups | where {$_.name -eq $TargetGroupName }

#Iterate through each users in the source group
foreach ($user in $SourceGroup.users)
{
    $TargetGroup.AddUser($user)
    Write-Host "Copied $user from $SourceGroup to $TargetGroup"
    #To move users, Just remove them from source group
    #$SourceGroup.RemoveUser($user)
}

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯