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
LVL 2
HankinaterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.