There's no way to retrieve all types of objects in a single request; instead, you can either iterate over the children of an object, splitting the processing of each object type up via functions, or execute a series of highly specified queries to target the actual objects you're interested in.
If you really wish to loop over all objects, the following code snippet shows an example of how to do this using PrtgAPI, adapted from a script originally designed to generate a "tree" of PRTG's object hierarchy
function ProcessRootChildren()
{
$probes = Get-Probe
foreach($probe in $probes)
{
ProcessProbeChildren $probe
}
}
function ProcessProbeChildren($probe)
{
ProcessContainerChildren $probe
}
function ProcessContainerChildren($parentObj)
{
$filter = flt parentid eq $parentObj.Id
$groups = $filter|Get-Group
foreach($group in $groups)
{
ProcessGroupChildren $group
}
$devices = $filter|Get-Device
foreach($device in $devices)
{
ProcessDeviceChildren $device
}
}
function ProcessGroupChildren($parentObj)
{
ProcessContainerChildren $parentObj
}
function ProcessDeviceChildren($device)
{
$sensors = $device | Get-Sensor
foreach($sensor in $sensors)
{
# Do stuff to sensors
}
}
Most likely though you don't really need to loop over every object, and would be better served executing more specified queries
$groups = Get-Group -Tags newyork
foreach($group in $groups)
{
# Suppose the site code is encoded in the first few letters of the group name
$siteCode = $group.Name.Substring(0, 2)
# etc
}
If you have a CSV of your device names (as displayed in PRTG) that's even better
$csv = Import-Csv C:\servers.csv
foreach($server in $csv)
{
Get-Device $csv.Device | Set-ObjectProperty Host $csv.NewHost
}
Regards,
lordmilko
Add comment