vendredi 4 août 2017

powershell if -gt script not working correctly results always in above limit

please help me, my powershell script somehow doesnt see the correct value and always reports to the email adress even if the space is less then the threshold.

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

Aucun commentaire:

Enregistrer un commentaire