我想知道如何通过CSV将单个用户添加到多个群组?这是我尝试过的,但不起作用。
$SPWeb = Get-SPWeb “https://sharepoint"
$SPList = $SPWeb.Lists["LISTNAME"]
$exportlist = @()
$SPList.Items | foreach {
$obj = New-Object PSObject -Property @{
’SharePointAccessGroup’= $_["SharePointAccess"]
’samaccountnameSharePoint’= "i:0#.w|domain\" + $_["SAMAccountName"]
} $exportlist += $obj
$exportlist | Export-Csv -path ‘C:\SharePointGroup.csv’ -noType
}
$dataa = import-Csv -Path "C:\SharePointGroup.csv" -Delimiter ";"
foreach ($s in $dataa)
{
$SharePointAccessGroup = $s.SharePointAccessGroup
$samaccountnameSharePoint = $s.samaccountnameSharePoint
$Groups=($s.SharePointAccessGroup)
foreach ($g in $Groups) {
set-SPUser -Identity $s.samaccountnameSharePoint -Web https://sharepoint -Group $g
}
答案 0 :(得分:1)
因此,如果我正确地阅读您的代码,看起来您正在尝试添加用户但使用内部名称(i:0#.w | ...)这不会与set-SPUser一起使用。只需使用Domain \ username。此外,如果用户不在UIL中,您可能需要使用New-SPUser。
New-SPUser -UserAlias <domain\username> -Web "https://sharepoint" -Group $g
希望这有帮助。