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!
Article Comments
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
Mar, 2017 - Permalink
Stephan, Thank you for your suggestion. I added the Import-Module cmdlet to my script, and it does work now!
Mar, 2017 - Permalink
Are you actually loading the HyperV modules at the beginning of the script? Could you post the entire script?
Mar, 2017 - Permalink