List all SharePoint sites, users and groups using Powershell

Create a .ps1 script and run this in the sharepoint management console


[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null

$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
$webapps = @()

foreach ($websvc in $websvcs) {
           write-output "Web Applications" >> sitelist.txt
           write-output "" >> sitelist.txt
    foreach ($webapp in $websvc.WebApplications) {
        write-output "Webapp Name -->"$webapp.Name >> sitelist.txt
           write-output "" >> sitelist.txt
           write-output "Site Collections" >> sitelist.txt
           write-output "" >> sitelist.txt
    foreach ($site in $webapp.Sites) {
        write-output "Site URL --> -->" $site.URL >> sitelist.txt
           write-output "" >> sitelist.txt
           write-output "Websites" >> sitelist.txt
           write-output "" >> sitelist.txt
    foreach ($web in $site.AllWebs) {
        write-output "Web URL --> --> -->" $web.URL >> sitelist.txt
           write-output "" >> sitelist.txt
           write-output "Lists" >> sitelist.txt
           write-output "" >> sitelist.txt
    foreach ($list in $web.Lists) {
           write-output "List Title --> --> --> -->" $list.Title >> sitelist.txt
           write-output "" >> sitelist.txt
    }

    foreach ($group in $web.Groups) {
           write-output "Group Name --> --> --> -->" $group.Name >> sitelist.txt
           write-output "">> sitelist.txt

    foreach ($user in $group.Users) {
           write-output "User Name --> --> --> -->" $user.Name >> sitelist.txt
           write-output "" >> sitelist.txt
    }
    }

    }

    }

    }
}
Share on Google Plus

About Tom DeMeulenaere

Highly accomplished information technology professional with extensive knowledge in System Center Configuration Manager, Windows Server, SharePoint, and Office 365.
    Blogger Comment

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.