• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Make User Choose from Output

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
Joseph Moody
Asked:
Joseph Moody
2 Solutions
 
Rajitha ChimmaniCommented:
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
 
SubsunCommented:
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
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Thank you! I learn so much from you guys!
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now