2023-08-10 16:53:25 -04:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
|
# SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2020-03-31 15:02:43 -04:00
|
|
|
#Requires -Modules VagrantMessages
|
|
|
|
|
|
|
|
|
|
param(
|
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
|
[string]$VmId,
|
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
|
[string]$ControllerType,
|
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
|
[string]$ControllerNumber,
|
|
|
|
|
[Parameter(Mandatory=$true)]
|
2020-04-14 17:01:39 -04:00
|
|
|
[string]$ControllerLocation,
|
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
|
[string]$DiskFilePath
|
2020-03-31 15:02:43 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$VM = Hyper-V\Get-VM -Id $VmId
|
|
|
|
|
|
2020-04-14 14:50:30 -04:00
|
|
|
Hyper-v\Remove-VMHardDiskDrive -VMName $VM.Name -ControllerType $ControllerType -ControllerNumber $ControllerNumber -ControllerLocation $ControllerLocation
|
2020-04-14 17:01:39 -04:00
|
|
|
|
|
|
|
|
Remove-Item -Path $DiskFilePath
|
2020-03-31 15:02:43 -04:00
|
|
|
} catch {
|
|
|
|
|
Write-ErrorMessage "Failed to remove disk ${DiskFilePath} to VM ${VM}: ${PSItem}"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|