Merge pull request #7108 from jtopper/fix_hyperv_status_exception

HyperV: Reinstate compatibility with PowerShell 4
This commit is contained in:
Seth Vargo 2016-05-20 10:46:01 -04:00
commit 08550b6888
1 changed files with 8 additions and 2 deletions

View File

@ -7,12 +7,18 @@ Param(
$Dir = Split-Path $script:MyInvocation.MyCommand.Path $Dir = Split-Path $script:MyInvocation.MyCommand.Path
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1")) . ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
# Get the VM with the given name
if($PSVersionTable.PSVersion.Major -le 4) {
$ExceptionType = [Microsoft.HyperV.PowerShell.VirtualizationOperationFailedException]
} else {
$ExceptionType = [Microsoft.HyperV.PowerShell.VirtualizationException]
}
try { try {
$VM = Get-VM -Id $VmId -ErrorAction "Stop" $VM = Get-VM -Id $VmId -ErrorAction "Stop"
$State = $VM.state $State = $VM.state
$Status = $VM.status $Status = $VM.status
} catch [Microsoft.HyperV.PowerShell.VirtualizationException] { } catch $ExceptionType {
$State = "not_created" $State = "not_created"
$Status = $State $Status = $State
} }