<#
******-----------------------------------------------------------------------******
Author -> Shiv Mangal Singh
Date -> 6th December - 2016
Description -> This Script will generate the all AD Security Groups from the site collection
Path of csv file->$path = "D:\contosoSPSSU_MW_Team\Shiv\ps\ADGroups_InvFrontOffice1.csv"
Site Collection Name --> $Site = Get-SPSite "https://ms.contoso.net/global/InvFrontOffice"
******-----------------------------------------------------------------------******
#>
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#variable for data collection
$Site = Get-SPSite "https://ms.contoso.net/global/InvFrontOffice"
$ADGroupCollection= @()
$ReportPath ="D:\contoso\Shiv\ps\ADGroups_InvFrontOffice1.csv"
Write-host -foregroundcolor green "Processing Site Collection: "$site.RootWeb.URL
#Get all AD Security Groups from the site collection
$ADGroups = Get-SPUser -Web $Site.Url | Where { $_.IsDomainGroup -and $_.displayName -ne "Everyone" }
#Iterate through each AD Group
foreach($Group in $ADGroups)
{
Write-host "Found AD Group:" $Group.DisplayName
#Get Direct Permissions
$Permissions = $Group.Roles | Where { $_.Name -ne "Limited Access" } | Select -ExpandProperty Name
#Get SharePoint User Groups where the AD group is member of.
$SiteGroups = $Group.Groups | Select -ExpandProperty Name
#Send Data to an object array
$ADGroup = new-object psobject
$ADGroup | add-member noteproperty -name "Site Collection" -value $Site.RootWeb.Title
$ADGroup | add-member noteproperty -name "URL" -value $Site.Url
$ADGroup | add-member noteproperty -name "Group Name" -value $Group.DisplayName
$ADGroup | add-member noteproperty -name "Direct Permissions" -value ($Permissions -join ",")
$ADGroup | add-member noteproperty -name "SharePoint Groups" -value ($SiteGroups -join ",")
#Add to Array
$ADGroupCollection+=$ADGroup
}
#Export Data to CSV
$ADGroupCollection | export-csv $ReportPath -notypeinformation
Write-host "SharePoint Security Groups data exported to a CSV file at:"$ReportPath -ForegroundColor Cyan
******-----------------------------------------------------------------------******
Author -> Shiv Mangal Singh
Date -> 6th December - 2016
Description -> This Script will generate the all AD Security Groups from the site collection
Path of csv file->$path = "D:\contosoSPSSU_MW_Team\Shiv\ps\ADGroups_InvFrontOffice1.csv"
Site Collection Name --> $Site = Get-SPSite "https://ms.contoso.net/global/InvFrontOffice"
******-----------------------------------------------------------------------******
#>
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#variable for data collection
$Site = Get-SPSite "https://ms.contoso.net/global/InvFrontOffice"
$ADGroupCollection= @()
$ReportPath ="D:\contoso\Shiv\ps\ADGroups_InvFrontOffice1.csv"
Write-host -foregroundcolor green "Processing Site Collection: "$site.RootWeb.URL
#Get all AD Security Groups from the site collection
$ADGroups = Get-SPUser -Web $Site.Url | Where { $_.IsDomainGroup -and $_.displayName -ne "Everyone" }
#Iterate through each AD Group
foreach($Group in $ADGroups)
{
Write-host "Found AD Group:" $Group.DisplayName
#Get Direct Permissions
$Permissions = $Group.Roles | Where { $_.Name -ne "Limited Access" } | Select -ExpandProperty Name
#Get SharePoint User Groups where the AD group is member of.
$SiteGroups = $Group.Groups | Select -ExpandProperty Name
#Send Data to an object array
$ADGroup = new-object psobject
$ADGroup | add-member noteproperty -name "Site Collection" -value $Site.RootWeb.Title
$ADGroup | add-member noteproperty -name "URL" -value $Site.Url
$ADGroup | add-member noteproperty -name "Group Name" -value $Group.DisplayName
$ADGroup | add-member noteproperty -name "Direct Permissions" -value ($Permissions -join ",")
$ADGroup | add-member noteproperty -name "SharePoint Groups" -value ($SiteGroups -join ",")
#Add to Array
$ADGroupCollection+=$ADGroup
}
#Export Data to CSV
$ADGroupCollection | export-csv $ReportPath -notypeinformation
Write-host "SharePoint Security Groups data exported to a CSV file at:"$ReportPath -ForegroundColor Cyan
No comments:
Post a Comment