Solved

PowerShell and inline Read-Host

Posted on 2013-01-22
6
508 Views
Last Modified: 2013-01-22
Just a little thought... Is it possible to a Read-Host in the same line as ie. Get-ADUser?
Something like this:
$inp = read-host "User" | get-aduser $inp

Open in new window

I know the abowe isn't possible, but is there another way to keep it all in the same line?

Regards
Kasper
0
Comment
Question by:Kasper Katzmann
6 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 38805392
easy enough just want you have w/o a pipe

$inp = read-host "User"
get-aduser $inp

do it at the command line or in a script.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38805400
You can try..
read-host "User" | get-aduser

or

$inp = read-host "User" | get-aduser

Open in new window

0
 

Author Comment

by:Kasper Katzmann
ID: 38805456
This one works:
read-host "User" | get-aduser

Open in new window

This one doesn't return anything:
$inp = read-host "User" get-aduser $inp

Open in new window

0
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.

 
LVL 40

Expert Comment

by:Subsun
ID: 38805471
$inp = read-host "User" get-aduser $inp will not work..

$inp = read-host "User" | get-aduser will work. It will not return anything because the result is saved in var $inp

If you run $inp , then you will get the saved value..
0
 

Author Comment

by:Kasper Katzmann
ID: 38805504
Exactly
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 38805647
To complete the answer:
 $inp = read-host "User" | get-aduser
is the same as
 $inp = (read-host "User" | get-aduser)
and not
 ($inp = read-host "User") | get-aduser

Another way to execute is
 get-aduser (read-host "User")
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

776 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