2014-02-15 23:29:16 +00:00
|
|
|
param (
|
2014-03-06 16:51:07 +00:00
|
|
|
[string]$VmId = $(throw "-VmId is required.")
|
2014-02-15 23:29:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Include the following modules
|
|
|
|
$presentDir = Split-Path -parent $PSCommandPath
|
|
|
|
$modules = @()
|
|
|
|
$modules += $presentDir + "\utils\write_messages.ps1"
|
|
|
|
forEach ($module in $modules) { . $module }
|
|
|
|
|
|
|
|
try {
|
2014-03-06 16:51:07 +00:00
|
|
|
$vm = Get-VM -Id $VmId -ErrorAction "stop"
|
2015-01-03 23:05:50 +00:00
|
|
|
Start-VM $vm -ErrorAction "stop"
|
2014-02-15 23:29:16 +00:00
|
|
|
$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 $_"
|
2015-01-03 23:05:50 +00:00
|
|
|
}
|