• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

SharePoint 2010 and PowerShell

Hey Experts,

I have a script that I use to pull down site collection storage statistics as follows:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
#Specify the root site collection within the Web app
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
$webapps = @()
foreach ($websvc in $websvcs) {
    foreach ($webapp in $websvc.WebApplications) {
        $webapps = $webapps + $webapp
    }
}
$webapps2 = $webapps | Select -ExpandProperty Sites |  WHere {$_.url -notlike '*/sites/*' -and $_.url -notlike '*USHDC2880*' -and $_.url -notlike '*dforums*' -and $_.url -notlike '*ecp*' -and $_.url -notlike '*scp*'} |select url
$webappUrl = $webapps2 | Select Url 
Foreach ($Siteurl in $webappUrl){
$FileName = $Siteurl.url -replace "https://","" -replace "http://",""
$Output="E:\Orchestrator\SCStorageStats\CSV\"+$FileName +".csv";
"Site URL"+","+"Quota Limit (MB)"+","+"Total Storage Used (MB)"+","+"Site Quota Percentage Used" | Out-File -Encoding Default -FilePath $Output;
$Rootweb=New-Object Microsoft.Sharepoint.Spsite($Siteurl.url);
$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){$SiteQuotaUsed=[int]$Storageused/[int]$Maxstorage* 100} else {$SiteQuotaUsed="0"}; 
$Web=$Site.Rootweb; $Site.Url + ","  +$MaxStorage +","+$StorageUsed + "," + $SiteQuotaUsed |  Out-File -Encoding Default -Append -FilePath $Output;$Site.Dispose()};
Import-CSV $Output | ConvertTo-HTML | Out-File -FilePath E:\Orchestrator\SCStorageStats\HTML\$FileName.htm
}

Open in new window


It brings back the information without issue.  However when I use the following script to consolidate the information and target site collections that have consumed more than 90%, it will only bring back results from 91-100 percent.  And there are some that have exceeded their quota.

Set-Location E:\Orchestrator\SCStorageStats\CSV
$File = "AllSCs.csv"
"Site URL"+","+"Quota Limit (MB)"+","+"Total Storage Used (MB)"+","+"Site Quota Percentage Used" | Out-File -Encoding Default -FilePath $File;
Get-Content *.csv | Where {$_ -notlike "*Site Url*"} |  Out-File -Encoding Default -Append -FilePath $File
Import-CSV $File | Where {$_."Site Quota Percentage Used" -gt [int]90} | ConvertTo-HTML | Out-File -FilePath E:\Orchestrator\SCStorageStats\HTML\QuotaAtRisk.htm

Open in new window


There is something I'm missing and I can't figure out what it is!

Thanks in advance!

Hank
0
Hankinater
Asked:
Hankinater
1 Solution
 
HankinaterAuthor Commented:
If I change the Where statement in the second script as follows, it works:

Import-CSV $File | Where {[int]$_."Site Quota Percentage Used" -gt [int]90} | ConvertTo-HTML | Out-File -FilePath E:\Orchestrator\SCStorageStats\HTML\QuotaAtRisk.htm

Open in new window


Note the leading "[int]"
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now