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

Exchange Powersehll Remote Script

Votes:

0

Dear Support,

i have following Problem:

If i exec this Scritp on the powershell of PRTG Server, everything works fine and i get all Values. But if i Run it with a PRTG Sensor ill get an Error, i wonder why the Script is Executed with the Computer Account of PRTG. OF COurse the XXXX are replaced with the Real Adresses and Server Names

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

param (
[String]$mailbox="xxxxxxxxx"
)

#Exchange 2010 with current user

$ExchangeOrNLBFQDN = "xxxxxx"
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$ExchangeOrNLBFQDN/PowerShell/?SerializationLevel=Full" -Authentication Kerberos 

Import-PSSession $Session -DisableNameChecking -AllowClobber



# Letzer Monat // Variablen mit -Start & -End können nicht in die Remote Session übergeben werden
$CurrentDate = Get-Date
$LastMonth = (($CurrentDate).AddMonths(-1)).ToUniversalTime().Month
$LastMonthYear = (($CurrentDate).AddMonths(-1)).ToUniversalTime().Year
$LastMonthName = $LastMonth | %{(Get-Culture).DateTimeFormat.GetMonthName($_)}
$LastMonthDays = [DateTime]::DaysInMonth($LastMonthYear, $LastMonth)
$StartOfPrevMonth = Get-Date -Month $LastMonth -Year $LastMonthYear -Day 1 -Hour 0 -Minute 0 -Second 0 
$EndOfPrevMonth = ($StartOfPrevMonth).AddMonths(1).AddTicks(-1)


# Abruf des Messagtrackinglogs
$WeekCS = Get-Messagetrackinglog -Server $ExchangeOrNLBFQDN -Recipients $mailbox -Start $StartOfPrevMonth -End $EndOfPrevMonth -ResultSize unlimited -EventID RECEIVE


$InternWeekCS=$WeekCS| where {($_.Sender -like "*@xxxxxx") -or ($_.Sender -like "*xxxxxxxx")}
$ExternWeekCS=$WeekCS| where {($_.Sender -notlike "*x") -and ($_.Sender -notlike "*xxxxxxxx") } 
$AllWeekCS=$WeekCS

$InternCountWeekCS=$InternWeekCS | measure
$InternSumWeekCS14=$InternCountWeekCS.count

$ExternCountWeekCS=$ExternWeekCS | measure
$ExternSumWeekCS14=$ExternCountWeekCS.count

$AllCountWeekCS=$AllWeekCS | measure
$AllSumWeekCS14=$AllCountWeekCS.count

#$AllSumWeekCS14
#$InternSumWeekCS14
#$ExternSumWeekCS14



#write-host "Sending XML Result to STDOUT"

"<prtg>
	<result>
		<channel>Sendcount2</channel>
		<value>$AllSumWeekCS14</value>
		<showChart>1</showChart>
		<showTable>1</showTable>
		<unit>Count</unit>
		<customunit>Mails</customunit>
	    <mode>Absolute</mode>
	</result>
	<result>
		<channel>Sendcount1</channel>
		<value>$InternSumWeekCS14</value>
		<showChart>1</showChart>
		<showTable>1</showTable>
		<unit>Count</unit>
		<customunit>Mails</customunit>
	    <mode>Absolute</mode>
	</result><result>
		<channel>Sendcount</channel>
		<value>$ExternSumWeekCS14</value>
		<showChart>1</showChart>
		<showTable>1</showTable>
		<unit>Count</unit>
		<customunit>Mails</customunit>
	    <mode>Absolute</mode>
	</result>
	
	
	
</prtg>"

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

And here is the Result of the Sensor

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


New-PSSession : [ixxxxxxxt] Beim Verarbeiten von Daten vom 
Remoteserver "xxxxxxxxxxt" ist folgender Fehler aufgetreten: 
Benutzer "xxxxxx/xxxxx/PRTGServer" ist keiner 
Verwaltungsrolle zugewiesen. Weitere Informationen finden Sie im Hilfethema 
"about_Remote_Troubleshooting".
In C:\Program Files (x86)\PRTG Network Monitor\custom 
sensors\EXEXML\GKS14.ps1:8 Zeichen:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange 
-ConnectionUri "h ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:Re 
   moteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : IncorrectProtocolVersion,PSSessionOpenFailed
Import-PSSession : Das Argument fr den Parameter "Session" kann nicht 
berprft werden. Das Argument ist NULL. Geben Sie einen gltigen Wert fr das 
Argument an, und fhren Sie den Befehl erneut aus.
In C:\Program Files (x86)\PRTG Network Monitor\custom 
sensors\EXEXML\GKS14.ps1:10 Zeichen:18
+ Import-PSSession $Session -DisableNameChecking -AllowClobber
+                  ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Import-PSSession], ParameterBi 
   ndingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power 
   Shell.Commands.ImportPSSessionCommand
 
Get-Messagetrackinglog : Die Benennung "Get-Messagetrackinglog" wurde nicht 
als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines 
ausfhrbaren Programms erkannt. šberprfen Sie die Schreibweise des Namens, 
oder ob der Pfad korrekt ist (sofern enthalten), und wiederholen Sie den 
Vorgang.
In C:\Program Files (x86)\PRTG Network Monitor\custom 
sensors\EXEXML\GKS14.ps1:25 Zeichen:11
+ $WeekCS = Get-Messagetrackinglog -Server $ExchangeOrNLBFQDN -Recipients 
$mailbox ...
+           ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-Messagetrackinglog:String)  
   [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
<prtg>
	<result>
		<channel>Sendcount2</channel>
		<value>0</value>
		<showChart>1</showChart>
		<showTable>1</showTable>
		<unit>Count</unit>
		<customunit>Mails</customunit>
	    <mode>Absolute</mode>
	</result>
	<result>
		<channel>Sendcount1</channel>
		<value>0</value>
		<showChart>1</showChart>
		<showTable>1</showTable>
		<unit>Count</unit>
		<customunit>Mails</customunit>
	    <mode>Absolute</mode>
	</result><result>
		<channel>Sendcount</channel>
		<value>0</value>
		<showChart>1</showChart>
		<showTable>1</showTable>
		<unit>Count</unit>
		<customunit>Mails</customunit>
	    <mode>Absolute</mode>
	</result>
	
	
	
</prtg>

exchange powershell remote

Created on Jun 25, 2019 1:01:15 PM

Last change on Jun 25, 2019 2:35:40 PM by  Torsten Lindner [Paessler Support]



4 Replies

Votes:

0

Hello there,

If you want to change the security context for executing the script, you can do so in the script sensor's settings, so that it will be executed using the account configured in "Credentials for Windows Systems" located in the device's "Settings" tab.

Kind regards,

Erhard

Created on Jun 26, 2019 7:15:06 AM by  Erhard Mikulik [Paessler Support]



Votes:

0

Hi Erhard,

thank you for your Reply. Sadly i already tried this and still getting the Same Error

New-PSSession : [ixxxxxxxt] Beim Verarbeiten von Daten vom Remoteserver "xxxxxxxxxxt" ist folgender Fehler aufgetreten: Benutzer "xxxxxx/xxxxx/PRTGServer" ist keiner Verwaltungsrolle zugewiesen. Weitere Informationen finden Sie im Hilfethema "about_Remote_Troubleshooting".

It Seems that PRT is executing the Script with the Computer Account and not wiht the Credentials i did supply, i even used the DOmain Administrator.

Created on Jun 27, 2019 5:41:15 AM



Votes:

0

Hi there,

Did you make sure to enter the regarding credentials in device's "Settings" tab in "Credentials for Windows Systems"?

Open services.msc and check the properties of service "PRTG Probe". Check tab "Log On"/"Anmeldung". Usually it is set to "Local System". Try setting there manually the domain admin to check if it works then.

Kind regards,

Erhard

Created on Jun 27, 2019 6:11:25 AM by  Erhard Mikulik [Paessler Support]



Votes:

4

Hi IgetYaAll,

Your problem likely is the NEW-PSSESSION command - I highly recommend to load credentials from another file and try it this way. The KERBEROS parameter could interfere there as well, but that's another story.

Credentials can be saved in a file and loaded from there - see the following link for details: https://blogs.technet.microsoft.com/robcost/2008/05/01/powershell-tip-storing-and-using-password-credentials/

Of course, in theory this would be a security hole.

If you want to avoid this all together, why don't you just install the Exchange PowerShell extensions to your PRTG probe server or install a remote-probe on the Exchange and have the script execute there? This eventually would avoid the whole struggle with the remote session itself.

Regards

Florian Rossmark

www.it-admins.com

Created on Jun 27, 2019 1:38:28 PM




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.