2014-02-16 19:31:33 +00:00
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
[string]$VmId
|
|
|
|
)
|
2014-02-15 23:29:16 +00:00
|
|
|
|
|
|
|
# Include the following modules
|
2014-02-16 19:31:33 +00:00
|
|
|
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
|
|
|
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
2014-02-15 23:29:16 +00:00
|
|
|
|
2014-02-16 19:31:33 +00:00
|
|
|
# Get the VM with the given name
|
2014-02-15 23:29:16 +00:00
|
|
|
try {
|
2014-02-16 19:31:33 +00:00
|
|
|
$VM = Get-VM -Id $VmId -ErrorAction "Stop"
|
|
|
|
$State = $VM.state
|
|
|
|
$Status = $VM.status
|
2015-08-09 16:44:49 +00:00
|
|
|
} catch [Microsoft.HyperV.PowerShell.VirtualizationException] {
|
2014-02-16 19:31:33 +00:00
|
|
|
$State = "not_created"
|
|
|
|
$Status = $State
|
2014-02-15 23:29:16 +00:00
|
|
|
}
|
2014-02-16 19:31:33 +00:00
|
|
|
|
|
|
|
$resultHash = @{
|
|
|
|
state = "$State"
|
|
|
|
status = "$Status"
|
2014-02-15 23:29:16 +00:00
|
|
|
}
|
2014-02-16 19:31:33 +00:00
|
|
|
$result = ConvertTo-Json $resultHash
|
|
|
|
Write-Output-Message $result
|