The command (up_time) returned an invalid return code: 255


hello every one,

I need to set up a nagios server with passive checks at my clients (outside my network) So I use NSClient ++ with NSCA My configuration works for all my clients except for two AD server.

The command (up_time) returned an invalid return code: 255

The script up_time works fine when I run it locally.

My config nsclient.ini


uptime = up_time diskfail = disk_fail space = space_disk backup-exec = check_serviceoff updates = check_maj hyperv-snapshot = hyperv_snapshot vmware-snapshot = vmware_snapshot windows-backup = windows_backup veeam-backup = veeam_backup


CheckExternalScripts = enabled

CheckHelpers = enabled

CheckNSCP = enabled

CheckDisk = enabled

CheckSystem = enabled

NSClientServer = disabled

CheckEventLog = enabled

NSCAClient = enabled

Scheduler = enabled

NRPEServer = disabled

[/settings/external scripts]

allow arguments = True timeout=120

[/settings/external scripts/scripts]

list_file=cmd /c “dir c:\”

up_time = cmd /c echo scripts\up_time.ps1; exit($lastexitcode) | powershell.exe -command - disk_fail = cmd /c echo scripts\disk_fail.ps1; exit($lastexitcode) | powershell.exe -command - space_disk = cmd /c echo scripts\space_disk.ps1; exit($lastexitcode) | powershell.exe -command - ;check_backupexec = cmd /c echo scripts\check_backupexec.ps1; exit($lastexitcode) | powershell.exe -command - ;hyperv_snapshot = cmd /c echo scripts\hyperv_snapshot.ps1; exit($lastexitcode) | powershell.exe -command - ;vmware_snapshot = cmd /c echo scripts\vmware_snapshot.ps1; exit($lastexitcode) | powershell.exe -command - check_maj = cmd /c echo scripts\maj.ps1; exit($lastexitcode) | powershell.exe -command - ;windows_backup = cmd /c echo scripts\check_windows_backup.ps1; exit($lastexitcode) | powershell.exe -command - ;veeam_backup = cmd /c echo scripts\veeam_backup.ps1; exit($lastexitcode) | powershell.exe -command -

Example of a script powershell that i run with nsclient :

function Get-SystemUptime { $operatingSystem = Get-WmiObject Win32_OperatingSystem [Management.ManagementDateTimeConverter]::ToDateTime($operatingSystem.LastBootUpTime) }

Get-SystemUptime ($computer = “localhost”) >$NULL $lastboot = [System.Management.ManagementDateTimeconverter]::ToDateTime( "$((gwmi Win32_OperatingSystem -computername $computer).LastBootUpTime)") $uptime = (Get-Date) - $lastboot Write-Host "Duree de fonctionnement : " $uptime.days “jours” $uptime.hours “heures” $uptime.minutes “minutes”

le code d’erreur est toujours a 0 pour que l’état dans nagios soit toujours a OK

exit 0


Hi Arenn,

One condition we met for this kind of error is, we lost the powershell path in system variables.

For this kind of situation, the solution is just add below path to system variable or the nsclient running user variable “PATH”