This script gets list of site collection owners for each site collection for every web application within sharepoint farm and saves them to csv file for audit purposes. Also owners can be used to get maintenance and other approvals.
This script gets list of site collection owners for each site collection for every web application within sharepoint farm and saves them to csv file for audit purposes. Also owners can be used to get maintenance and other approvals.
This csv file can be opened in Microsoft Excel for better viewing. Below is one sample output generated by script:
Assumptions:
1. This script needs to run either with farm admin privileges or a service account which has read access for every web application in the farm. Also site collections with lock state set as no access, will not be included in the script output.
2. This csv file is generated in the current working directory as per powershell prompt. If you need to save the output to some other directory, modify the value of $FileLocation variable in the script.
As a part of best practices, pls run this script in your dev/qa environment first to get familiar with script output. Here's the code:
Power Shell
############################################################################### # This script gets list of administrators for each site collection within # sharepoint farm and saves output in tab separated format (.csv) file. ############################################################################### #Set file location for saving information. We'll create a tab separated file. $FileLocation = "SiteCollectionOwnersReport.csv" #Load SharePoint snap-in Add-PSSnapin Microsoft.SharePoint.PowerShell #Fetches webapplications in the farm $WebApplications = Get-SPWebApplication -IncludeCentralAdministration Write-Output "URL `t ID `t Site Collection Owner `t Site Collection Owner Email `t Site Collection Secondary Owner `t Site Collection Secondary Owner Email " | Out-file $FileLocation foreach($WebApplication in $WebApplications){ #Fetches site collections list within sharepoint webapplication Write-Output "" Write-Output "Working on web application $($WebApplication.Url)" $Sites = Get-SPSite -WebApplication $WebApplication -Limit All foreach($Site in $Sites){ #Fetches information for each site Write-Output "$($Site.Url) `t $($Site.ID.Guid) `t $($Site.Owner.Name) `t $($Site.Owner.Email) `t $($Site.SecondaryContact.Name) `t $($Site.SecondaryContact.Email)" | Out-File $FileLocation -Append $Site.Dispose() } } #Unload SharePoint snap-in Remove-PSSnapin Microsoft.SharePoint.PowerShell Write-Output "" Write-Output "Script Execution finished" ############################################################################## ## End of Script ##############################################################################
No comments:
Post a Comment