Avatar of BellevueAdmin
BellevueAdmin
 asked on

Powershell - how do I.....

I'm using the following

$prompt = @"
***************************************************
*                                                 *
*    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 "John Doe"} -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")


To search for and restore deleted ADObjects, specifically user accounts.

However, as you can see I want to make this into a menu that can be used by others, and I don't want them playing with the code so I would like to make it ask them to enter the display name rather than it being hard coded in the script.

Does anyone have a way of doing this without making the user have to do more than select the option and type the name?
Microsoft Legacy OSMicrosoft Applications

Avatar of undefined
Last Comment
SubSun

8/22/2022 - Mon
SOLUTION
Joseph Daly

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
SubSun

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck