forked from jamesstringerparsec/Easy-GPU-PV
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Update-VMGpuPartitionDriver.ps1
45 lines (34 loc) · 1.14 KB
/
Update-VMGpuPartitionDriver.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function Update-VMGpuPartitionDriver {
#requires -Module Hyper-V
[CmdletBinding()]
Param (
[string]$VMName,
[string]$GPUName,
[string]$Hostname = $ENV:Computername
)
Import-Module $PSSCriptRoot\Add-VMGpuPartitionAdapterFiles.psm1
$VM = Get-VM -VMName $VMName
$VHD = $VM.HardDrives|where-object { $_.ControllerNumber -eq 0 -and $_.ControllerLocation -eq 0 }
If ($VM.state -eq "Running") {
[bool]$state_was_running = $true
}
if ($VM.state -ne "Off"){
"Attemping to shutdown VM..."
Stop-VM -Name $VMName -Force
}
While ($VM.State -ne "Off") {
Start-Sleep -s 3
"Waiting for VM to shutdown - make sure there are no unsaved documents..."
}
"Mounting Drive..."
$DriveLetter = (Mount-VHD -Path $VHD.Path -PassThru | Get-Disk | Get-Partition | Get-Volume | Where-Object {$_.DriveLetter} | ForEach-Object DriveLetter)
"Copying GPU Files - this could take a while..."
Add-VMGPUPartitionAdapterFiles -hostname $Hostname -DriveLetter $DriveLetter -GPUName $GPUName
"Dismounting Drive..."
Dismount-VHD -Path $VHD.Path
If ($state_was_running){
"Previous State was running so starting VM..."
Start-VM $VMName
}
"Done..."
}