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 (EXE/XML Advanced Sensor) issue

Votes:

0

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

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



8 Replies

Votes:

0

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



Votes:

0

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

Created on May 16, 2018 8:00:59 PM



Votes:

0

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

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



Votes:

0

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

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



Votes:

0

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

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




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.