Remove multiple SharePoint groups listed in *csv file using Powershell

    if ((Get-PSSnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue) -eq $null) {
Write-Host “Connect SharePoint Cmd-Let”
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
$sp = Get-SPSite ” https://mysharepoint
$spWeb = $sp.RootWeb
$csvlocation = “c:\csv\groupsDeleteList.csv”
$values = Import-Csv $($csvlocation) -Delimiter “;”
    $values | ForEach-Object {
    if($_.group -eq $spWeb.SiteGroups[$_.group])
{
$spWeb.SiteGroups.Remove($_.group)
$spWeb.Update()
Write-Host “Group “$_.group” Deleted!”
}
else
{
Write-Host “Group “$_.group” doesn’t Exists!”
}
    }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s