What is the best way, to make a loop in powershell? including powershell Switch, So that every time you finish, you will return to the Switch to be rerun example:
$list_of_scripts=Read-Host "welcome to AD tool :) select: 1: new user 2: new OU Switch ($list_of_scripts){
1 { $name=Read-Host "enter the user name" New-ADUser -Name $name -Accountpassword (Read-Host -AsSecureString "AccountPassword") -Enabled $true -PasswordNeverExpires $true }
2 {$username=Read-Host "Enter OU name" New-ADOrganizationalUnit -name $username -Path "DC=slipknot,DC=main" -ProtectedFromAccidentalDeletion $False}}
what i tried:
$list_of_scripts = $scripts foreach ($script in $scripts) {
"welcome to AD tool :) select: 1: new user 2: new OU"
Switch ($list_of_scripts)
$script=1 {$name=Read-Host "enter the user name" New-ADUser -Name $name -Accountpassword (Read-Host -AsSecureString "AccountPassword") -Enabled $true -PasswordNeverExpires $true}
$script=2 {$username=Read-Host "Enter OU name" New-ADOrganizationalUnit -name $username -Path "DC=slipknot,DC=main"}}}
CRTL+J and Shift+CRTL+Spacebarto see a snippet sample for you to refactor. Yet, you seem to be asking to build a menu that allows a user to supply data, complete a task and come back to the beginning menu. You can do this using Out-GridView as a GUI, with proper calls to the code nodes. It would be the same approach in any MenuApp and its code behind language. I've posted examples in the locations if you can to see them, you can reach me via the stackoverflow chat feature.