Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell - how do I.....

Posted on 2013-11-27
2
Medium Priority
?
289 Views
Last Modified: 2013-11-27
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?
0
Comment
Question by:BellevueAdmin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Assisted Solution

by:Joseph Daly
Joseph Daly earned 400 total points
ID: 39681269
How about something like this.

$information = read-host "Enter some information here."
0
 
LVL 40

Accepted Solution

by:
Subsun earned 1600 total points
ID: 39681347
Try this.. After selecting the choice they will be prompted to enter the Displayname of the user to search/restore.
$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 {
	  $search = Read-Host "Type DisplayName of user and press Enter to search"
	  Get-ADObject -Filter {displayName -eq $search} -IncludeDeletedObjects
	  }
        r {
	   $restore = Read-Host "Type DisplayName of user and press Enter to restore"
	   Get-ADObject -Filter {displayName -eq $restore} -IncludeDeletedObjects | Restore-ADObject
	   }
         x {break}
         default {write-host "Invalid selection, please try again." -ForegroundColor Red}
      }
}Until($choice -eq "x")

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question