Powershell custom sensor and Exchange 2007 problem

Votes:

0

Your Vote:

Up

Down

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 by  Jürgen R. Weiss (0) 1

Last change on Jan 18, 2011 2:38:46 PM by  Torsten Lindner [Paessler Support] (19,480) 3 1



Best Answer

Accepted Answer

Votes:

0

Your Vote:

Up

Down

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] (1,080) 2 1

Last change on Jun 25, 2012 3:05:29 PM by  Dieter Loskarn [Paessler Support] (1,080) 2 1



8 Replies

Votes:

0

Your Vote:

Up

Down

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] (19,480) 3 1



Votes:

0

Your Vote:

Up

Down

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 by  Jürgen R. Weiss (0) 1



Votes:

0

Your Vote:

Up

Down

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] (19,480) 3 1



Votes:

0

Your Vote:

Up

Down

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 by  willn (0) 1



Votes:

0

Your Vote:

Up

Down

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] (19,480) 3 1



Votes:

0

Your Vote:

Up

Down

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 by  willn (0) 1



Votes:

0

Your Vote:

Up

Down

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] (19,480) 3 1



Accepted Answer

Votes:

0

Your Vote:

Up

Down

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] (1,080) 2 1

Last change on Jun 25, 2012 3:05:29 PM by  Dieter Loskarn [Paessler Support] (1,080) 2 1



Please log in or register to enter your reply.


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.

PRTG
Network Monitor
Intuitive to Use.
Easy to manage.

150.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Visit
www.paessler.com

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

Top Tags


View all Tags