cant get powershell script to run
-
There is agent configuration parameter ExternalParameterProviderTimeout that sets timeout for external parameters provider execution. By default it's equial to 30 seconds. The behavior you describing might be happening if your script runs longer then 30s.
-
Thanks for suggestion, i tested that config parameter but no joy. I think it must be somthing else, because according to logs, script dont even have time to run 30s before '0 value' is returned according to netxms agent.
From agent log:
2020.01.14 09:33:34.573 *I* [ ] NetXMS Agent started 2020.01.14 09:33:34.575 *D* [ ] ProcessExecutor::execute(): process "CMD.EXE /C powershell.exe C:\NetXMS\script\test.ps1" started 2020.01.14 09:33:34.575 *D* [ ] ParamProvider::poll(): started command "powershell.exe C:\NetXMS\script\test.ps1" 2020.01.14 09:33:39.852 *D* [ ] ParamProvider::poll(): command "powershell.exe C:\NetXMS\script\test.ps1" execution completed, 0 values readAgent conf file:
# # NetXMS agent configuration file # Created by agent installer at Wed Sep 4 14:38:01 2019 # MasterServers = ip ConfigIncludeDir = C:\NetXMS\etc\nxagentd.conf.d LogFile = C:\NetXMS\log\netxms-agent.log FileStore = C:\NetXMS\var SubAgent = winperf.nsm SubAgent = filemgr.nsm DebugLevel = 5 ExternalParameterProviderTimeout = 60 ExternalParametersProvider=powershell.exe C:\NetXMS\script\test.ps1:300Script after updating PowerShell to ver 4:
$folder = Get-ChildItem 'D:\a8becad8-6be2-4164-a405-dea4052b3720' -Directory | Sort LastWriteTime | Select -First 1 $age = ([datetime]::Now - $folder.LastWriteTime).TotalHours #$age = ([datetime]::Now - $folder.LastWriteTime).Days if($age -ige 1) { $Output = 'Parameter1=' + $age }else{ $Output = 'Parameter1=1' } echo $OutputWhen i change path variable in script to count smaller folder where result will be instant, instead of few seconds then agent gets the value.
Even updated to latest version today.
-
Yes, right, it's not the timeout, otherwise there would be a message on 4-th debug level:
command "powershell.exe C:\test3.ps1" execution timeout (70 seconds)Can you increase debug level to 7 and attach the log.
-
Debug 7 gave one extra line:
2020.01.14 19:49:10.356 *D* [ ] ProcessExecutor::execute(): process "CMD.EXE /C powershell.exe C:\NetXMS\script\test.ps1" started 2020.01.14 19:49:10.356 *D* [ ] ParamProvider::poll(): started command "powershell.exe C:\NetXMS\script\test.ps1" 2020.01.14 19:49:10.357 *I* [ ] NetXMS Agent started 2020.01.14 19:49:15.569 *D* [ ] ProcessExecutor::readOutput(): stopped on GetOverlappedResult (The pipe has been ended.) 2020.01.14 19:49:15.569 *D* [ ] ParamProvider::poll(): command "powershell.exe C:\NetXMS\script\test.ps1" execution completed, 0 values read -
2020.01.14 19:49:15.569 *D* [ ] ProcessExecutor::readOutput(): stopped on GetOverlappedResult (The pipe has been ended.)Could that mean script or agent error ? It seems script runs about 5-6 seconds as usual. Also if someone is decent at powershell maybe there is somthing wrong with script itself? I am very beginner in PS

-
Seems like it is Bug / error on netxms, did quick and simple test:
Script:
$age = 1500; Start-Sleep -Milliseconds 4840 $Output = 'Parameter.Name=' + $age echo $Outputif script ran 4835 ms or more then no result to agent. Anything less and agent received value.
Also "The pipe has been ended." doesent mean error, it comes with 0 or 1 value.
-
What is your PS and Windows versions?
-
Win 7 Pro
$PSVersionTable:
Name Value ---- ----- PSVersion 4.0 WSManStackVersion 3.0 SerializationVersion 1.1.0.1 CLRVersion 4.0.30319.42000 BuildVersion 6.3.9600.16406 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0} PSRemotingProtocolVersion 2.2Currently i have setup where i run PS script with task scheduler and save result into txt file. Then with netxms agent i run a script that reades value out of txt file. That way it stays well under 1 sec runtime and works perfectly. Currently testing in 8 different machines.
ExternalParametersProvider=powershell.exe C:\NetXMS\script\ReturnInfo.ps1:1800 -
Could the issue be the missing quotes?
Try this (not sure about your execution policy, so I added that):ExternalParametersProvider=powershell.exe -executionpolicy bypass -c "C:\NetXMS\script\ReturnInfo.ps1":1800Without the quotes, I'm not sure what NetXMS will make out of your C**:**, considering the colon is a separator.
Your original ExternalParameter did not escape the $ character, which needs to be double up, e.g. like this:
ExternalParameter=Custom.Script:powershell -Command "& {Get-ChildItem 'path' | Where { $$_.PSIsContainer } | Sort CreationTime | Select -First 1 | Foreach-Object {$$dtdiff = (New-TimeSpan ($$_.LastWriteTime) $$(Get-Date))}; write-host $$dtdiff.days}" -
Thanks for the reply. In later posts i changed the polling method to script file instead of direct command in agent conf. When i changed script content to simple output where i could change execution time, then depending on run time > 4835ms:error | < 4835ms:good. So i think path variable is working.
$age = 1500; Start-Sleep -Milliseconds 4840 $Output = 'Parameter.Name=' + $age echo $OutputCurrently working method:
Agent Conf:
ExternalParametersProvider=powershell.exe C:\NetXMS\script\ReturnInfo.ps1:1800$DataFile = "C:\NetXMS\script\output.txt" $Array = ""; if (Test-Path -Path $DataFile) { $Content = Get-Content $DataFile $Array = $Content.split('|'); } return $ArrayOutput.txt is generated from different script that is running with task scheduler.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login