This script is used to recurse the farm and list all sites in the farm.  This script is used for inventorying the farm and the basis of any scripts that need to act on all sites in the farm.

 

function Get-SiteInventory() {
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
    foreach ($spService in $farm.Services) {
        if (!($spService -is [Microsoft.SharePoint.Administration.SPWebService])) {
            continue;
        }

        foreach ($webApp in $spService.WebApplications) {
            if ($webApp -is [Microsoft.SharePoint.Administration.SPAdministrationWebApplication]) { continue }

            foreach ($site in $webApp.Sites) {
                foreach ($web in $site.AllWebs) {
                            $data = @{
                                "Web Application" = $webApp.ToString()
                                "Site" = $site.Url
                                "Web" = $web.Url
                                "ServerRelativeUrl" = $web.ServerRelativeUrl
                                "Parent" = $web.ParentWeb.Url
                                "Title" = $web.Title
                                "MasterUrl" = $web.MasterUrl
                                "CustomMasterUrl" = $web.CustomMasterUrl
                                "RequestAccessEmail" = $web.RequestAccessEmail
                                "RequestAccessEnabled" = $web.RequestAccessEnabled
                                "RecycleBinEnabled" = $web.RecycleBinEnabled
                                "WebTemplate" = $web.WebTemplate
                                "HasUniquePerm" = $web.HasUniquePerm
                            }
                            New-Object PSObject -Property $data

                    $web.Dispose();
                }
                $site.Dispose()
            }
        }
    }
}

Get-SiteInventory  |Out-GridView
Get-SiteInventory | Export-Csv -Path c:\users\istcbfm\inventory.csv
Get-SiteInventory | Export-Clixml -Path c:\users\istcbfm\inventory.xml