Inject files into offline VHD with PowerShell


You can inject files info an offline VHD using those few lines :

$MountedDisk = Mount-VHD -Path "MyVhdx.vhdx" -Passthru
[String]$DriveLetter = ($MountedDisk | Get-Disk | Get-Partition | ? {$_.Type -eq "Basic"} | Select-Object -ExpandProperty DriveLetter) + ":"
$DriveLetter = $DriveLetter.Replace(' ','')
Start-Sleep -Seconds 2 #Optional
Get-PSDrive | Out-Null #refresh PsDrive, Optional
New-Item -Path "$DriveLetterSources" -ItemType Directory | Out-Null
Copy-Item -Path "MyScript.cmd" -Destination "$DriveLettersourcesrun.cmd" -Force
Start-Sleep -Seconds 2 #Optional
Dismount-VHD $MountedDisk.Path

With thse fex lines, you can deploy/update logonscripts, or deploy new features massively on your VHD library.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.