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 fr den Parameter "Session" kann nicht berprft werden. Das Argument ist NULL. Geben Sie einen gltigen Wert fr das Argument an, und fhren 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 ausfhrbaren Programms erkannt. šberprfen 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>
Article Comments
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.
Jun, 2019 - Permalink
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
Jun, 2019 - Permalink
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
Jun, 2019 - Permalink
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
Jun, 2019 - Permalink