The requirement is to record the output of a docker command into a variable. Failed attempt:
$var = docker ps | Receive-Output
Write-Output $var
How would one go about recording the output of the command into a variable?
CodePudding user response:
You can use Invoke-Expression
. The Invoke-Expression
cmdlet evaluates or runs a specified string as a command and returns the results of the expression or command.
$var = Invoke-Expression "docker ps"