Sha256: 11371be462bf8fe3cdeebec799cecc686595c21a7c17ef152ffcd6d489e9fee2

Contents?: true

Size: 1.62 KB

Versions: 19

Compression:

Stored size: 1.62 KB

Contents

#Requires -Modules VagrantMessages

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

# 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 = Hyper-V\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-OutputMessage $result

Version data entries

19 entries across 15 versions & 2 rubygems

Version Path
vagrant-unbundled-2.2.9.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.2.8.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.2.7.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.2.6.2 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.2.6.1 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.2.6.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.2.5.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.2.4.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.2.3.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.2.2.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.2.0.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.1.4.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-unbundled-2.1.2.0 plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-packet-0.1.2 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/scripts/get_vm_status.ps1
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/hyperv/scripts/get_vm_status.ps1