如何使用 Powershell 将 AD 组添加到 SharePoint 组

如何使用 Powershell 将 AD 组添加到 SharePoint 组

我用声明身份验证对于 sharepoint 2016。AD 组是 安全组 - 本地域

我采用了该论坛(santosh kondapalli)上的代码,但它无法用于添加 AD 组。 https://sharepoint.stackexchange.com/questions/133960/how-to-add-ad-group-to-sharepoint-group-using-powershell?newreg=70f56cc5e26348b7a5c1161ba894af7b


Function AddADGroup($SPGroupName,$ADGroupName)
{    
    $SiteCollection = "http://yoursitcollectionurl"
    $site = Get-SPWeb $SiteCollection
    $site.EnsureUser($ADGroupName)
    $ADGroupSPFriendly = $site | Get-SPUser $ADGroupName
    Set-SPUser -Identity $ADGroupSPFriendly -Web $SiteCollection -Group $SPGroupName
    Write-Host $ADGroupName
    Write-Host $ADGroupSPFriendly
    Write-Host "Added the ADGroup" + $ADGroupName + "Sucessfully to the SPGroup" + $SPGroupName

    $site.Dispose()
}

#To Execute this function 

AddADGroup "Sharepointgroup" "Domain\ADGroup"

添加 AD 安全组可以吗?因为它不起作用!!

添加ADGroup“Group1”“i:0#.w | domain \FinanceADGroup”

这对于添加用户有用,但对于添加广告组则没用。

添加ADGroup“Group1”“i:0#.w|domain\User”

错误

Exception calling "EnsureUser" with "1" argument(s): "The specified user c:0-.t|adfs|fsum/ORG_senat could not be found."
At line:5 char:5
+     $site.EnsureUser($ADGroupName)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SPException

Get-SPUser : You must specify a valid user object or user identity.
At line:6 char:34
+     $ADGroupSPFriendly = $site | Get-SPUser $ADGroupName
+                                  ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Share....SPUserPipeBind:SPUserPipeBind) [Get-SPUser], PSArgumentException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetUser

Set-SPUser : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the comma
nd again.
At line:7 char:26
+     Set-SPUser -Identity $ADGroupSPFriendly -Web $SiteCollection -Gro ...
+                          ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Set-SPUser], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.SharePoint.PowerShell.SPCmdletSetUser


感谢所有帮助

答案1

您可以尝试以下操作:

$ADGroupSPFriendly = $site.EnsureUser($ADGroupName)

相关内容