Check_nrpe + Powershell

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
joaase
Posts: 9
Joined: Fri Apr 17, 2015 7:26 am

Check_nrpe + Powershell

Post by joaase »

Hi.
Trying to create a new check too look when last windows update was install. i whant this check to run from one server and in my powershell script use New-PSSession to run script into Another server.
my powershell script look like this.

param (
[string] $computername
)

$password = ConvertTo-SecureString "password" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("username",$password )
$s = New-PSSession -ComputerName $computername -Credential $cred

$result = invoke-command -session $s -scriptblock {Get-ItemProperty -path "HKLM:\Software\microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install" -Name LastSuccessTime | select -Property LastSuccessTime}

Write-host = $result | select -Property LastSuccessTime

if i run script line by line its work perfect and give me correct value back
if i try to run script .\WindowsUpdate.ps1 "computername" is work perfect and give me correct value back

My op5.ini file look like this: check_Windowsupdate = cmd /c echo scripts\custom\WindowsUpdate.ps1 "$ARG1$" ; exit($lastexitcode) | powershell.exe -command -

MY check in OP5 look like this: $USER1$/check_nrpe -s -H $HOSTADDRESS$ -c check_Windowsupdate

my op5.ini file i have put this in under [/settings/external scripts/scripts]

when i try this check in op5 i get an error:

New-PSSession : One or more computer names are not valid. If you are trying to
pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of st
rings.
At C:Program FilesNSClient++scriptscustomWindowsUpdate.ps1:9 char:6
+ $s = New-PSSession -ComputerName $computername -Credential $cred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (System.String[]:String[]) [New
-PSSession], ArgumentException
+ FullyQualifiedErrorId : PSSessionInvalidComputerName,Microsoft.PowerShel
l.Commands.NewPSSessionCommand

Invoke-Command : Cannot validate argument on parameter 'Session'. The argument
is null or empty. Provide an argument that is not null or empty, and then try t
he command again.
At C:Program FilesNSClient++scriptscustomWindowsUpdate.ps1:11 char:35
+ $result = invoke-command -session $s -scriptblock {Get-ItemProperty -path "HK
LM: ...
+ ~~
+ CategoryInfo

Please can someone help me to understand what the problems is?

Best regard
Joakim
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Check_nrpe + Powershell

Post by mcapra »

joaase wrote: My op5.ini file look like this: check_Windowsupdate = cmd /c echo scripts\custom\WindowsUpdate.ps1 "$ARG1$" ; exit($lastexitcode) | powershell.exe -command -

MY check in OP5 look like this: $USER1$/check_nrpe -s -H $HOSTADDRESS$ -c check_Windowsupdate

my op5.ini file i have put this in under [/settings/external scripts/scripts]

when i try this check in op5 i get an error:
This sounds like an op5 issue more than a Nagios Core issue. I would recommend seeking assistance through that community.
Former Nagios employee
https://www.mcapra.com/
Locked