What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Cannot run Hyper-V cmdlets from custom script

Votes:

0

Hello

I created a custom PowerShell script to use with the Custom EXE/Script type of sensor, but I am not able to get results from it because it says it cannot find the "Get-VM" module. I have installed WMF 5.0 in the Windows Server 2012 R2 running the PRTG probe, AND installed Hyper-V Powershell management tools. When I run the script directly from the PRTG probe in a PowerShell ISE window, the script does what it needs. It uses the Get-VM module.

But when the PRTG sensor tries to use the script, the logs notes this:

Get-VM : The term 'Get-VM' is not recognized as the name of a cmdlet, 
function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At C:\Program Files (x86)\PRTG Network Monitor\custom 
sensors\EXE\checkAllDCsTimeSyncSvcs.ps1:5 char:22
+ $domaincontrollers = Get-VM -ComputerName $hypervhost | where {$_.Nam ...
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-VM:String) [], CommandNotFo 
undException
+ FullyQualifiedErrorId : CommandNotFoundException

This doesn't make sense to me, because I have all the necessary tools. Is there a way in PRTG to make it see the latest WMF / PowerShell version ?

Thank you!

custom-script-exe powershell prtg

Created on Mar 21, 2017 2:06:37 PM

Last change on Mar 21, 2017 2:46:46 PM by  Stephan Linke [Paessler Support]



4 Replies

Votes:

0

Are you actually loading the HyperV modules at the beginning of the script? Could you post the entire script?

Created on Mar 21, 2017 2:48:49 PM by  Stephan Linke [Paessler Support]



Votes:

0

Here is the script (no, I didn't load the Hyper-V modules at beginning of script).

param (
[string]$hypervhost
)

$domaincontrollers = Get-VM -ComputerName $hypervhost | where {$_.Name -like 'DC*' -or $_.Name -like 'REPLICA DC*'} | ForEach-Object {$_.Name}
foreach ($domaincontroller in $domaincontrollers) {
   $dcscount += Get-VMIntegrationService -ComputerName $hypervhost -VMName $domaincontroller | where {$_.Name -eq "Time Synchronization" -and $_.Enabled -eq 1} | select VMName,Name,Enabled | Measure-Object | Select-Object -ExpandProperty Count
}

$dcstotal = $dcscount+":OK"

Write-Host $dcstotal

exit 0

Created on Mar 21, 2017 2:57:36 PM

Last change on Mar 21, 2017 3:25:23 PM by  Stephan Linke [Paessler Support]



Votes:

0

Stephan, Thank you for your suggestion. I added the Import-Module cmdlet to my script, and it does work now!

Created on Mar 21, 2017 3:13:00 PM



Votes:

0

Cool! :)

Created on Mar 21, 2017 3:25:28 PM by  Stephan Linke [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.