Add powershell script for attaching a harddisk to a guest

This commit is contained in:
Brian Cain 2020-03-31 11:29:05 -07:00
parent 09bd28048e
commit 26e5cf1d02
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0

View File

@ -0,0 +1,19 @@
#Requires -Modules VagrantMessages
param(
[Parameter(Mandatory=$true)]
[string]$VmId,
[string]$ControllerType,
[string]$ControllerNumber,
[string]$ControllerLocation,
[Parameter(Mandatory=$true)]
[string]$DiskFilePath
)
try {
$vm = Hyper-V\Get-VM -Id $VmId
Hyper-V\Add-VMHardDiskDrive -VMName $vm -ControllerType $ControllerType -ControllerNumber $ControllerNumber -ControllerLocation $ControllerLocation -Path $DiskFilePath
} catch {
Write-ErrorMessage "Failed to attach disk ${DiskFilePath} to VM ${vm}: ${PSItem}"
exit 1
}