New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

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

Free PRTG
Download >>

 

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


Powershell (EXE/XML Advanced Sensor) issue

Votes:

0

Your Vote:

Up

Down

Hi all,

I created a powershell script which monitors deduplication stats and the script runs fine for all servers except one. This happens to be the PRTG server itself. If I run the script manually in powershell with all necessary parameters it works flawlessly. Debug output is not very helpful unfortunately.

The Script itself:

param(
	[string]$ComputerName   = '',
	[string]$Username       = '',
    [string]$Password       = ''
)

function This-GenerateCredentials()
{
    $SecPasswd  = ConvertTo-SecureString $Password -AsPlainText -Force
    $Credentials= New-Object System.Management.Automation.PSCredential ($Username, $secpasswd)
    return $Credentials
}  

$results = Invoke-Command -ComputerName $ComputerName -ScriptBlock { Get-DedupVolume | Select-Object Volume, SavingsRate | Sort-Object Volume } -Credential (This-GenerateCredentials)

$xmlOutput = '<?xml version="1.0" encoding="UTF-8" ?><prtg>'

foreach ($result in $results) {
    $xmlOutput = $xmlOutput + "<result><channel>$($result.Volume)</channel><value>$($result.SavingsRate)</value></result>"
}

$xmlOutput = $xmlOutput + "</prtg>"

Out-File -FilePath 'C:\temp\debug.xml' -InputObject $xmlOutput

Write-Host $xmlOutput

The generated debug output when run from PRTG:

<?xml version="1.0" encoding="UTF-8" ?><prtg></prtg>

Any help is highly appreciated...

Kind Regards Matthias

deduplication error exexml powershell

Created on May 15, 2018 1:49:23 PM by  snookerfly (0) 1

Last change on May 16, 2018 4:19:34 AM by  Sven Roggenhofer [Paessler Technical Support]



8 Replies

Votes:

0

Your Vote:

Up

Down

Hey,

what is the error message in PRTG?

Also, did you check "Security Context" for the sensor?

Lukas

Created on May 16, 2018 7:26:11 AM by  Lukas (320) 2 1



Votes:

0

Your Vote:

Up

Down

It's setup as follows (just like the other working DeDup sensors): DeDup Sensor settings

Created on May 16, 2018 8:00:59 PM by  snookerfly (0) 1



Votes:

0

Your Vote:

Up

Down

Did you already try to replace %host with the FQDN of the host? Because when adding it to the local probe device in PRTG, %host will be resolved with 127.0.0.1, which doesn't work with Invoke-Command, as they always require a FQDN for kerberos authentication :)


Kind regards,
Stephan Linke, Tech Support Team

Created on May 17, 2018 7:09:31 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

If sensor result debug (Result of Sensor 3115.Data.txt) is correct then the script is getting called with all the correct parameters. What I'm wondering about is that I don't seem to get an exception of any kind, just an empty xml with no result values...

Data['exeparams'].asString := '-ComputerName 'defalvirt01.shire.loc' -Username 'SHIRE\svc_servacc' -Password '***'';

Created on May 17, 2018 12:14:20 PM by  snookerfly (0) 1



Votes:

0

Your Vote:

Up

Down

Then the $results var is just empty and Invoke-Command doesn't seem to work. You might want to add if/else to catch querying localhost:

if($ComputerName -eq [System.Net.Dns]::GetHostByName(($env:computerName)))
{
  $results = (Get-DedupVolume | Select-Object Volume, SavingsRate | Sort-Object Volume } -Credential (This-GenerateCredentials))
}
else
{
  $results = (Invoke-Command -ComputerName $ComputerName -ScriptBlock { Get-DedupVolume | Select-Object Volume, SavingsRate | Sort-Object Volume } -Credential (This-GenerateCredentials))
}

Created on May 17, 2018 12:33:17 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Tried that in one version of the script already, but tried again anyways:

if($ComputerName.ToLower() -eq [System.Net.Dns]::GetHostByName(($env:computerName)).ToLower()) { $results = (Get-DedupVolume | Select-Object Volume, SavingsRate | Sort-Object Volume ) } else { $results = (Invoke-Command -ComputerName $ComputerName -ScriptBlock { Get-DedupVolume | Select-Object Volume, SavingsRate | Sort-Object Volume } -Credential (This-GenerateCredentials)) }

Same result as before. Also checked with a debug file output, which parameters are passed from PRTG - it's the FQDN and not localhost or 127.0.0.1.

Created on May 17, 2018 12:53:36 PM by  snookerfly (0) 1



Votes:

0

Your Vote:

Up

Down

Does it actually enter the first or second condition?


Kind regards,
Stephan Linke, Tech Support Team

Created on May 18, 2018 8:26:56 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Finally got it working... one of the problems was that Deduplication cmdlets are not availaible for 32bit Powershell. So in the end it's the much simpler script with only Invoke-Command and using the Probe credentials when connecting to the local server.

Created on May 28, 2018 10:39:01 AM by  snookerfly (0) 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.