If you inside of a script mount a disk or do other operation that add another disk into system (unlock TrueCrypt protected volume) then you will not be able immediately access it. For example Get-ChildItem -Path X: will not work and you will get an error like you want to access a partition that does not exists.
The issue is related to Windows PowerShell Drives (PSDrive) that were not refreshed yet. You can wait (a bad idea in the script) or you can refresh them immediately after command that mounted drive:
Get-PSDrive | Out-Null
2 responses to “PowerShell Tip – How to immediately access new disk after mount (Mount-VHD, Mount-DiskImage)”
Thanks for this tip – we had problem with mounting image in Azure environment with Azure DSC xMountImage. There was no significant error and we were trying almost everything. This information really helped us.
Thanks so much for this tip. I’ve been banging my head against this for over a day when using DSC xMountImage. Also, I found that waiting for any amount of time did not help, if the drive letter should be changed by xMountImage, the path would sometimes not exist.