Hope you can help.
I have a script which essentially is an interactive menu using the switch function. One of the switch options requires a user to enter an integer by using Read-Host function to set a variable which is used later on in that script block. I'd like the integer to be able to change value a few times in one Powershell session.
I'm trying to add some error messages to stop the rest of the script from running if the value is not an integer or below 0. I'm using the below but no matter what, my Read-Host input will always throw the first error. Could someone let me know what I'm doing wrong? Thank you!
'16'{
Write-Host `nThis will export results to a CSV file - Please allow time for the report to run`n -BackgroundColor Black -ForegroundColor Yellow
$InactiveDays = Read-Host "`nEnter How Many Inactive Days To Search By`n"
if ($InactiveDays -isnot [int]) {
Write-Host 'You did not provide a number as input'-BackgroundColor Black -ForegroundColor Red
}
elseif ($InactiveDays -lt 1) {
Write-Host 'Enter a value above 1 as input' -BackgroundColor Black -ForegroundColor Red
}
else
{ *Rest of script } }