2017-08-04 7 views
0

私のPowerShellスクリプトはどういうわけか、正しい値を見ず、スペースがしきい値以下であっても常に電子メールアドレスに報告します。powershell powershell -gtスクリプトが正しく動作しない場合は、常に上限値に設定してください

$PSEmailServer = 'spamtitan.domain.nl' 
$username = [Environment]::UserName 
$folderSizeOutput = "{0:N0}" -f ((Get-ChildItem C:\users\$username -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum/1MB) 
$threshold = "4500" 
$folderSizeOutput 
if ($folderSizeOutput -gt "$threshold"){ 
Send-MailMessage -From "[email protected]" -To "[email protected]" -Subject "ser Profile Disk $username above threshold " -Body "User Profile folder size: $folderSizeOutput/5000 MB" 
} 
else { 
Write-Host "under limit" 
} 
+0

私はそれがに何か持って知っている: $ foldersizeoutput 原因を私はharddata $ foldersizeouput = 10、それは動作します...実際にどのようにすることができます動作します – IIIdefconIII

答えて

2

あなたは一例10 MB代わりに10ため$folderSizeOutput

$folderSizeOutputリターンの文字列を格納します。で

置き換えます

$username = [Environment]::UserName 
$folderSizeOutput = [math]::round((Get-ChildItem C:\users\$username -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum/1MB) 
$threshold = 4500 
Write-Host "Actual Size = $folderSizeOutput MB" 
$stringSizes = "$folderSizeOutput MB/$threshold MB" 
if ($folderSizeOutput -gt $threshold){ 
    Write-Host "Above limit : $stringSizes" 
} 
else { 
    Write-Host "Under limit : $stringSizes" 
} 
+0

使用する場合私はこのイージーエイジャーに読ませますか? 最終的なコードは100MB/5000MBのようなものを送ってください私は完全なスクリプトにOPを編集しました – IIIdefconIII

+0

コンソールのフォルダサイズと合計サイズをこのように表示するコードを編集しました: '100 MB/5000 MB' – Manu

+0

TY今まではコンスル出力を得ていました ctualサイズ= 4174.06918144226 MB 制限値:4174.06918144226 MB/4500MB – IIIdefconIII

0
$PSEmailServer = 'spamtitan.domain.nl' 
$username = [Environment]::UserName 
$folderSizeOutput = [math]::round((Get-ChildItem C:\users\$username -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum/1MB) 
$threshold = 4500 
$maxhold = 5000 
Write-Host "Actual Size = $folderSizeOutput MB" 
$stringSizes = "$folderSizeOutput MB/$maxhold MB" 
if ($folderSizeOutput -gt $threshold){ 
Send-MailMessage -From "[email protected]" -To "[email protected]" -Subject "User Profile Disk $username $StringSizes " -Body "User Profile folder above $threshold MB : $StringSizes" 
} 
else { 
    Write-Host "Under limit : $stringSizes" 
} 
関連する問題