From cd98f51860a1491a408efad65d82287ef637561c Mon Sep 17 00:00:00 2001 From: James Stringer <38541878+jamesstringerparsec@users.noreply.github.com> Date: Wed, 23 Jun 2021 13:12:12 +0200 Subject: [PATCH] Auto mount / dismount the disk --- CopyFilesToVM.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CopyFilesToVM.ps1 b/CopyFilesToVM.ps1 index 65b8611..8cfee20 100644 --- a/CopyFilesToVM.ps1 +++ b/CopyFilesToVM.ps1 @@ -1,5 +1,11 @@ -$hostname = $ENV:COMPUTERNAME -$DriveLetter = "F:" +$VMname = "VM Name HERE" +$hostname = $ENV:COMPUTERNAME +$DriveLetter = "X:" + + +$path = (Get-VM -VMName $VMname | Select-Object -Property VMId | Get-VHD).path +$Unique = (Mount-VHD -Path $path -PassThru | Get-Disk | Get-Partition | Get-Volume | Where-Object size -GT 10GB) +Get-Volume -UniqueId $unique.UniqueId | Get-Partition | Add-PartitionAccessPath -AccessPath $DriveLetter # Get Third Party drivers used, that are not provided by Microsoft and presumably included in the OS $drivers = Get-WmiObject Win32_PNPSignedDriver | where {$_.DriverProviderName -eq "NVIDIA"} @@ -46,3 +52,5 @@ foreach ($d in $drivers) { } } +Get-Volume -UniqueId $unique.UniqueId | Get-Partition | Remove-PartitionAccessPath -AccessPath $driveLetter +Dismount-vhd -Path $path