Created
August 15, 2018 20:25
-
-
Save JustinGrote/2595843babdccb3e38f91ad64fc34aee to your computer and use it in GitHub Desktop.
Function to retrieve PRTG Device System Information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -module PrtgAPI -version 5 | |
using namespace PrtgAPI | |
function Get-PRTGDeviceSysInfo { | |
<# | |
.SYNOPSIS | |
Retrieve PRTG Device System Information via the (undocumented) API. | |
.EXAMPLE | |
Get-PRTGDeviceSysInfo -ID 13926 | |
Retrieves the system information for the device specified | |
.EXAMPLE | |
Get-Device MyDevice1,MyDevice2 | Get-PRTGDeviceSysInfo -Category Hardware | |
Gets the hardware info for two devices. | |
.NOTES | |
Based on example from Arne Seifert. The XML and JSON come back completely wrong so CSV is the best way to get the information in a structured manner. | |
https://kb.paessler.com/en/topic/67824-how-can-prtg-get-data-for-system-information-tables | |
#> | |
[CmdletBinding()] | |
param ( | |
#ID of the device. You can pass devices via the pipeline to supply this information | |
[Parameter(Mandatory,ValueFromPipelineByPropertyName)][int]$ID, | |
#Which Category of information to retrieve. Defaults to System. | |
[ValidateSet("System","Software","Hardware","LoggedOnUsers","Processes","Services")][String]$Category = "System", | |
#Include RAW values | |
[Switch]$Raw | |
) | |
#region HelperFunctions | |
begin { | |
#Column Definitions | |
$QueryColumns = switch ($Category) { | |
"System" { | |
"_key", | |
"_value" | |
[string[]]$CustomHeader = "Property","Property_RAW","Value","Value_RAW" | |
} | |
"Software" { | |
"_displayname", | |
"_name", | |
"_vendor", | |
"_version", | |
"_date" | |
} | |
"Hardware" { | |
"_displayname", | |
"_name", | |
"_description", | |
"_class", | |
"_caption", | |
"_state", | |
"_serialnumber", | |
"_capacity" | |
} | |
"LoggedOnUsers" { | |
"_displayname", | |
"_domain", | |
"_user" | |
} | |
"Processes" { | |
"_displayname", | |
"_processid", | |
"_caption", | |
"_creationdate"a | |
} | |
"Services" { | |
"_displayname", | |
"_name", | |
"_description" | |
"_startname", | |
"_startmode", | |
"_state" | |
} | |
} | |
#Default Custom Header Generation | |
if (-not $CustomHeader) { | |
[string[]]$CustomHeader = $QueryColumns | foreach { | |
$propertyHeader = $PSItem -replace "^_(.*)",'$1' | |
$propertyHeaderRAW = $propertyHeader + "_RAW" | |
$propertyHeader | |
$propertyHeaderRAW | |
} | |
} | |
} | |
process { | |
write-verbose "Fetching $Category information for device ID $ID" | |
#Build the Query | |
$PrtgClient = Get-PrtgClient | |
$IWRParams = @{ | |
UseBasicParsing = $true | |
Method = "GET" | |
URI = "https://" + $PrtgClient.Server + "/api/table.csv" | |
Body = [ordered]@{ | |
username = $PrtgClient.UserName | |
passhash = $PrtgClient.PassHash | |
id = $ID | |
content = 'sysinfo' | |
category = $Category.ToLower() | |
columns = ($QueryColumns -join ',') | |
} | |
} | |
[string]$result = (Invoke-WebRequest @IWRParams).Content | |
if (-not $result) {write-error "Invalid Result or connectivity issue fetching sysinfo for device ID $ID from $($PrtgClient.Server)"; continue} | |
#The CSV comes back improper, this cleans it up | |
$resultObjects = (($result -split [Environment]::NewLine) | select -skip 1 | ConvertFrom-CSV -Header $CustomHeader) | |
#Strip Raw Values by default, they're basically always the same anyways | |
if (-not $RAW) {$resultObjects = ($resultObjects | select * -ExcludeProperty '*_RAW')} | |
return $resultObjects | |
} | |
} |
Hi, could you please advise the source of PRTGAPI module. I have tried to locate this but have only come across a release that is not the one you are referring to called PRTGAPI at https://github.com/lordmilko/PrtgAPI
Best Regards
Craig
No problem now. I have worked it out. It was the correct module after all.
Regards,
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, could you please advise the source of PRTGAPI module. I have tried to locate this but have only come across a release that is not the one you are referring to called PRTGAPI at https://github.com/lordmilko/PrtgAPI
Best Regards
Craig