-1

I have a directory with hundreds of Hard Disk Image Files (.vhdx) - each containing user profile directory (C:\Users\xxx). When I click on a file using File Explorer, it is automatically mounted and I can access files inside. I have an issue with recreating the same with a command.

I do not know what is the username with given SID - I just need to modify a single file in each profile.

Example file: E:\profiles\UVHD-S-1-5-21-1614895754-1035525444-839522115-21214.vhdx

I've tried to use net use, dism and subst however I couldn't get any of those to work.

Artur Rychlewicz
  • 495
  • 6
  • 16

2 Answers2

3

net use is for mapping SMB shares, dism is for working with .wim images, subst is for mapping local paths to drive letters. Neither of them is suitable for working with VHD(X) files. Or claims to be, for that matter.

In more recent Windows versions (starting with Windows 8 IIRC) you have cmdlets like Mount-DiskImage or Mount-VHD for working with Hyper-V virtual harddisks. On Windows 7 you need to use diskpart.exe.

Attach a virtual harddisk:

@'
select vdisk file="C:\path\to\your.vhdx"
attach vdisk
'@ | diskpart

Detach a virtual harddisk:

@'
select vdisk file="C:\path\to\your.vhdx"
detach vdisk
'@ | diskpart
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
1

You may be able to use New-PSDrive to manage this (although I do not have an ISO to test with):

New-PSDrive -PSProvider 'FileSystem' -Root 'path\to\container.vhdx' -Name 'vhd'

You can then access it like so:

Set-Location 'vdh:\Users\etc'

Edit:

Turns out there's an entire suite of commands to interact with Hyper-V. I'd recommend looking into this article and then look through these commands

There is a Mount-VHD cmdlet designed for exactly what you're trying to do.

Note: these commands appear to be limited to Windows Server 2012+ and Windows 8+

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63