kwizcom banner advertisement

Remove All Users from SharePoint Group using PowerShell

Requirement: SharePoint Remove all users from group

SharePoint PowerShell to remove all users from group:
PowerShell script to remove all user from a SharePoint group programmatically:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site collection URL 
$SiteUrl="http://intranet.crescent.com/sites/operations" 
$GroupName = "Operation Managers"

#get the Root Web
$web = Get-SPWeb $SiteUrl

#Get the Group
$Group = $Web.sitegroups | Where-Object {$_.Name -eq $GroupName}

If($Group -ne $null)
{
    $GroupUsers = $Group.Users
    
    foreach ($User in $GroupUsers)
    {
        #powershell to remove all users from sharepoint group
        $Group.RemoveUser($User)
        write-host "Removed User from Group:" $User
    }
}
else
{
    write-host "Group doesn't Exists!" -f yellow
}
Remove All Users from SharePoint Group using PowerShell Remove All Users from SharePoint Group using PowerShell Reviewed by Salaudeen Rajack on March 14, 2013 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.