Solved

PowerShell and inline Read-Host

Posted on 2013-01-22
6
496 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 28

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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 68

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

18 Experts available now in Live!

Get 1:1 Help Now