Highlighted
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.

0 Kudos
1 Reply
Highlighted
User Moderator
User Moderator

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

0 Kudos