Delete SharePoint Custom Group Using Power Sell Scirpt
Deleted SharePoint custom group names are fetching from Excel sheet.
- In Excel shell there is one column name is "Name".
Following is the power shell script code:
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$count = 0
$contentWebAppServices = (Get-SPFarm).services |? {$_.typename -eq "Microsoft SharePoint Foundation Web Application"}
foreach($webApp in $contentWebAppServices.WebApplications)
{
write-host "Site Collections"
write-host ""
foreach ($site in $webApp.Sites)
{
$count++
write-host "Site Collections URL --> -->" $site.URL
write-host ""
write-host "SubSites"
write-host ""
if($site.AllWebs -ne 'null')
{
foreach ($web in $site.AllWebs)
{
$count++
write-host "SubSite URL --> --> -->" $web.URL
write-host ""
$spGroups = $Web.SiteGroups
for ($index = 0; $index -lt $spGroups.Count; $index++)
{
write-Host "groupname" $spGroups[$index].Name
$SharePointGroupName= import-csv "C:\Users\test1\Desktop\PowerShell Script\SharePointListName.csv"
$SharePointGroupName|ForEach-Object{
$groupname=$_.'NAME'
if ($spGroups[$index].Name -eq $groupname )
{
$spGroups.Remove($groupname)
Write-Host $groupname
$spweb.Update();
}
}
}
}
}
}
}
write-host "Total Count :" $count
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$count = 0
$contentWebAppServices = (Get-SPFarm).services |? {$_.typename -eq "Microsoft SharePoint Foundation Web Application"}
foreach($webApp in $contentWebAppServices.WebApplications)
{
write-host "Site Collections"
write-host ""
foreach ($site in $webApp.Sites)
{
$count++
write-host "Site Collections URL --> -->" $site.URL
write-host ""
write-host "SubSites"
write-host ""
if($site.AllWebs -ne 'null')
{
foreach ($web in $site.AllWebs)
{
$count++
write-host "SubSite URL --> --> -->" $web.URL
write-host ""
$spGroups = $Web.SiteGroups
for ($index = 0; $index -lt $spGroups.Count; $index++)
{
write-Host "groupname" $spGroups[$index].Name
$SharePointGroupName= import-csv "C:\Users\test1\Desktop\PowerShell Script\SharePointListName.csv"
$SharePointGroupName|ForEach-Object{
$groupname=$_.'NAME'
if ($spGroups[$index].Name -eq $groupname )
{
$spGroups.Remove($groupname)
Write-Host $groupname
$spweb.Update();
}
}
}
}
}
}
}
write-host "Total Count :" $count
No comments:
Post a Comment