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

28 lines
601 B
PowerShell
Raw Normal View History

param (
[string]$VmId = $(throw "-VmId is required.")
)
# Include the following modules
$presentDir = Split-Path -parent $PSCommandPath
$modules = @()
$modules += $presentDir + "\utils\write_messages.ps1"
forEach ($module in $modules) { . $module }
try {
$vm = Get-VM -Id $VmId -ErrorAction "stop"
Start-VM $vm
$state = $vm.state
$status = $vm.status
$name = $vm.name
$resultHash = @{
state = "$state"
status = "$status"
name = "$name"
}
$result = ConvertTo-Json $resultHash
Write-Output-Message $result
}
catch {
Write-Error-Message "Failed to start a VM $_"
}