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?
You can try to use the Remove-Snapshot -RunAsync parameter.
Regards, Robert
You can try to use the Remove-Snapshot -RunAsync parameter.
Regards, Robert
You can hide the progress bar with
$progresspreference = "SilentlyContinue"
before calling the Remove-Snapshot cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
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
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
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!).