Solved

Make User Choose from Output

Posted on 2013-01-31
3
253 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article will help you understand what HashTables are and how to use them in PowerShell.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

15 Experts available now in Live!

Get 1:1 Help Now