I have a powershell script I use to search for and restore deleted AD user accounts, this is needed more than you would expect because of the nature of the environment so I have decided to make it into a "nice" menu that can be used by allowed users. However, as it is the user displayName is hard coded and I don't want to have others playing with the code so I would like to have it ask them to enter the name. I have been trying to work it out but have gone cross eyed and grey with no luck.
The code, including the already formatted menu, is below (the layout has changed when pasted in but that's cosmetic, not relevant to the question)
$prompt = @"
************************************************************************************************************************
* Please select
from the options below
*
*
*
* s = Search
AD for deleted users
*
* r = Restore
user account
*
* x = exit
*
*
*
************************************************************************************************************************
"@
Clear-host
Do{
$originalcolor = $host.UI.RawUI.ForegroundColor
$host.UI.RawUI.ForegroundColor = "Yellow"
$choice = Read-Host -Prompt $prompt
$host.UI.RawUI.ForegroundColor = $originalcolor
Switch($choice){
s {Get-ADObject -Filter {displayName -eq "Gareth Davies"} -IncludeDeletedObjects}
r {Get-ADObject -Filter {displayName -eq "John Doe"} -IncludeDeletedObjects | Restore-ADObject}
x {break}
default {write-host "Invalid selection, please try again." -ForegroundColor Red}
}
}Until($choice -eq "x")
How can I make it, once the s or r key is pressed, ask the user to enter the name they want to look for or restore?