mercredi 4 septembre 2019

If Statement based on a number stored in a Variable

First of all, I am fairly to Powershell.

Problem: I have been tasked with making a script to check how many files are in a specific file location. If this number is greater than a set value gives an error message. If the number is less than the set value gives a processing error message.

I am using the following to get the file count and store it in as $var $var = (powershell.exe -command Write-Host (Get-ChildItem c:\filepath | Measure-Object ).Count)

I have then tried using an IF statement to give the required error message. if ($var -lt 100) {'Processing'} Elseif ($var -gt 100) {'Error: File Limit Reached'}

$var = (powershell.exe -command Write-Host (Get-ChildItem c:\filepath | Measure-Object ).Count) if ($var -lt 100) {'Processing'} Elseif ($var -gt 100) {'Error: File Limit Reached'}

I need the script to recognize the $var number provided by the Measure-Object and give the correct message based on the current value.

Aucun commentaire:

Enregistrer un commentaire