Publish Sharepoint 2010 Site Collection Report

Hi Readers,

The script that I am sharing today is used for publishing the site owners & site quota report for shrepoint 2010 farm.

This script has been created by our team for helping the l1 & l2 teams to check the owners/ quotas of sharepoint sites.

There are few variables that needs to be defined first before executing it.

Webapp names, document library to which the report will be published, site url.

Below is the report how it looks like (I have created a hyper link based on the webapp in our farm)

Create a scripts folder & place the script inside it , also create an empty folder name output inside the scripts folder.

We have created a batch file to execute & schedule the script (below is the content of batch)

powershell .\Site-owner-quota-report.ps1

pause

Create a SP site & create a document library ( I have created it with name Site List)

Script can also be downloaded from below location (if you are facing issues in copy/paste)

https://github.com/VikasSukhija/Downloads/blob/master/Site-Owner-Quota-report.ps1

Hyperlink on webpage of site

After clicking the link below report will be visible.

########################################################################################## 
#             Authors: Vikas Sukhija,Mahesh Sharma 
#             Date: 05/28/2013 
#             Description: Script to Output SharePoint Site Owner & Quota information 
#                          Output file will then be uploaded to specified SharePoint Site  
########################################################################################## 

# Define sharepoint webapp for your Fram (I had two in my farm so defined two webapps) 

$webapp1 = "http://team.xxxxxxxx.com" 
$webapp2 = "http://sp.xxxxxxxxx.com" 

$output1 =  ".\" + "\" + "output" + "\" + "team.html" 
$output2 =   ".\" + "\" + "output" + "\" + "sp.html" 

# Define the site url & doc library to which this report will be published 

$siteurl = "http://team.xxxxxxxx.com/sites/SPDir" 
$docLibraryName = "Site List"    

#----ADD Sharepoint Shell------- 

If ((Get-PSSnapin | where {$_.Name -match "SharePoint.Powershell"}) -eq $null) 
{ 
    Add-PSSnapin Microsoft.SharePoint.Powershell 
} 

# All HTML formatting in a single variable to be used with ConvertTo-HTML cmdlet 

$HTMLFormat = "<!--mce:0-->" 

#Get specified WebApplication --->> Get All sites from specified WebApplication --->> Select URL, Owners & Quo9ta for each site  
#--->> Format output in HTML & save to HTML file 

# repeat the code for each web app that you have in the farm 

Get-SPWebApplication $webapp1 | Get-SPSite -Limit All | Select URL, Owner, SecondaryContact,  
@{Name="Used Storage"; Expression={"{0:N2} MB" -f ($_.Usage.Storage/1048576)}},  
@{Name="Storage Quota"; Expression={"{0:N2} MB" -f ($_.Quota.StorageMaximumLevel/1048576)}} |  
ConvertTo-HTML -Head $HTMLFormat  -Body "<H2><Font Size = 4,Color = DarkCyan>SharePoint Farm Site List</Font></H2>" -AS Table |  
Set-Content $output1 

# repeated code 

Get-SPWebApplication $webapp2 | Get-SPSite -Limit All | Select URL, Owner, SecondaryContact,  
@{Name="Used Storage"; Expression={"{0:N2} MB" -f ($_.Usage.Storage/1048576)}},  
@{Name="Storage Quota"; Expression={"{0:N2} MB" -f ($_.Quota.StorageMaximumLevel/1048576)}} |  
ConvertTo-HTML -Head $HTMLFormat  -Body "<H2><Font Size = 4,Color = DarkCyan>SharePoint Farm Site List</Font></H2>" -AS Table |  
Set-Content $output2 

#Below code will upload the output HTML file to specified SharePoint site 
#It will overwrite any existing file with same name 

$spWeb = Get-SPWeb $siteurl                             
$localFolderPath = ".\output"                       
$docLibrary = $spWeb.Lists[$docLibraryName]    

$files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()  

$files | ForEach-Object {   

          $fileStream = ([System.IO.FileInfo] (Get-Item $_.FullName)).OpenRead()   

                $contents = new-object byte[] $fileStream.Length   

                $fileStream.Read($contents, 0, [int]$fileStream.Length);   

               $fileStream.Close();   

                $folder = $docLibrary.RootFolder   

                $spFile = $folder.Files.Add($folder.Url + "/" + $_.Name, $contents, $true)   

                $spItem = $spFile.Item   

                        }  

##################################################################################################################

Regards
Sukhija Vikas

Leave a comment