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
Solved

Make User Choose from Output

Posted on 2013-01-31
3
258 Views
Last Modified: 2013-01-31
I have this script:

# Technical Documentation Here: http://www.netsupportsoftware.com/Support/kb/asp/kbprovider.asp?gettd=298&lang=EN&xsl=http%3A//www.netsupportsoftware.com/Support/kb/TechDoc.xsl
Add-PSSnapin Quest.ActiveRoles.ADManagement

$User= read-host "What is the firstname,last name, or Username of the user?"
$ComputerName = Get-QADComputer -ManagedBy (Get-QADUser $User)
$Computer=$Computer.Name


while ((Test-Connection -Quiet -ComputerName $Computer) -eq $False) {Test-Connection -Quiet -ComputerName $Computer}

if ((Test-Connection -Quiet -ComputerName $Computer) -eq $True) {
& 'C:\Program Files (x86)\NetSupport\NetSupport Manager\PCICTLUI.EXE' /C"$Computer" /vw /e
}

pause

Open in new window


It prompts for a username and searches AD for that username. It then returns a list of computers.

If only a single computer is returned, it will ping that computer and start a remote connection to that computer. If the computer is off, it will continue to ping until it is turned on.

When multiple computers are returned, I get a lot of errors because of the $Computer variable. How can I prompt the user to choose between the list computers and then input their choice into the $Computer variable?
0
Comment
Question by:Joseph Moody
3 Comments
 
LVL 16

Assisted Solution

by:Rajitha Chimmani
Rajitha Chimmani earned 50 total points
ID: 38840420
You may try adding a foreach loop irrespective of single or multiple computers...something like this

# Technical Documentation Here: http://www.netsupportsoftware.com/Support/kb/asp/kbprovider.asp?gettd=298&lang=EN&xsl=http%3A//www.netsupportsoftware.com/Support/kb/TechDoc.xsl
Add-PSSnapin Quest.ActiveRoles.ADManagement

$User= read-host "What is the firstname,last name, or Username of the user?"
$Computers = Get-QADComputer -ManagedBy (Get-QADUser $User)

foreach($Computer in $Computers){
$ComputerName = $Computer.Name
while ((Test-Connection -Quiet -ComputerName $ComputerName) -eq $False) {Test-Connection -Quiet -ComputerName $ComputerName}

if ((Test-Connection -Quiet -ComputerName $ComputerName) -eq $True) {
& 'C:\Program Files (x86)\NetSupport\NetSupport Manager\PCICTLUI.EXE' /C"$ComputerName" /vw /e
}
}

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 450 total points
ID: 38840435
Try
# Technical Documentation Here: http://www.netsupportsoftware.com/Support/kb/asp/kbprovider.asp?gettd=298&lang=EN&xsl=http%3A//www.netsupportsoftware.com/Support/kb/TechDoc.xsl
Add-PSSnapin Quest.ActiveRoles.ADManagement

Function Run-PCICTLUI
{
while ((Test-Connection -Quiet -ComputerName $Computer) -eq $False) {Test-Connection -Quiet -ComputerName $Computer}

if ((Test-Connection -Quiet -ComputerName $Computer) -eq $True) {
& 'C:\Program Files (x86)\NetSupport\NetSupport Manager\PCICTLUI.EXE' /C"$Computer" /vw /e
}

pause
}

$User= read-host "What is the firstname,last name, or Username of the user?"
$ComputerName = Get-QADComputer -ManagedBy (Get-QADUser $User)

If (($ComputerName | Measure-Object).Count -gt 1){
$ComputerName | Select Name
$Computer = read-host "Type the correct Computer Name from list"
Run-PCICTLUI
}
Else{
$Computer = $ComputerName.name
Run-PCICTLUI
}

Open in new window

0
 
LVL 22

Author Closing Comment

by:Joseph Moody
ID: 38840455
Thank you! I learn so much from you guys!
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Set OWA language and time zone in Exchange for individuals, all users or per database.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

840 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