vagrant/plugins/providers/hyperv/scripts/remove_disk_drive.ps1

29 lines
766 B
PowerShell
Raw Normal View History

# 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)]
[string]$ControllerLocation,
[Parameter(Mandatory=$true)]
[string]$DiskFilePath
2020-03-31 15:02:43 -04:00
)
try {
$VM = Hyper-V\Get-VM -Id $VmId
Hyper-v\Remove-VMHardDiskDrive -VMName $VM.Name -ControllerType $ControllerType -ControllerNumber $ControllerNumber -ControllerLocation $ControllerLocation
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
}