Friday, November 6, 2015

Sharepoint PowerShell List of all site collections in Web Application

$xl=New-Object -ComObject "Excel.Application"
$xl.Visible=$True
$xl.Workbooks.Add()
$ws=$xl.ActiveWorkbook.ActiveSheet
$cells=$ws.Cells
$i = 1
$sites = Get-SPSite -Limit All -WebApplication http://pc362/
foreach ($site in $sites)
{
 $cells.item($i,1)= invoke-command { $site.URL }
 $cells.item($i,2)= invoke-command { $site.Owner.UserLogin }
 $cells.item($i,3)= invoke-command { $site.SecondaryContact.UserLogin }
 $cells.item($i,4)= invoke-command { $site.WebApplication.DisplayName }
 $cells.item($i,5)= invoke-command { $site.Usage.Storage/1MB }
 $cells.item($i,6)= invoke-command { $site.ContentDatabase.Name }
 $cells.item($i,7)= invoke-command { $site.Quota.Storagemaximumlevel }
 $cells.item($i,8)= invoke-command { $site.RootWeb.SiteUsers.Count }
 $cells.item($i,9)= invoke-command { $site.Usage.Hits }
 $cells.item($i,10)= invoke-command { $site.Usage.Bandwidth }
 $i++
}

Or

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
#Configure the location for the output file
$Output="C:\Output.csv";
"Site URL"+","+"Owner Login"+","+"SecondaryContact Login"+","+"WebApplication DisplayName"+","+"Quota Limit (MB)"+","+"Total Storage Used (MB)"+","+"Site Quota Percentage Used"+","+"ContentDatabase"+","+"SiteUsers"+","+"UsageHits"+","+"UsageBandwidth" | Out-File -Encoding Default -FilePath $Output;
#Specify the root site collection within the Web app
$Siteurl="https://your web application";
$Rootweb=New-Object Microsoft.Sharepoint.Spsite($Siteurl);
$Webapp=$Rootweb.Webapplication;
#Loops through each site collection within the Web app, if the owner has an e-mail address this is written to the output file
Foreach ($Site in $Webapp.Sites)
{if ($Site.Quota.Storagemaximumlevel -gt 0) {[int]$MaxStorage=$Site.Quota.StorageMaximumLevel /1MB} else {$MaxStorage="0"};
if ($Site.Usage.Storage -gt 0) {[int]$StorageUsed=$Site.Usage.Storage /1MB};
if ($Storageused-gt 0 -and $Maxstorage-gt 0){[int]$SiteQuotaUsed=$Storageused/$Maxstorage* 100} else {$SiteQuotaUsed="0"};
$Web=$Site.Rootweb; $Site.Url + "," + $Site.Owner.UserLogin + "," + $Site.SecondaryContact.UserLogin + "," +$Site.WebApplication.DisplayName + "," +$MaxStorage+","+$StorageUsed + "," + $SiteQuotaUsed+ "," + $Site.ContentDatabase.Name+ "," + $Site.RootWeb.SiteUsers.Count+ "," + $Site.Usage.Hits+ "," + $Site.Usage.Bandwidth | Out-File -Encoding Default -Append -FilePath $Output;$Site.Dispose()};

0 comments:

Post a Comment