VMware Cloud Community
ShyamBanala
Contributor
Contributor

Is there any way to capture the output of Remove-Vm. For example when I issue "Remove-VM -VM vm1 -DeletePermanently -confirm:$false", it displays the progress but there is no persistence of the output.

Is there any way to capture the output of Remove-Vm. For example when I issue "Remove-VM -VM vm1 -DeletePermanently -confirm:$false", it displays the progress but there is no persistence of the output.

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

There is no number for the progress stream, so you can not redirect it in classical way.

You can use the System.Management.Automation.PowerShell class to run your code.

Something like this

$code = @'

1..10 | %{

    Write-Progress -Activity 'Test stream' -Status "Counter $_" -PercentComplete ($_*10)

    sleep 1

}

'@

$ps = [System.Management.Automation.PowerShell]::Create()

$ps.AddScript($code,$false)

$ps.Invoke()


$ps.Streams.Progress


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos