Output of execution through Show-Command should follow normal output rules and be capturable - by Matthew Reynolds [MSFT]

Status : 

 


6
0
Sign in
to vote
ID 782841 Comments
Status Active Workarounds
Type Suggestion Repros 0
Opened 4/2/2013 10:30:32 AM
Access Restriction Public

Description

In PSv3 Show-Command by default causes the targeted command to execute, but the output is not sent to the normal output pipeline nor can it be captured. This limits the usefulness of Show Command as a tool to let users fill in parameters for tasks. See below.

# my expected behavior would be that $myItemChosenByUser should be a fileinfo as
# returned by Get-Item.
# It is not. Instead the formatted fileinfo seems to go straight to the console
# bypassing all normal powershell output convention. Meanwhile
# $myItemChosenByUser is null
$myItemChosenByUser = Show-COmmand -Name Get-Item #in the show-command window specify a file that exists
# at this point a formatted fileinfo appears in the console instead of being captured in variable.
$myItemChosenByUser.gettype() # fails as $myItemChosenByUser is null

# You can work around this using -Passthru & Invoke-Expression, but this makes people
# sad since Invoke-Expression in considered dangerous.
$myCommand = Show-COmmand -Name Get-Item -Passthru #in the show-command window specify a file that exists
$myItemChosenByUser = Invoke-Expression $mycommand
$myItemChosenByUser.gettype() # Now $myItemChosenByUser is a fileinfo, but I had to go through Invoke-Expression to get there
Sign in to post a comment.