Powershell从sharepoint中的特定组中删除用户

时间:2009-09-30 18:45:15

标签: sharepoint powershell active-directory

我正在尝试从sharepoint中删除特定用户,并且已经碰壁。

我一直收到以下错误

You cannot call a method on a null-valued expression.

代码:

function verifyUsers
{
    $verify_sitepath="https://extranet.mydomain.com"
    $verify_site=new-object Microsoft.SharePoint.SPSite($verify_sitepath)
    $verify_web=$verify_site.Rootweb
    $verify_web.site.url
    $verify_groups = $verify_web.groups | ? {$_.Name -match "^.*$CurrentGroup" }
    foreach($verify_group in $verify_groups)
    {
        #Write-Output "+ $($verify_group.Name)"
        foreach($verify_user in $verify_group.users)
        {
            $verify_user = $verify_user -replace "MYDOM\\",""
            Write-Output "$verify_user" | Out-File -filepath "$splist$currentGroup.txt" -append
        }
    }
    $strReference = get-Content "C:\Powershell\Users from SharePoint\$currentgroup.txt"
    $strDifference = get-Content "C:\Powershell\Users in groups\$currentgroup.txt"
    Compare-Object $strReference $strDifference

    Compare-Object $strReference $strDifference | `
    Where-Object { $_.SideIndicator -eq "<=" } | `
    ForEach-Object {
        if ($_.InputObject -eq "testuser ")
        {
            Write-Host "testuser HAHAHAHAHA"
            $TheNewGroup = $OpenWeb.SiteGroups | Where-Object {($_.Name -match $currentGroup)}
            "group Name: $TheNewGroup.Name"
            #$TheNewGroup.deleteuser("MYDOM\" + $_.InputObject)
            #$web.Update()

            $TheNewGroup.SiteUsers.Remove("MYDOM\testuser ")
        }
        Write-Host $_.InputObject
        "Deleting user: {0} from $currentgroup" -f $_.InputObject
    }
}

2 个答案:

答案 0 :(得分:1)

找到答案(抱歉我上面的杂乱代码)

$theuser = $verify_web.AllUsers.Item("MYDOM\testuser")
$TheNewGroup.RemoveUser($theuser)

答案 1 :(得分:1)

嗯,有多种方法可以从SharePoint网站集中删除用户:

  1. 您可以使用SharePoint Web界面删除用户
  2. 使用PowerShell从SharePoint网站删除用户(也可以批量删除)
  3. 使用C#
  4. 以编程方式从SharePoint中删除用户

    在SharePointDiary.com上找到了各种可能的方法:Delete Users from SharePoint Site Collection