Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
I have been experimenting with PowerShell scripting for the past few months.
Below is a script I have written to remove all users in a specific SharePoint group. There have been many instances where we find users have added too many individual user accounts to a specific SharePoint group. This causes many issues like search failing, performance issues, etc.
################################################################################################################
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
[System.Reflection.Assembly]::Load("System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
###########################
# "Enter the site URL here"
$SITEURL = "https://serverurl"
# "Name of Site group from which users have to be removed"
$SITEGROUP = "Site_Contributors"
###########################
$site = new-object Microsoft.SharePoint.SPSite ( $SITEURL )
$web = $site.OpenWeb()
"Web is : " + $web.Title
$oSiteGroup = $web.SiteGroups[$SITEGROUP];
"Site Group is :" + $oSiteGroup.Name
$oUsers = $oSiteGroup.Users
foreach ($oUser in $oUsers)
{
"Removing user : " + $oUser.Name
$oSiteGroup.RemoveUser($oUser)
}
################################################################################################################
Disclaimer: The above code is provided "As Is". This is just a sample code and is not production ready.
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in