PowerShell script exchange
Post Reply
futureal
Lurker
Posts: 1
Liked: never
Joined: Aug 23, 2021 1:00 am
Contact:

Wait command not waiting

Post by futureal »

Hi.

We've recently added a second tape job to our weekly backups. For all our full backups, we have a pre-script where we erase and inventory the tape:

Code: Select all

Add-PSSnapin VeeamPSSnapin
Start-VBRTapeInventory -Medium $TapeName -wait
if ($TapeName) { Erase-VBRTapeMedium –Medium $TapeName -Wait }
The problem we have now is if the first tape job is still running, the second one's inventory and erase command gives the error 'Unable to perform Tape inventory for library HP MSL G3 Series 7.10: cannot lock tape drive' and skips past the commands straight onto the backup job (which runs once the first tape job is finished). Is there any way to pause the prescript until the drive is free?

Cheers
soncscy
Veteran
Posts: 643
Liked: 312 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey
Contact:

Re: Wait command not waiting

Post by soncscy » 2 people like this post

Hey futureal,

-Wait only tells Powershell to wait for the command you attach the parameter to; it doesn't wait for other processes :)

That is, for your above script, -Wait would tell powershell (in plan language) "Don't do anything else in the script until this command completes."

What you will want to do is write a logic in your script to look for the alternate job and see if it's running. The $_.LatestState property can help likely with determining this, but it should be __stopped__ in most cases. If it's not, you might just assume it's still running.

If you want to be a bit more complex, you can try to write a "Try/Catch" statement for your script and write a handling to wait N minutes if the lock fails.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests