What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Powershell custom sensor and Exchange 2007 problem

Votes:

0

The following script is working on the PRTG server in a power shell without problems but from PRTG (custom sensor) not. Please assist. Thank you.

--------------------------------------

[string]$status = ""
[string]$result = ""

if ($args.count -eq 2) {
	[string]$server = $args[0]
	[string]$queue = $args[1]
	if ($server.Contains(".")) {
		#remove domain part from name
		[string]$queueName = $server.Substring(0, $server.IndexOf(".")) + "\" + $queue
	}
}
else {
	$status = "Missing parameters Server Queue"
}

if ($status -eq "") {
	Try {
		$objItem = Get-Queue -server $server | Where-object {$_.Identity -eq $queueName} | Select-object MessageCount
		if ($objItem -is [Object]) {
			$result = $objItem.MessageCount.ToString()
			$result = $result.Trim()
		}
		else {
			$status = "No results for Server=" + $server + ", Queue=" + $queue
		}
	}
	Catch {
		$status = "Executing Get-Queue Server=" + $server + ", Queue=" + $queueName
	}	
}

if ($status.Length -eq 0) {
	write-host $result, ":OK"
	exit 0
}
else {
	$status = "0:ERROR " + $status
	write-host $status
	exit 1
}

custom exchange powershell

Created on Jan 18, 2011 10:55:01 AM

Last change on Jan 18, 2011 2:38:46 PM by  Torsten Lindner [Paessler Support]



Best Answer

Accepted Answer

Votes:

0

To be able to run Powershell scripts it is necessary to modify the ExecutionPolicy of Powershell from its default 'restricted' value to at least 'remotesigned'. This can be done from a Powershell-prompt with the command: 'Set-ExecutionPolicy RemoteSigned'

Because PRTG is still a 32bit programm it starts the 32bit vorsion of powershell even if you are running a 64bit system.
To enable Powershell-scripting from PRTG on such systems it is necessary to set the execution policy in a different way. Start the Commandline with adminrights and execute the following command:
c:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe "Set-ExecutionPolicy RemoteSigned"

For a complete list and descriptions of the options please refer to http://www.windowsecurity.com/articles/PowerShell-Security.html -> Going behind the defaults

If you are trying to get values via Powershell from a remote machine keep in mind that PRTG is running as a service in the 'system'-context. You can manually set the security context in the sensor settings or use 'New-PSSession' which can connect to the remote machine with alternative credentials.

With kind regards

Created on Jun 25, 2012 2:09:54 PM by  Dieter Loskarn [Paessler Support]

Last change on Jun 25, 2012 3:05:29 PM by  Dieter Loskarn [Paessler Support]



8 Replies

Votes:

0

Hello,

which error do you get in PRTG? Is this a Powershell 1 script? On which Windows is PRTG installed?

Best Regards.

Created on Jan 18, 2011 2:42:53 PM by  Torsten Lindner [Paessler Support]



Votes:

0

Hi,

PRTG Error: "ERROR Executing Get-Queue Server=EXFEVPS01.99eight.com, Queue=EXFEVPS01\Submission" (see Catch in Try statement of above script)

PRTG Server: Windows 2003 SP2 with latest updates, Windows Management Framework and Exchange 2007 Mgmt Tools installed, checked that Exchnage snap-ins are registered

Powershell version: v2

Many thanks, Jurgen

Created on Jan 19, 2011 8:08:55 AM



Votes:

0

Dear Jürgen,

Powershell 2 is not yet supported by PRTG I'm afraid. That is most likely the reason.

Best Regards.

Created on Jan 19, 2011 12:16:27 PM by  Torsten Lindner [Paessler Support]



Votes:

0

Is version 2 of powershell still not supported in the latest version? I would like to run a similar script since exchange 2007/2010 queues are no longer handled by WMI. You guys have to keep the software updated so we can monitor efficiently.

Created on May 24, 2012 10:32:51 PM



Votes:

0

Yes, Powershell v2 is unfortunately still not supported, but seeing as this was the first request for it since over one year, the priority is not very high. Sorry.

Created on May 25, 2012 12:36:20 PM by  Torsten Lindner [Paessler Support]



Votes:

0

Well I am having a similar issue to this. I am running the command "%SystemRoot%\system32\WindowsPowerShell\v1.0\powerShell.exe -PSConsoleFile ""C:\program files\Microsoft\Exchange Server\v14\bin\exshell.psc1" and then running the command Start-Transcript c:\shelloutput.txt; $MessageCount = get-queue -server 01dalsvmowa2 | foreach -begin {$total=0} -process {$total+=$_.messageCount} -end {$total}; exit $MessageCount; Stop-Transcript; from the powershell. It works when I run it manually, but when I go through PRTG it doesn't run at all. I have the same credentials that I used to run manually and everything else looks the same. Any ideas why it wouldn't run correctly?

Created on May 25, 2012 7:22:38 PM



Votes:

0

Maybe running the PRTG Probe Service under your own account does help?

Created on May 28, 2012 9:20:48 AM by  Torsten Lindner [Paessler Support]



Accepted Answer

Votes:

0

To be able to run Powershell scripts it is necessary to modify the ExecutionPolicy of Powershell from its default 'restricted' value to at least 'remotesigned'. This can be done from a Powershell-prompt with the command: 'Set-ExecutionPolicy RemoteSigned'

Because PRTG is still a 32bit programm it starts the 32bit vorsion of powershell even if you are running a 64bit system.
To enable Powershell-scripting from PRTG on such systems it is necessary to set the execution policy in a different way. Start the Commandline with adminrights and execute the following command:
c:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe "Set-ExecutionPolicy RemoteSigned"

For a complete list and descriptions of the options please refer to http://www.windowsecurity.com/articles/PowerShell-Security.html -> Going behind the defaults

If you are trying to get values via Powershell from a remote machine keep in mind that PRTG is running as a service in the 'system'-context. You can manually set the security context in the sensor settings or use 'New-PSSession' which can connect to the remote machine with alternative credentials.

With kind regards

Created on Jun 25, 2012 2:09:54 PM by  Dieter Loskarn [Paessler Support]

Last change on Jun 25, 2012 3:05:29 PM by  Dieter Loskarn [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.