Solved

Powershell - how do I.....

Posted on 2013-11-27
2
262 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
2 Comments
 
LVL 35

Assisted Solution

by:Joseph Daly
Joseph Daly earned 100 total points
Comment Utility
How about something like this.

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

Accepted Solution

by:
Subsun earned 400 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now