<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[cant get powershell script to run]]></title><description><![CDATA[<p dir="auto">Hello</p>
<p dir="auto">i made a small powershell query to return oldest folder age in days. But i cant get it to run with netxms agent, i get error:</p>
<pre><code>Process "powershell -Command "&amp; SCRIPT"" killed because of execution timeout
</code></pre>
<p dir="auto">Agent conf file:</p>
<pre><code>MasterServers = ip
ConfigIncludeDir = C:\NetXMS\etc\nxagentd.conf.d
LogFile = C:\NetXMS\log\netxms-agent.log
FileStore = C:\NetXMS\var
SubAgent = winperf.nsm

ExternalParameter = Custom.Script:powershell -Command "&amp; {Get-ChildItem 'path' | Where { $_.PSIsContainer } | Sort CreationTime | Select -First 1 | Foreach-Object {$dtdiff = (New-TimeSpan ($_.LastWriteTime) $(Get-Date))}; write-host $dtdiff.days}"
</code></pre>
]]></description><link>https://forum.netxms.org/topic/6369/cant-get-powershell-script-to-run</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 12:19:02 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/6369.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 11 Jan 2020 17:55:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to cant get powershell script to run on Mon, 17 Feb 2020 09:44:11 GMT]]></title><description><![CDATA[<p dir="auto">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 &gt; 4835ms:error | &lt; 4835ms:good. So i think path variable is working.</p>
<pre><code>$age = 1500;
Start-Sleep -Milliseconds 4840
$Output = 'Parameter.Name=' + $age
echo $Output
</code></pre>
<p dir="auto">Currently working method:</p>
<p dir="auto">Agent Conf:<br />
ExternalParametersProvider=powershell.exe C:\NetXMS\script\ReturnInfo.ps1:1800</p>
<p dir="auto"><a href="http://ReturnInfo.ps" rel="nofollow ugc">ReturnInfo.ps</a>:</p>
<pre><code>$DataFile = "C:\NetXMS\script\output.txt"

$Array = "";

if (Test-Path -Path $DataFile) {

    $Content = Get-Content $DataFile
    $Array = $Content.split('|');

}


return $Array
</code></pre>
<p dir="auto">Output.txt is generated from different script that is running with task scheduler.</p>
]]></description><link>https://forum.netxms.org/post/27392</link><guid isPermaLink="true">https://forum.netxms.org/post/27392</guid><dc:creator><![CDATA[Egert143]]></dc:creator><pubDate>Mon, 17 Feb 2020 09:44:11 GMT</pubDate></item><item><title><![CDATA[Reply to cant get powershell script to run on Mon, 17 Feb 2020 06:56:17 GMT]]></title><description><![CDATA[<p dir="auto">Could the issue be the missing quotes?<br />
Try this (not sure about your execution policy, so I added that):</p>
<pre><code>ExternalParametersProvider=powershell.exe -executionpolicy bypass -c "C:\NetXMS\script\ReturnInfo.ps1":1800
</code></pre>
<p dir="auto">Without the quotes, I'm not sure what NetXMS will make out of your C**:**, considering the colon is a separator.</p>
<p dir="auto">Your original ExternalParameter did not escape the $ character, which needs to be double up, e.g. like this:</p>
<pre><code>ExternalParameter=Custom.Script:powershell -Command "&amp; {Get-ChildItem 'path' | Where { $$_.PSIsContainer } | Sort CreationTime | Select -First 1 | Foreach-Object {$$dtdiff = (New-TimeSpan ($$_.LastWriteTime) $$(Get-Date))}; write-host $$dtdiff.days}"
</code></pre>
]]></description><link>https://forum.netxms.org/post/27390</link><guid isPermaLink="true">https://forum.netxms.org/post/27390</guid><dc:creator><![CDATA[Tursiops]]></dc:creator><pubDate>Mon, 17 Feb 2020 06:56:17 GMT</pubDate></item><item><title><![CDATA[Reply to cant get powershell script to run on Thu, 23 Jan 2020 14:07:29 GMT]]></title><description><![CDATA[<p dir="auto">Win 7 Pro</p>
<p dir="auto">$PSVersionTable:</p>
<pre><code>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.2
</code></pre>
<p dir="auto">Currently 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.</p>
<pre><code>ExternalParametersProvider=powershell.exe C:\NetXMS\script\ReturnInfo.ps1:1800
</code></pre>
]]></description><link>https://forum.netxms.org/post/27297</link><guid isPermaLink="true">https://forum.netxms.org/post/27297</guid><dc:creator><![CDATA[Egert143]]></dc:creator><pubDate>Thu, 23 Jan 2020 14:07:29 GMT</pubDate></item><item><title><![CDATA[Reply to cant get powershell script to run on Thu, 23 Jan 2020 13:18:03 GMT]]></title><description><![CDATA[<p dir="auto">What is your PS and Windows versions?</p>
]]></description><link>https://forum.netxms.org/post/27296</link><guid isPermaLink="true">https://forum.netxms.org/post/27296</guid><dc:creator><![CDATA[Filipp Sudanov]]></dc:creator><pubDate>Thu, 23 Jan 2020 13:18:03 GMT</pubDate></item><item><title><![CDATA[Reply to cant get powershell script to run on Sat, 18 Jan 2020 11:01:15 GMT]]></title><description><![CDATA[<p dir="auto">Seems like it is Bug / error on netxms, did quick and simple test:</p>
<p dir="auto">Script:</p>
<pre><code>$age = 1500;
Start-Sleep -Milliseconds 4840
$Output = 'Parameter.Name=' + $age
echo $Output
</code></pre>
<p dir="auto">if script ran 4835 ms or more then no result to agent. Anything less and agent received value.</p>
<p dir="auto">Also "The pipe has been ended." doesent mean error, it comes with 0 or 1 value.</p>
]]></description><link>https://forum.netxms.org/post/27291</link><guid isPermaLink="true">https://forum.netxms.org/post/27291</guid><dc:creator><![CDATA[Egert143]]></dc:creator><pubDate>Sat, 18 Jan 2020 11:01:15 GMT</pubDate></item><item><title><![CDATA[Reply to cant get powershell script to run on Thu, 16 Jan 2020 06:03:20 GMT]]></title><description><![CDATA[<pre><code>2020.01.14 19:49:15.569 *D* [                   ] ProcessExecutor::readOutput(): stopped on GetOverlappedResult (The pipe has been ended.)
</code></pre>
<p dir="auto">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 <img src="https://forum.netxms.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=72b86a538fc" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
]]></description><link>https://forum.netxms.org/post/27281</link><guid isPermaLink="true">https://forum.netxms.org/post/27281</guid><dc:creator><![CDATA[Egert143]]></dc:creator><pubDate>Thu, 16 Jan 2020 06:03:20 GMT</pubDate></item><item><title><![CDATA[Reply to cant get powershell script to run on Tue, 14 Jan 2020 17:52:15 GMT]]></title><description><![CDATA[<p dir="auto">Debug 7 gave one extra line:</p>
<pre><code>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
</code></pre>
]]></description><link>https://forum.netxms.org/post/27271</link><guid isPermaLink="true">https://forum.netxms.org/post/27271</guid><dc:creator><![CDATA[Egert143]]></dc:creator><pubDate>Tue, 14 Jan 2020 17:52:15 GMT</pubDate></item><item><title><![CDATA[Reply to cant get powershell script to run on Tue, 14 Jan 2020 15:30:22 GMT]]></title><description><![CDATA[<p dir="auto">Yes, right, it's not the timeout, otherwise there would be a message on 4-th debug level:</p>
<pre><code>command "powershell.exe C:\test3.ps1" execution timeout (70 seconds)
</code></pre>
<p dir="auto">Can you increase debug level to 7 and attach the log.</p>
]]></description><link>https://forum.netxms.org/post/27270</link><guid isPermaLink="true">https://forum.netxms.org/post/27270</guid><dc:creator><![CDATA[Filipp Sudanov]]></dc:creator><pubDate>Tue, 14 Jan 2020 15:30:22 GMT</pubDate></item><item><title><![CDATA[Reply to cant get powershell script to run on Tue, 14 Jan 2020 07:45:19 GMT]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">From agent log:</p>
<pre><code>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 read
</code></pre>
<p dir="auto">Agent conf file:</p>
<pre><code>#
# 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:300
</code></pre>
<p dir="auto">Script after updating PowerShell to ver 4:</p>
<pre><code>$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 $Output
</code></pre>
<p dir="auto">When i change path variable in script to count smaller folder where result will be instant, instead of few seconds then agent gets the value.</p>
<p dir="auto">Even updated to latest version today.</p>
]]></description><link>https://forum.netxms.org/post/27268</link><guid isPermaLink="true">https://forum.netxms.org/post/27268</guid><dc:creator><![CDATA[Egert143]]></dc:creator><pubDate>Tue, 14 Jan 2020 07:45:19 GMT</pubDate></item><item><title><![CDATA[Reply to cant get powershell script to run on Mon, 13 Jan 2020 17:23:43 GMT]]></title><description><![CDATA[<p dir="auto">There is agent configuration parameter <strong>ExternalParameterProviderTimeout</strong> 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.</p>
]]></description><link>https://forum.netxms.org/post/27263</link><guid isPermaLink="true">https://forum.netxms.org/post/27263</guid><dc:creator><![CDATA[Filipp Sudanov]]></dc:creator><pubDate>Mon, 13 Jan 2020 17:23:43 GMT</pubDate></item><item><title><![CDATA[Reply to cant get powershell script to run on Mon, 13 Jan 2020 12:38:28 GMT]]></title><description><![CDATA[<p dir="auto">Bump, Any suggestions what could be the issue here ? <img src="https://forum.netxms.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=72b86a538fc" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
]]></description><link>https://forum.netxms.org/post/27262</link><guid isPermaLink="true">https://forum.netxms.org/post/27262</guid><dc:creator><![CDATA[Egert143]]></dc:creator><pubDate>Mon, 13 Jan 2020 12:38:28 GMT</pubDate></item><item><title><![CDATA[Reply to cant get powershell script to run on Sun, 12 Jan 2020 17:40:43 GMT]]></title><description><![CDATA[<p dir="auto">Attempt #2</p>
<p dir="auto">This time i tryed with ExternalParametersProvider:</p>
<p dir="auto">Agent Conf</p>
<pre><code>MasterServers = ip
ExecTimeout = 10000
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

ExternalParametersProvider=powershell.exe C:\NetXMS\script\test2.ps1:60
</code></pre>
<p dir="auto">Script: <code>Get-ChildItem 'D:\test\609920fa-6243-4587-b33c-b73961130e04' | Where { $_.PSIsContainer } | Sort LastWriteTime | Select -First 1 | Foreach-Object {$age = (New-TimeSpan ($_.LastWriteTime) $(Get-Date)); $out = 'Parameter1=' + $age.days; echo $out}</code></p>
<p dir="auto">Agent Debug log:</p>
<pre><code>2020.01.12 19:17:10.703 *D* [                   ] ProcessExecutor::execute(): process "CMD.EXE /C powershell.exe C:\NetXMS\script\test2.ps1" started
2020.01.12 19:17:10.703 *D* [                   ] ParamProvider::poll(): started command "powershell.exe C:\NetXMS\script\test2.ps1"
2020.01.12 19:17:22.825 *D* [                   ] ParamProvider::poll(): command "powershell.exe C:\NetXMS\script\test2.ps1" execution completed, 0 values read
</code></pre>
<p dir="auto">When i run command manualy i get response Parameter1=114</p>
<pre><code>CMD.EXE /C powershell.exe C:\NetXMS\script\test2.ps1
</code></pre>
<p dir="auto">Why doesent netxms get that value ?</p>
<p dir="auto">EDIT: when testing with smaller ammount of files it does return a value. When testing folder with ~82000 sub folders where script runs about ~6 seconds then agent gets result 0, manualy running script works ? Any fix for that ?</p>
]]></description><link>https://forum.netxms.org/post/27257</link><guid isPermaLink="true">https://forum.netxms.org/post/27257</guid><dc:creator><![CDATA[Egert143]]></dc:creator><pubDate>Sun, 12 Jan 2020 17:40:43 GMT</pubDate></item></channel></rss>