0

I'm trying to create a backup script that unlocks an external bitlocker drive, robocopies files to it, then locks it when it's done. I am able to unlock and copy just fine, but the final step of "Lock-Bitlocker" is giving me an "access denied" error because the drive is still in use (e.g. the robocopy is still wrapping up).

Unlock-Bitlocker e: -Password (ConvertTo-SecureString "omgClearText" -AsPlainText -Force)
Robocopy "\\MyFileServer\C$\Files" "E:\" /Bunch /of /parameters
Lock-Bitlocker e:

I've tried using Wait-Job to wait for Robocopy to complete, but that doesn't work. I've considered Lock-Bitlocker E: -ForceDismount but I don't want to dismount until after all files have successfully copied over.

Is there a way to properly wait for the system to copy before locking?

0

I tested this and could reproduce this problem. What solved it for me was to insert

timeout 5

before the line with the lock command.

1
  • Oh my... After analyzing further, it seems it's not about wait time AT ALL. You will just need to add another line lock-bitlocker e: and that's all! – Bernd Schwanenmeister Dec 21 '19 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.