2017-08-04 2 views
0

s'il vous plaît aidez-moi, mon script PowerShell en quelque sorte ne voit pas la valeur correcte et rapporte toujours à l'adresse e-mail même si l'espace est inférieur au seuil.powershell si -gt script ne fonctionne pas correctement résultats toujours au-dessus de la limite

$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

je sais qu'il a quelque chose à voir avec: foldersizeoutput $ Parce que quand j'utilise harddata $ foldersizeouput = 10 .. cela fonctionne – IIIdefconIII

Répondre

2

Vous stockez une chaîne dans $folderSizeOutput

$folderSizeOutput retours par exemple 10 MB au lieu de 10.

Remplacer par:

$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

qui fonctionne bien, mais comment peut je fais ce easieer à lire alors? le code final devrait envoyer quelque chose comme 100 Mo/5000 Mo J'ai modifié l'OP au script complet – IIIdefconIII

+0

Je viens de modifier le code pour afficher la taille du dossier et la taille totale dans la console: '100 Mo/5000 Mo' – Manu

+0

TY jusqu'à présent, mais je reçois la sortie consule ctual Taille = 4174.06918144226 Mo Sous la limite: 4174.06918144226 MB/4500 Mo – 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" 
}