Thursday, March 14, 2013

Remove All Users from SharePoint Group using PowerShell

PowerShell script to remove all user from a SharePoint group programmatically:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site collection URL 
$SiteUrl="http://operations.cloudservices.com" 
$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 remove all users from sharepoint group

            $Group.RemoveUser($User)
            write-host "Removed User from Group:" $User
        } 
   }



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...