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

PowerShell and inline Read-Host

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
Kasper Katzmann
Asked:
Kasper Katzmann
1 Solution
 
becraigCommented:
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
 
SubsunCommented:
You can try..
read-host "User" | get-aduser

or

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

Open in new window

0
 
Kasper KatzmannSeniorkonsulentAuthor Commented:
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
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
SubsunCommented:
$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
 
Kasper KatzmannSeniorkonsulentAuthor Commented:
Exactly
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

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