2018-05-24 16:57:55 +00:00
|
|
|
#Requires -Modules VagrantVM, VagrantMessages
|
|
|
|
|
2017-03-15 21:12:19 +00:00
|
|
|
param (
|
2018-05-24 16:57:55 +00:00
|
|
|
[parameter (Mandatory=$true)]
|
|
|
|
[string] $VMID,
|
|
|
|
[parameter (Mandatory=$true)]
|
|
|
|
[string] $Name,
|
|
|
|
[parameter (Mandatory=$false)]
|
|
|
|
[switch] $Enable
|
2017-03-15 21:12:19 +00:00
|
|
|
)
|
|
|
|
|
2018-05-24 16:57:55 +00:00
|
|
|
$ErrorActionPreference = "Stop"
|
2017-03-15 21:12:19 +00:00
|
|
|
|
2018-05-24 16:57:55 +00:00
|
|
|
try {
|
|
|
|
$VM = Hyper-V\Get-VM -Id $VMID
|
|
|
|
} catch {
|
2018-06-12 22:32:29 +00:00
|
|
|
Write-ErrorMessage "Failed to locate VM: ${PSItem}"
|
2018-05-24 16:57:55 +00:00
|
|
|
exit 1
|
2017-03-15 21:12:19 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 16:57:55 +00:00
|
|
|
try {
|
2018-06-07 21:00:09 +00:00
|
|
|
Set-VagrantVMService -VM $VM -Name $Name -Enable $Enable
|
2018-05-24 16:57:55 +00:00
|
|
|
} catch {
|
2018-06-07 21:00:09 +00:00
|
|
|
if($Enable){ $action = "enable" } else { $action = "disable" }
|
2018-06-12 22:32:29 +00:00
|
|
|
Write-ErrorMessage "Failed to ${action} VM integration service ${Name}: ${PSItem}"
|
2018-05-24 16:57:55 +00:00
|
|
|
exit 1
|
|
|
|
}
|