Solved

PowerShell and inline Read-Host

Posted on 2013-01-22
6
527 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Job running powershell script 2 32
Save Exchange PowerShell Command 12 38
Remote Powershell Issue 3 34
Move files based on file names? 8 31
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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