Check_nrpe + Powershell
Posted: Mon Mar 20, 2017 7:38 am
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
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