I actually wanted to test something this morning, and completely deleted the script off a server. I then forced the check, and it STILL came back okay
Code: Select all
Current Status:
OK
(for 4d 17h 0m 30s)
Status Information: scripts\check_windows_updates.ps1 : The module 'scripts' could not be loaded.
For more information, run 'Import-Module scripts'.
At line:1 char:1
+ scripts\\check_windows_updates.ps1 ; exit($lastexitcode)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (scripts\\check_windows_updates.
ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoLoadModule
So I think this means it's definitely not the script itself? That points to the wrapping but as we saw it seems okay...
EDIT:
I've done some looking into $lastexitcode and I wonder if thats not the issue?
This post says that it only returns the exit code of the last executable that ran, i.e., nothing runs, it'll be 0
https://social.technet.microsoft.com/Fo ... forum=ITCG
Tested using the wrapper and it does look like the issue could be from this..
With $lastexitcode
Code: Select all
C:\Program Files\NSClient++>echo scripts\\check_windows_updates.ps1; exit ($lastexitcode) | powershell
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS C:\Program Files\NSClient++> scripts\\check_windows_updates.ps1; exit ($lastexitcode)
Updates: 0 Critical, 2 Optional, 1 'Fresh' Updates
| critical=0, optional=2, hidden=0, new=1
C:\Program Files\NSClient++>echo Exit Code is %errorlevel%
Exit Code is 0
C:\Program Files\NSClient++>echo "I am moving the file"
"I am moving the file"
C:\Program Files\NSClient++>echo scripts\\check_windows_updates.ps1; exit ($lastexitcode) | powershell
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS C:\Program Files\NSClient++> scripts\\check_windows_updates.ps1; exit ($lastexitcode)
scripts\\check_windows_updates.ps1 : The module 'scripts' could not be loaded. For more information, run
'Import-Module scripts'.
At line:1 char:1
+ scripts\\check_windows_updates.ps1; exit ($lastexitcode)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (scripts\\check_windows_updates.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoLoadModule
C:\Program Files\NSClient++>echo Exit Code is %errorlevel%
Exit Code is 0
Without $lastexitcode
Code: Select all
C:\Program Files\NSClient++>echo scripts\\check_windows_updates.ps1 | powershell
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS C:\Program Files\NSClient++> scripts\\check_windows_updates.ps1
scripts\\check_windows_updates.ps1 : The module 'scripts' could not be loaded. For more information, run
'Import-Module scripts'.
At line:1 char:1
+ scripts\\check_windows_updates.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (scripts\\check_windows_updates.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoLoadModule
PS C:\Program Files\NSClient++>
C:\Program Files\NSClient++>echo Exit Code is %errorlevel%
Exit Code is 1
C:\Program Files\NSClient++>echo "moving file back"
"moving file back"
C:\Program Files\NSClient++>echo scripts\\check_windows_updates.ps1 | powershell
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS C:\Program Files\NSClient++> scripts\\check_windows_updates.ps1
Updates: 0 Critical, 2 Optional, 1 'Fresh' Updates
| critical=0, optional=2, hidden=0, new=1
PS C:\Program Files\NSClient++>
C:\Program Files\NSClient++>echo Exit Code is %errorlevel%
Exit Code is 0
So something funky seems to be going on with the wrapping? $lastexitcode doesn't seem necessary, but the documentation/your original link seems to say that it is to capture the exit code..Any comments/ideas?