Hello, I am attempting a very similar (almost identical) sensor - DFSR Backlog count although my script and approach has been slightly different to overcome the x32 vs x64 Powershell issue.
I am still having issues and would appreciate any help. Thanks
My experience has been that I can get the same script to run via an x32 PowerShell instance as the same user as the Sensor Parent and results are returned in the value:text format expected by PRTG EXE. I have also set the execution policy to Unrestricted for both environments for the PRTG Sensor Parent User Context (which is a Domain Admin service account).
My approach based on other KB articles is to create a sensor that calls a parent Powershell script that PRTG will execute as an x32 instance. it in turn evokes x64 PowerShell instance calling the sensor script.
Please keep in mind that this combination of scripts works 100% outside of PRTG being evoked from a x32 PS interactive Shell as the same user that the sensor parent context. However, IT MUST BE WITH ELEVATED PRIVILEGES. I suspect that PRTG is not doing this and thus all of the errors in the Sensor Debug log are red-herrings and are the result of the lack of elevated privileges.
The FINAL Error I now get is...
The term 'Get-DfsrBacklog' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
However the sensor data log has numerous errors starting with the following.
Import-Module : The specified module 'Microsoft.PowerShell.Management' was not loaded because no valid module file was found in any module directory.
The PARENT PS1 Script called by the Sensor is...
c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -file "C:\tgm\bin\prtg\Custom Sensors\EXE\Get-DFSR-Count.ps1" 10.0.1.44 SVR-DC1
The CHILD PS1 sensor script is as follows...
Param(
$sourceIP=$args[0],
$targetName=$args[1]
)
import-module DFSR
$count = -1
$msg = "Unknown Error"
$computername = [System.Net.Dns]::GetHostByAddress($sourceIP).hostname
$computername = $computername.Replace(".domain.local","")
Try
{
$oDFSBacklog = Get-DfsrBacklog -SourceComputerName $computername -DestinationComputerName $targetName -ErrorAction Stop
$count = $oDFSBacklog.Count
if ($count -eq 0)
{
$msg = "All files have been replicated"
}
else
{
$msg = "Files waiting to be replicated"
}
}
Catch
{
$msg = $_.Exception.Message.SubString(0, 200)
$failedItem = $_.Exception.ItemName
}
"{0}:{1}" -f $count, $msg
Add comment