Output of execution through Show-Command should follow normal output rules and be capturable
Matthew Reynolds [MSFT]
4/2/2013 10:30:32 AM
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