1. 加載Add-PSSnapin模塊
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
2. 获取网站存储信息
#$root_path = Split-Path -Parent $MyInvocation.MyCommand.Definition
$webapps = Get-SPWebApplication | select Url
$calc_storage = New-Object -TypeName System.Collections.ArrayList
if($webapps.Count -ge 1){
foreach($webapp in $webapps){
$res = Get-SPWebApplication $webapp.Url | Get-SPSiteAdministration -Limit All |Select-Object title,url,@{n='hd_used';e={'{0:0}' -f ($_.DiskUsed/1024/1024)}},@{n='hd_total';e={$_.quota.StorageMaximumLevel/1024/1024}},@{n='hd_usage';e={if($_.quota.StorageMaximumLevel -ne 0){'{0:p0}' -f ($_.DiskUsed/$_.quota.StorageMaximumLevel)}else{"0"}}}
$null = $calc_storage.add(@{
webapp=$webapp.Url;
siteinfo=$res
})
}
}else{
Write-Warning "Not found webapplication, please check and retry!!!"
}
write-host ($calc_storage |convertto-json -dept 99)
3. 打印返回结果, 单位MB
[
{
"webapp": "http://bj-mossap01/",
"siteinfo": [
{
"Title": "bj MOSS",
"Url": "http://bj-mossap01",
"hd_used": "2",
"hd_total": 0,
"hd_usage": "0"
},
{
"Title": "SM-SMTEST11",
"Url": "http://sm-test11",
"hd_used": "4",
"hd_total": 4096,
"hd_usage": "0%"
}
]
},
{
"webapp": "http://bj-s001:100/",
"siteinfo": {
"Title": "爱上对方过后就哭了",
"Url": "http://bj-masd:88",
"hd_used": "26308",
"hd_total": 40960,
"hd_usage": "64%"
}
}
]