From a2e65c159262185ff4a83f4748952c7bd62a5624 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 7 Mar 2022 11:12:47 +0100 Subject: [PATCH] (plugin) apps::microsoft::hyperv::2012 - try to load Hyper-V module if needed (#3525) --- .../centreon/common/powershell/hyperv/2012/listnodevms.pm | 4 ++++ .../common/powershell/hyperv/2012/nodeintegrationservice.pm | 3 +++ .../centreon/common/powershell/hyperv/2012/nodereplication.pm | 4 ++++ .../centreon/common/powershell/hyperv/2012/nodesnapshot.pm | 4 ++++ .../centreon/common/powershell/hyperv/2012/nodevmstatus.pm | 4 ++++ 5 files changed, 19 insertions(+) diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/listnodevms.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/listnodevms.pm index 9d0512700..46f05afc4 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/listnodevms.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/listnodevms.pm @@ -40,6 +40,10 @@ $ProgressPreference = "SilentlyContinue" Try { $ErrorActionPreference = "Stop" + If (@(Get-Module | Where-Object {$_.Name -Match "Hyper-V"} ).count -eq 0) { + Import-Module -Name "Hyper-V" + } + $vms = Get-VM $items = New-Object System.Collections.Generic.List[Hashtable]; diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm index 395f11002..d06d7f91a 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm @@ -40,6 +40,9 @@ $ProgressPreference = "SilentlyContinue" Try { $ErrorActionPreference = "Stop" + If (@(Get-Module | Where-Object {$_.Name -Match "Hyper-V"} ).count -eq 0) { + Import-Module -Name "Hyper-V" + } $vms = Get-VM diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodereplication.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodereplication.pm index bf3719e87..5a6d38942 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodereplication.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodereplication.pm @@ -40,6 +40,10 @@ $ProgressPreference = "SilentlyContinue" Try { $ErrorActionPreference = "Stop" + If (@(Get-Module | Where-Object {$_.Name -Match "Hyper-V"} ).count -eq 0) { + Import-Module -Name "Hyper-V" + } + $vms = Get-VMReplication $items = New-Object System.Collections.Generic.List[Hashtable]; diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm index 7a1f7dcac..5a3a3bf88 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodesnapshot.pm @@ -40,6 +40,10 @@ $ProgressPreference = "SilentlyContinue" Try { $ErrorActionPreference = "Stop" + If (@(Get-Module | Where-Object {$_.Name -Match "Hyper-V"} ).count -eq 0) { + Import-Module -Name "Hyper-V" + } + $vms = Get-VM if ($vms.Length -gt 0) { $snapshots = Get-VMSnapshot -VMName * diff --git a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodevmstatus.pm b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodevmstatus.pm index 57e93083b..6fc96a56c 100644 --- a/centreon-plugins/centreon/common/powershell/hyperv/2012/nodevmstatus.pm +++ b/centreon-plugins/centreon/common/powershell/hyperv/2012/nodevmstatus.pm @@ -40,6 +40,10 @@ $ProgressPreference = "SilentlyContinue" Try { $ErrorActionPreference = "Stop" + If (@(Get-Module | Where-Object {$_.Name -Match "Hyper-V"} ).count -eq 0) { + Import-Module -Name "Hyper-V" + } + $vms = Get-VM $node_is_clustered = 0