powershell if -gt 脚本不能正常工作导致总是超出限制
powershell if -gt script not working correctly results always in above limit
请帮助我,我的 powershell 脚本不知何故看不到正确的值,并且总是向电子邮件地址报告,即使 space 小于阈值也是如此。
$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 "spamtitan@domain.nl" -To "reporting@domain.nl" -Subject "ser Profile Disk $username above threshold " -Body "User Profile folder size: $folderSizeOutput / 5000 MB"
}
else {
Write-Host "under limit"
}
您在 $folderSizeOutput
中存储了一个字符串
$folderSizeOutput
returns 例如 10 MB
而不是 10
.
替换为:
$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"
}
$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 "alerts@domain.nl" -To "reporting@domain.nl" -Subject "User Profile Disk $username $StringSizes " -Body "User Profile folder above $threshold MB : $StringSizes"
}
else {
Write-Host "Under limit : $stringSizes"
}
请帮助我,我的 powershell 脚本不知何故看不到正确的值,并且总是向电子邮件地址报告,即使 space 小于阈值也是如此。
$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 "spamtitan@domain.nl" -To "reporting@domain.nl" -Subject "ser Profile Disk $username above threshold " -Body "User Profile folder size: $folderSizeOutput / 5000 MB"
}
else {
Write-Host "under limit"
}
您在 $folderSizeOutput
$folderSizeOutput
returns 例如 10 MB
而不是 10
.
替换为:
$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"
}
$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 "alerts@domain.nl" -To "reporting@domain.nl" -Subject "User Profile Disk $username $StringSizes " -Body "User Profile folder above $threshold MB : $StringSizes"
}
else {
Write-Host "Under limit : $stringSizes"
}