PowerShell Tip – How to immediately access new disk after mount (Mount-VHD, Mount-DiskImage)


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)”

  1. 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.

  2. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Active Directory Advanced function AlwaysOn Availability Groups AlwaysOn Failover Cluster Instances Building Cloud Cloud Cluster Cmdlet Database Deployment Design DFS Domain Controller DSC Fabric Failover Clustering File Server Group Policy Hardware Profile Host Hyper-V Installation Library Library Asset Library Server Network Operations Manager Orchestrator PowerShell PowerShell User Group PowerShell Workflow Security Service Manager SQL Server Storage System Center Template Time Time Synchronization Tips Virtual Machine Virtual Machine Manager VM Network VM Template Windows Server 2012 R2