Home Dashboard Directory Help
Search

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


Status: 

Active


5
0
Sign in
to vote
Type: Suggestion
ID: 782841
Opened: 4/2/2013 10:30:32 AM
Access Restriction: Public
0
Workaround(s)
view

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
Details
Sign in to post a comment.
Sign in to post a workaround.