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


Article Comments

Hey,

what is the error message in PRTG?

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

Lukas


May, 2018 - Permalink

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


May, 2018 - Permalink

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


May, 2018 - Permalink

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 '***'';


May, 2018 - Permalink

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))
}


May, 2018 - Permalink

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.


May, 2018 - Permalink

Does it actually enter the first or second condition?


Kind regards,
Stephan Linke, Tech Support Team


May, 2018 - Permalink

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.


May, 2018 - Permalink