Hello,

I have a powershell script that looks for some information regarding the state of the backup, how many hours since the last backup.

I tested the script by running it through the PRTG server and it returns the information with the times since the last backup, but in the channel the value is always listed as 0. How do I do to show the hours example 21, only the number 21.

<?xml version="1.0" encoding="UTF-8" ?> <prtg> <result> <channel>Last</channel> <value>22</value> </result> <text>LastBackup</text> </prtg>


Article Comments

Is the script needed to be run under a certain security context? Did you already try to configure the same in the sensor settings so that the administrative credentials of the same are used? What does the script look like?


PRTG Scheduler | PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team


Dec, 2018 - Permalink

The script is not of any additional level of security.

$DEVICE=$args[0]

$BackupStatus = Invoke-Command -Computername $DEVICE -ScriptBlock { Get-WBSummary }

$hlast=(Get-Date)-($BackupStatus.LastBackupTime)

$h1= $($hlast.Hours).ToString()


$output = @"
<?xml version=`"1.0`" encoding=`"UTF-8`" ?>
<prtg>
<result>
<channel>Last</channel>
<value>$($h1)</value>
</result>
<text>Last Backup</text>
</prtg>
"@
Write-Output $output

Dec, 2018 - Permalink

You're not providing any credentials for the Invoke-Command, hence it fails. Check this for more information on the topic.


PRTG Scheduler | PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team


Dec, 2018 - Permalink

I was able to do it differently.

I created a script to export to a text file and I put in the sensor a script that reads this file, so I did not have to raise the level of any credentials.

Thanks for the help and collaboration.


Dec, 2018 - Permalink

Glad it's up and running now :)


PRTG Scheduler | PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team


Dec, 2018 - Permalink