I'm trying to use PowerShell to check if a user-provided position number exists. I want to loop this until the user provides a valid position. I am fairly new to PowerShell and I don't understand why it's not working...
#Start Store and Check Budget Position Number User Template#
Clear-Host
Do{
Try{
# Find the user template
$budgetpositionnumber = Read-Host "
What budget position number is the user filling?
"
Write-Host "
You entered budget position number: $budgetpositionnumber
"
# Find the position on Your.Domain
Get-ADuser $budgetpositionnumber
}
Catch{
Write-Host ("Failed to find position number " + $budgetpositionnumber) -ForegroundColor Red -ErrorAction Stop
}
} Until ($budgetpositionnumber -ne $Null)
#End Store and Check Budget Position Number Template#
Even if I enter invalid data, it still continues with the rest of the script. I want it to stop or loop until its' a vaild position number.
##Edited for clarity