<?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[Powershell commands in Agent config]]></title><description><![CDATA[<p dir="auto">I need to monitor a java process on some Windows hosts with the NetXMS Agent installed and running. The regular Process.Count and Process.CountEx only work for the process name, which is "java". This is not enough for my needs, since I need to make sure that java is run with certain arguments.</p>
<p dir="auto">In linux, I would simply to a <code>ps aux | grep &lt;Java class or jar name&gt; | wc -l</code> which works for all user permissions.</p>
<p dir="auto">I'm not very familiar with neither Windows nor Powershell, but I did manage to construct this one-liner for doing (sort of) the same thing:</p>
<pre><code>(WMIC path win32_process get Commandline | select-string &lt;Java class name&gt;).Matches.count
</code></pre>
<p dir="auto">This command returns the number of matches, or null if none were found.</p>
<p dir="auto">This works when I manually start a powershell with elevated permissions. It does not work through an ExternalParameter in the Agent though. When querying in the DCI config it returns "" even when the process is running. Is this because powershell commands are not run with elevated privileges? The agent itself is run elevated as far as I know.</p>
<p dir="auto">The full external parameter line in the config looks like this:</p>
<pre><code>ExternalParameter = ProcMon.SymmetricLauncher:powershell -Command "&amp; {(WMIC path win32_process get Commandline | select-string &lt;Java class name&gt;).Matches.count}"
</code></pre>
<p dir="auto">I also tried ExternalParameterShellExec, but it didn't work either.</p>
<p dir="auto">Are there any simple solutions to my problem?</p>
]]></description><link>https://forum.netxms.org/topic/4875/powershell-commands-in-agent-config</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 07:26:06 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/4875.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 18 Jan 2017 09:46:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Powershell commands in Agent config on Thu, 26 Jan 2017 15:26:39 GMT]]></title><description><![CDATA[<p dir="auto">It is supposed to be generic. I'll check it on Windows 7.</p>
<p dir="auto">Best regards,<br />
Victor</p>
]]></description><link>https://forum.netxms.org/post/21754</link><guid isPermaLink="true">https://forum.netxms.org/post/21754</guid><dc:creator><![CDATA[victor]]></dc:creator><pubDate>Thu, 26 Jan 2017 15:26:39 GMT</pubDate></item><item><title><![CDATA[Reply to Powershell commands in Agent config on Thu, 26 Jan 2017 12:12:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/victor" aria-label="Profile: victor">@<bdi>victor</bdi></a> said in <a href="/post/21734">Powershell commands in Agent config</a>:</p>
<blockquote>
<p dir="auto">just tested in on Windows - works as expected.</p>
</blockquote>
<p dir="auto">I did some further testing on different nodes. Process.CountEx works as expected on Windows 8.1 Pro, but not on Windows 7 Home Premium (don't ask, not my system design  <img src="https://forum.netxms.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f62e.png?v=72b86a538fc" class="not-responsive emoji emoji-android emoji--open_mouth" style="height:1.4em;width:auto;vertical-align:middle" title=":o" alt="😮" /> ).</p>
<p dir="auto">Is the Windows subagent supposed to be generic, or do you have a specific version subset that is supported?</p>
]]></description><link>https://forum.netxms.org/post/21753</link><guid isPermaLink="true">https://forum.netxms.org/post/21753</guid><dc:creator><![CDATA[MarkusW]]></dc:creator><pubDate>Thu, 26 Jan 2017 12:12:31 GMT</pubDate></item><item><title><![CDATA[Reply to Powershell commands in Agent config on Wed, 25 Jan 2017 09:16:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/victor" aria-label="Profile: victor">@<bdi>victor</bdi></a> said in <a href="/post/21742">Powershell commands in Agent config</a>:</p>
<blockquote>
<p dir="auto">Remember that second argument is regular expression, so certain characters have special meaning. For example, \ is an escape character, so to match it you should specify it as \\. As for class name you're probably right - agent extracts only first 255 characters of process command line. I'll fix that in next release.</p>
<p dir="auto">Best regards,<br />
Victor</p>
</blockquote>
<p dir="auto">Thank you. I have not used any special characters in the second argument.</p>
<p dir="auto">I just did some testing. The class path of one of the java processes contains the word "symmetric".</p>
<p dir="auto">Process.CountEx(java) returns 2 as expected.<br />
Process.CountEx(java,<strong>symmetric</strong>) returns <strong>0</strong>.<br />
Process.CountEx(java,<strong>s</strong>) returns <strong>1</strong>, even though the character "s" is present in the command line of both java processes.<br />
Process.CountEx(java,<strong>sy</strong>) returns <strong>0</strong>.<br />
Process.CountEx(java,<strong>.</strong>) returns <strong>1</strong>.</p>
<p dir="auto">Process.CountEx(java,<strong>_</strong>) returns <strong>1</strong> even though _ is not present in either command line.</p>
<p dir="auto">It seems no matter what I put as matching pattern, CountEx returns 0 if the pattern is longer than one character (other than regex special chars), and 1 if the pattern is one character.</p>
<p dir="auto">Any ideas?</p>
]]></description><link>https://forum.netxms.org/post/21744</link><guid isPermaLink="true">https://forum.netxms.org/post/21744</guid><dc:creator><![CDATA[MarkusW]]></dc:creator><pubDate>Wed, 25 Jan 2017 09:16:07 GMT</pubDate></item><item><title><![CDATA[Reply to Powershell commands in Agent config on Wed, 25 Jan 2017 08:07:57 GMT]]></title><description><![CDATA[<p dir="auto">Remember that second argument is regular expression, so certain characters have special meaning. For example, \ is an escape character, so to match it you should specify it as \\. As for class name you're probably right - agent extracts only first 255 characters of process command line. I'll fix that in next release.</p>
<p dir="auto">Best regards,<br />
Victor</p>
]]></description><link>https://forum.netxms.org/post/21742</link><guid isPermaLink="true">https://forum.netxms.org/post/21742</guid><dc:creator><![CDATA[victor]]></dc:creator><pubDate>Wed, 25 Jan 2017 08:07:57 GMT</pubDate></item><item><title><![CDATA[Reply to Powershell commands in Agent config on Wed, 25 Jan 2017 07:59:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/victor" aria-label="Profile: victor">@<bdi>victor</bdi></a> said in <a href="/post/21734">Powershell commands in Agent config</a>:</p>
<blockquote>
<p dir="auto">Hi,</p>
<p dir="auto">just tested in on Windows - works as expected. Please provide exact details - process name and command line and how you specify Process.CountEx parameter.</p>
<p dir="auto">Best regards,<br />
Victor</p>
</blockquote>
<p dir="auto">Thanks for your reply.</p>
<p dir="auto">There are two Java processes running on the agent host.</p>
<p dir="auto">The process I need to monitor has a long command line (700+ chars), mostly consisting of class path declarations and jvm arguments. I can't give the exact details, but it looks basically like this:</p>
<pre><code>"java" -cp "C:\SomePath1\;C:\SomePath2\;C:\SomePath3" -DsomeJvmArg1=someValue1 -DsomeJvmArg2=someValue2 com.domain.package.ClassName --someArg someValue
</code></pre>
<p dir="auto">The above is what comes up when I run the PowerShell command</p>
<pre><code>WMIC path win32_process get Commandline | select-string ClassName
</code></pre>
<p dir="auto">Process.CountEx(java) returns "2" as expected.</p>
<p dir="auto">Process.CountEx(java,ClassName) returns "0". I understand this might be because the command line is longer than the MAX_PATH defined in the source code? Since ClassName appears at the end of the long command line.</p>
<p dir="auto">However:</p>
<p dir="auto">Process.CountEx(java, SomePath1) also returns 0. As does any attempt to match on anything at the beginning of the command line.</p>
<p dir="auto">The Windows host seems to be a 32 bit system.</p>
]]></description><link>https://forum.netxms.org/post/21741</link><guid isPermaLink="true">https://forum.netxms.org/post/21741</guid><dc:creator><![CDATA[MarkusW]]></dc:creator><pubDate>Wed, 25 Jan 2017 07:59:41 GMT</pubDate></item><item><title><![CDATA[Reply to Powershell commands in Agent config on Tue, 24 Jan 2017 18:17:28 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">just tested in on Windows - works as expected. Please provide exact details - process name and command line and how you specify Process.CountEx parameter.</p>
<p dir="auto">Best regards,<br />
Victor</p>
]]></description><link>https://forum.netxms.org/post/21734</link><guid isPermaLink="true">https://forum.netxms.org/post/21734</guid><dc:creator><![CDATA[victor]]></dc:creator><pubDate>Tue, 24 Jan 2017 18:17:28 GMT</pubDate></item><item><title><![CDATA[Reply to Powershell commands in Agent config on Thu, 19 Jan 2017 13:55:14 GMT]]></title><description><![CDATA[<p dir="auto">I see now in the docs that CountEx should be able to match the command line as well. It does not work for me unfortunately.</p>
<p dir="auto">Process.CountEx(java, &lt;Java class name&gt;) still returns 0. Is there some subtle feature here that I'm missing?</p>
<p dir="auto">NetXMS agent version is 2.0.6. Agent is running on a Windows 7 host.<br />
NetXMS server version is 2.0.3.</p>
]]></description><link>https://forum.netxms.org/post/21695</link><guid isPermaLink="true">https://forum.netxms.org/post/21695</guid><dc:creator><![CDATA[MarkusW]]></dc:creator><pubDate>Thu, 19 Jan 2017 13:55:14 GMT</pubDate></item></channel></rss>