Get All SiteCollection Audit Info

cls
#get-spsite -Limit All -ContentDatabase WSS_Content_ProjectServer | select url,@{label=”Size in GB”;Expression={$_.usage.storage/1024MB}} | Format-Table –AutoSize

function ProcessSiteCollection($site)
{

$list = $site.url

if ($site.Quota.Storagemaximumlevel -gt0)
{
[int]$MaxStorage = $site.Quota.StorageMaximumLevel /1MB
}
else
{ $MaxStorage = “0”
};
$contentDbName = get-spsite -Identity $list -Limit All | select contentdatabase
if ($site.Usage.Storage -gt0) {[int]$StorageUsed = $site.Usage.Storage /1MB};
if ($Storageused -gt0 -and $Maxstorage -gt0){[int]$SiteQuotaUsed = $Storageused / $Maxstorage * 100} else {$SiteQuotaUsed = “0”};
$subsite = New-Object System.Object

$subsite | Add-Member -MemberType NoteProperty -Name “Url” -Value $site.Url
$subsite | Add-Member -MemberType NoteProperty -Name “Web Application” -Value $Webapp.DisplayName
$subsite | Add-Member -MemberType NoteProperty -Name “Owner Name” -Value $site.Owner.Name
$subsite | Add-Member -MemberType NoteProperty -Name “Owner Email” -Value $site.Owner.Email
$subsite | Add-Member -MemberType NoteProperty -Name “Last Modified” -Value $site.LastContentModifiedDate.ToShortDateString()
$subsite | Add-Member -MemberType NoteProperty -Name “Quota Limit (MB)” -Value $MaxStorage
$subsite | Add-Member -MemberType NoteProperty -Name “Total Storage Used (MB)” -Value $StorageUsed
$subsite | Add-Member -MemberType NoteProperty -Name “Site Quota Percentage Used” -Value $SiteQuotaUsed
$subsite | Add-Member -MemberType NoteProperty -Name “Content DB” -Value $site.ContentDatabase.Name
$global:SiteCollInfo += $subsite

Write-Host “Title :” $site.HostName
Write-Host “Url :” $site.Url
Write-Host “Web Application” $Webapp.DisplayName
Write-Host “Owner Name” $site.Owner.Name
Write-Host “Owner Email” $site.Owner.Email
Write-Host “Last Modified” $site.LastContentModifiedDate.ToShortDateString()
Write-Host “Quota Limit (MB)” $MaxStorage
Write-Host “Total Storage Used (MB)” $StorageUsed
Write-Host “Site Quota Percentage Used” $SiteQuotaUsed
Write-Host “Content DB” $site.ContentDatabase.Name
Write-Host
# $web = Get-SPWeb $site.Url
# [long]$total = 0
# # $total += GetWebSize -Web $web
# $val = ProcessSubWebs -Site $web
# $total += $total +$val ;
# $totalInMb = ($total/1024)/1024
# $totalInMb = “{0:N2}” -f $totalInMb
# $totalInGb = (($total/1024)/1024)/1024
# $totalInGb = “{0:N2}” -f $totalInGb
# write-host “Total size of all sites below” $StartWeb “is” $total “Bytes,”
# write-host “which is” $totalInMb “MB or” $totalInGb “GB” -foregroundcolor blue
$web.Dispose()

}

function ProcesWebApplication($Webapp)
{
Write-Host “Web Application : ” $webApp.name
Write-Host “Application Pool : ” $webApp.ApplicationPool.Name
# #Get all Solution in Web Application
# Get-SPSolution | ForEach-Object {
# if ($_.LastOperationDetails.IndexOf($webApp.url) -gt 0)
# {
# Write-Host ” Solutions:”
# Write-Host ” ” $_.DisplayName
# }
# }

#Get All Site Collection in a Web Application
foreach($site in $webApp.Sites)
{
ProcessSiteCollection $site ;
$site.Dispose()
}

}

$global:SiteCollInfo = @()
#Get All Web Application
$contentWebAppServices = (Get-SPFarm).services |? {$_.typename -eq “Microsoft SharePoint Foundation Web Application”}

 

foreach($webApp in $contentWebAppServices.WebApplications)
{

ProcesWebApplication -Webapp $webApp;

}

$global:SiteCollInfo | Export-Csv -NoTypeInformation -Path “C:\AllSiteCollectionInfo.csv”

Advertisements