Solved

Powershell - how do I.....

Posted on 2013-11-27
2
270 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
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

803 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