Solved

Powershell - how do I.....

Posted on 2013-11-27
2
279 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 100 total points
ID: 39681269
How about something like this.

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

Accepted Solution

by:
Subsun earned 400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
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). …
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.

752 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