Sha256: f6179a86acdceec1627547b366be9a7fff7d4b151c96c1f54386d8b5abe02f5c

Contents?: true

Size: 1.72 KB

Versions: 14

Compression:

Stored size: 1.72 KB

Contents

Param(
    [Parameter(Mandatory=$true)]
    [string]$VmId
)

# Include the following modules
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))

# Make sure the exception type is loaded
try
{
    # Microsoft.HyperV.PowerShell is present on all versions of Windows with HyperV
    [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.HyperV.PowerShell, Culture=neutral, PublicKeyToken=31bf3856ad364e35')
    # Microsoft.HyperV.PowerShell.Objects is only present on Windows >= 10.0, so this will fail, and we ignore it since the needed exception
    # type was loaded in Microsoft.HyperV.PowerShell
    [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.HyperV.PowerShell.Objects, Culture=neutral, PublicKeyToken=31bf3856ad364e35')
} catch {
	# Empty catch ok, since if we didn't load the types, we will fail in the next block
}

$VmmsPath = if ([environment]::Is64BitProcess) { "$($env:SystemRoot)\System32\vmms.exe" } else { "$($env:SystemRoot)\Sysnative\vmms.exe" }
$HyperVVersion = [version](Get-Item $VmmsPath).VersionInfo.ProductVersion

if($HyperVVersion -lt ([version]'10.0')) {
  $ExceptionType = [Microsoft.HyperV.PowerShell.VirtualizationOperationFailedException]
} else {
  $ExceptionType = [Microsoft.HyperV.PowerShell.VirtualizationException]
}
try {
    $VM = Get-VM -Id $VmId -ErrorAction "Stop"
    $State = $VM.state
    $Status = $VM.status
} catch [Exception] {
    if($_.Exception.GetType() -eq $ExceptionType)
    {
        $State = "not_created"
        $Status = $State
    }
    else 
    {
        throw;
    }
}

$resultHash = @{
    state = "$State"
    status = "$Status"
}
$result = ConvertTo-Json $resultHash
Write-Output-Message $result

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
vagrant-unbundled-2.0.1.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.0.0.1 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-1.9.8.1 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-1.9.7.1 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-1.9.5.1 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-1.9.1.1 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-1.8.5.2 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-1.8.5.1 plugins/providers/hyperv/scripts/get_vm_status.ps1