Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 641
  • 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
Building an Effective Phishing Protection Program

Join Director of Product Management Todd OBoyle on April 26th as he covers the key elements of a phishing protection program. Whether you’re an old hat at phishing education or considering starting a program -- we'll discuss critical components that should be in any program.

 
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

Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

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