-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathUpdate-VMGpuPartitionDriver.ps1
More file actions
67 lines (53 loc) · 1.87 KB
/
Update-VMGpuPartitionDriver.ps1
File metadata and controls
67 lines (53 loc) · 1.87 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Param (
[Parameter(Mandatory=$true)]
[string] $VMName,
[string] $GPUName = "AUTO",
[string] $Hostname = $ENV:Computername
)
Import-Module $PSSCriptRoot\Add-VMGpuPartitionAdapterFiles.psm1
$VM = Get-VM -VMName $VMName
$VHD = Get-VHD -VMId $VM.VMId
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..."
$WinPartition = (Mount-VHD -Path $VHD.Path -PassThru | Get-Disk | Get-Partition | Where-Object { $_.Type -eq "Basic" } | Select-Object -First 1)
if(!$WinPartition) {
Write-Error "Unable to find a basic partition on drive"
Dismount-VHD -Path $VHD.Path
Exit
}
$DriveLetter = $WinPartition.DriveLetter
if (!$DriveLetter) {
$UsedDriveLetters = (Get-WmiObject Win32_Volume | Where-Object { $_.DriveLetter }).DriveLetter.ToUpper().TrimEnd(':')
# 68-90 = D-Z
for ($i = 68; $i -le 90; $i++) {
$DriveLetter = [char]$i
if ($UsedDriveLetters -notcontains $DriveLetter) {
"Assigning ${DriveLetter}: to basic partition..."
Set-Partition -InputObject $WinPartition -NewDriveLetter $DriveLetter
break
}
}
}
if (Test-Path -Path ${DriveLetter}:\\Windows) {
"Copying GPU Files - this could take a while..."
Add-VMGPUPartitionAdapterFiles -hostname $Hostname -DriveLetter $DriveLetter -GPUName $GPUName
} else {
Write-Error "Mounted partition does not look like the Windows system partition"
}
"Dismounting Drive..."
Dismount-VHD -Path $VHD.Path
If ($state_was_running){
"Previous State was running so starting VM..."
Start-VM $VMName
}
"Done..."