PowerCLI

 View Only
  • 1.  Power CLI - Progress bar stays on screen

    Posted Jul 19, 2011 08:05 AM

    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?



  • 2.  RE: Power CLI - Progress bar stays on screen
    Best Answer

    Posted Jul 19, 2011 08:14 AM

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

    Regards, Robert



  • 3.  RE: Power CLI - Progress bar stays on screen

    Posted Jul 19, 2011 09:54 AM

    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.



  • 4.  RE: Power CLI - Progress bar stays on screen

    Posted Jul 19, 2011 10:07 AM

    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



  • 5.  RE: Power CLI - Progress bar stays on screen

    Posted Jul 19, 2011 11:02 AM

    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!).



  • 6.  RE: Power CLI - Progress bar stays on screen

    Posted Jul 19, 2011 10:45 AM

    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.



  • 7.  RE: Power CLI - Progress bar stays on screen

    Posted Jul 19, 2011 08:24 AM

    You can hide the progress bar with

    $progresspreference = "SilentlyContinue"

    before calling the Remove-Snapshot cmdlet.