Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Loops & conditional navigation

$
0
0

I'm trying to create a custom AD user management PowerShell script for both myself and others at my organization to use.

Here is the idea:

#menu"C - Create User""D - Disable User""M - Migrate User""E - Exit"""
$menuAns = Read-Host "Enter Selection"

if ($menuAns -eq "c") {
#createuser
}

elseif ($menuAns -eq "d") {
#disableuser
}

elseif ($menuAns -eq "m") {
#migrateuser}
}

else {exit}

My problem is, having lots of batch file experience, I'm building my flow around the concept of GOTO..

If could mix and match commands between batch and ps1, what I'm trying to do would look like this

#menu
:menu"C - Create User""D - Disable User""M - Migrate User""E - Exit"""
$menuAns = Read-Host "Enter Selection"

if ($menuAns -eq "c") {
#user creation code
}
GOTO menu

elseif ($menuAns -eq "d") {
#user disabling code
}
GOTO menu

elseif ($menuAns -eq "m") {
#user migration code
}
GOTO menu

elseif ($menuAns -eq "e") {GOTO end} #will kill the script

else {GOTO menu} #loops back to beginning if none of the 4 letters were entered

:end

That being said, I know there is no Powershell equivalent to this method, so I would need to use some sort of loop, or something? I will likely need to adjust the structure and flow of my script to accomplish what I'm looking for.. but I don't know what I'm looking for.. any help would be greatly appreciated!

Thank you!


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>