This script captures the below information's,
- All subsites under the site collection
- All lists
- Item Count
- All items
- Ersion details
- Security details
The output will be available as a CSV file and text files on the same location where the script is placed.
- $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
- $LogFile = ".\SiteReportPatch-$LogTime.rtf"
-
- # Add SharePoint PowerShell Snapin
-
-
- if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
- Add-PSSnapin Microsoft.SharePoint.Powershell
- }
-
- $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
- Set-Location $scriptBase
-
-
- #Deleting any .rtf files in the scriptbase location
- $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
- if($FindRTFFile)
- {
- foreach($file in $FindRTFFile)
- {
- remove-item $file
- }
- }
Start-transcript $logfile - write-host "################################################" -fore cyan
- Write-host "Generating site reports" -fore yellow
- write-host "Following informations will be captured" -fore yellow
- write-host "All subsites under the site collection" -fore yellow
- write-host "All lists" -fore yellow
- write-host "Item Count" -fore yellow
- write-host "All items" -fore yellow
- write-host "Version details" -fore yellow
- write-host "Security details" -fore yellow
- write-host "################################################" -fore cyan
-
-
- Function SiteReport()
- {
-
- $Output = $scriptBase + "\" + "SiteReport.csv";
- "SiteCollection" + "," + "Webs" + "," + "Lists" + "," + "ItemCount" + "," + "Items" + "," + " ItemID" + "," + "VersionCount" | Out-File -Encoding Default -FilePath $Output;
- $NoValue = ""
- $SiteCollectionURL = read-host "Enter the site collection URL "
- $global:SiteCollectionURL + "," + $NoValue + "," + $NoValue + "," + $NoValue + "," + $NoValue + "," + $NoValue + "," + $NoValue | Out-File -Encoding Default -Append -FilePath $Output;
- $global:Site = get-spsite $SiteCollectionURL
- foreach($web in $site.allwebs)
- {
- $NoValue + "," + $web.url + "," + $NoValue + "," + $NoValue + "," + $NoValue + "," + $NoValue + "," + $NoValue | Out-File -Encoding Default -Append -FilePath $Output;
- $lists = $web.lists
- foreach($list in $lists)
- {
- $NoValue + "," + $NoValue + "," + $list.title + "," + $list.items.count + "," + $NoValue + "," + $NoValue + "," + $NoValue | Out-File -Encoding Default -Append -FilePath $Output;
- $listitems = $list.items
- foreach($item in $listitems)
- {
- if($item.versions)
- {
- $VersionCount = $item.versions.count
- }
- else
- {
- $VersionCount = $NoValue
- }
- $NoValue + "," + $NoValue + "," + $NoValue + "," + $NoValue + "," + $item.name + "," + $item.ID + "," + $VersionCount | Out-File -Encoding Default -Append -FilePath $Output;
- }
- }
- }
- write-host "Site report completed" -fore green
-
- }
-
- Function SitePermission()
- {
-
- foreach($web in $site.allwebs)
- {
- Write-host "Collecting permission details for the web " $web.url -fore Yellow
- $users = get-spuser -web $web.url -Limit ALL
- foreach($user in $users)
- {
- write-host $User.userlogin
- $permissionInfo = $web.GetUserEffectivePermissionInfo($User.userLogin)
- $roles = $permissionInfo.RoleAssignments
- write-host "Now checking the permissions of the user " $User.userLogin " in the site " $web.Url -fore magenta
- for ($i = 0; $i -lt $roles.Count; $i++)
- {
- $bRoles = $roles[$i].RoleDefinitionBindings
- foreach ($roleDefinition in $bRoles)
- {
- if ($roles[$i].Member.ToString().Contains('\'))
- {
- write-host "The User " $user.userLogin " has direct permissions " $roleDefinition.Name -fore green
- "The User " + $user.userLogin + " has direct permissions " + $roleDefinition.Name | out-file $scriptbase\DirectPermissons.txt -append
- }
- else
- {
- write-host "The User " $user.userLogin " has permissions " $roleDefinition.Name " given via " $roles[$i].Member.ToString() -fore green
- "The User " + $user.userLogin + " has permissions " + $roleDefinition.Name + " given via " + $roles[$i].Member.ToString() | out-file $scriptbase\GroupPermissions.txt -append
- }
- }
- }
- }
-
- }
- write-host "Permission details collected" -fore green
- }