Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.*
45 changes: 32 additions & 13 deletions Update-VMGpuPartitionDriver.ps1
Original file line number Diff line number Diff line change
@@ -1,52 +1,71 @@
<#
<#
If you are opening this file in Powershell ISE you should modify the params section like so...
Remember: GPU Name must match the name of the GPU you assigned when creating the VM...

Param (
[string]$VMName = "NameofyourVM",
[string]$GPUName = "NameofyourGPU",
[string]$BitLockerKey = "XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX-XXXXXX",
[string]$Hostname = $ENV:Computername
)

#>

Param (
[string]$VMName,
[string]$GPUName,
[string]$Hostname = $ENV:Computername
[string]$VMName,
[string]$GPUName,
[string]$BitLockerKey,
[string]$Hostname = $ENV:Computername
)

$ErrorActionPreference = "Stop"

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
}
[bool]$state_was_running = $True
}

if ($VM.state -ne "Off"){
if ($VM.state -ne "Off") {
"Attemping to shutdown VM..."
Stop-VM -Name $VMName -Force
}
$VHD = Get-VHD -VMId $VM.VMId
}

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)
if ($VHD.Attached -eq $False) {
"Mounting Drive..."
$DriveLetter = (Mount-VHD -Path $VHD.Path -PassThru | Get-Disk | Get-Partition | Get-Volume | Where-Object { $_.DriveLetter } | ForEach-Object DriveLetter)
}
else {
$DriveLetter = ($VHD | Get-Disk | Get-Partition | Get-Volume | Where-Object { $_.DriveLetter } | ForEach-Object DriveLetter)
"Using already mounted drive ${DriveLetter}"
}

$BitLockerStatus = Get-BitLockerVolume $DriveLetter
if ($BitLockerStatus.LockStatus) {
if ([string]::IsNullOrWhiteSpace($BitLockerKey)) {
$BitLockerKey = Read-Host "Enter BitLocker Key for drive ${DriveLetter}"
}
Unlock-BitLocker -MountPoint $DriveLetter -RecoveryPassword $BitLockerKey
}

"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){
If ($state_was_running) {
"Previous State was running so starting VM..."
Start-VM $VMName
}
}

"Done..."