Easy-GPU-PV/Update-VMGpuPartitionDriver.ps1

40 lines
1011 B
PowerShell
Raw Normal View History

2021-11-21 13:38:21 +00:00
Param (
[string]$VMName,
[string]$GPUName,
[string]$Hostname = $ENV:Computername
)
Import-Module $PSSCriptRoot\Add-VMGpuPartitionAdapterFiles.psm1
2021-11-21 13:38:21 +00:00
$VM = Get-VM -VMName $VMName
2021-11-21 13:40:09 +00:00
$VHD = Get-VHD -VMId $VM.VMId
2021-11-21 13:38:21 +00:00
If ($VM.state -eq "Running") {
2021-11-21 13:40:09 +00:00
[bool]$state_was_running = $true
}
2021-11-21 13:38:21 +00:00
if ($VM.state -ne "Off"){
2021-11-21 13:40:09 +00:00
"Attemping to shutdown VM..."
Stop-VM -Name $VMName -Force
}
2021-11-21 13:38:21 +00:00
While ($VM.State -ne "Off") {
2021-11-21 13:40:09 +00:00
Start-Sleep -s 3
"Waiting for VM to shutdown - make sure there are no unsaved documents..."
}
2021-11-21 13:38:21 +00:00
"Mounting Drive..."
$DriveLetter = (Mount-VHD -Path $VHD.Path -PassThru | Get-Disk | Get-Partition | Get-Volume | Where-Object {$_.DriveLetter} | ForEach-Object DriveLetter)
2021-11-21 13:38:21 +00:00
"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){
2021-11-21 13:40:09 +00:00
"Previous State was running so starting VM..."
Start-VM $VMName
}
"Done..."