Home > front end >  Powershell - get the output of running a docker command (e.g. docker ps) into a variable
Powershell - get the output of running a docker command (e.g. docker ps) into a variable

Time:09-21

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"
  • Related