VMware Cloud Community
steelej
Contributor
Contributor
Jump to solution

Power CLI - Progress bar stays on screen

I have a PowerShell scrpt that autmatically creates a new snapshot and then removes all earlier snapshots. It also powere down and powers up the VM.

In all cases bar one the progress bar appears while the operation is taking place and then disappears when the operation completes,

The case where it stays is :

$sn = get-snapshot $machinename

......

remove-snapshot -snapshot £sn[-2] -confirm:$false

The progress bar remains until I terminate the script. This is unfortunate as my script is intended to loop permanently and perform an automated task when a file is placed into a folder.

What can I do to get rid of this progress bar?

Reply
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can try to use the Remove-Snapshot -RunAsync parameter.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
6 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can try to use the Remove-Snapshot -RunAsync parameter.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can hide the progress bar with

$progresspreference = "SilentlyContinue"

before calling the Remove-Snapshot cmdlet.


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

Reply
0 Kudos
steelej
Contributor
Contributor
Jump to solution

Thanks for the suggestion.

Before I try it - how do I then wait for the snaphot to be completed? I am not too experienced with Power CLI but this is the only aspect that has me beaten.

For other parts of my script I can already produce my own progress report using a sleep loop so if I can test that thesnapshot is complete I will be happy.

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can wait for the completion of the removal of the snapshot with:

$sn = get-snapshot $machinename

......

$task = remove-snapshot -snapshot $sn[-2] -confirm:$false -RunAsync

Wait-Task -Task $Task

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
LucD
Leadership
Leadership
Jump to solution

If you want to do this RunAsync method a bit more intellegently and with more parallelism, you can use the method I showed in my About Async tasks, the Get-Task cmdlet and a hash table post.


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

Reply
0 Kudos
steelej
Contributor
Contributor
Jump to solution

Thanks - the -RunAsync and the Wait-task fixed it and had the bonus of putting something meabungful on the progress bar.

I have converted all of my other calls that have the RunAsync parameter but, while these were not persisting after the command was completing, were not showing any progress either.

Since the change po -RunAsync  and woat-task they are still not showing any progress (but I am still testing - each run of my script takes about 10 minutes!).

Reply
0 Kudos