< Back

Add-Sensor

Sun Jan 19, 2020 5:40 pm

NAME Add-Sensor



SYNOPSIS

Adds a new sensor to a PRTG Device.





SYNTAX

Add-Sensor [-Parameters] <NewSensorParameters> -Destination <Device> [-Resolve <SwitchParameter>]

[<CommonParameters>]



Add-Sensor -Parameters <NewSensorParameters> [-Resolve <SwitchParameter>] [<CommonParameters>]





DESCRIPTION

The Add-Sensor cmdlet adds a new sensor to a PRTG Device. When adding a new sensor, you must first create a

NewSensorParameters object that defines the type of sensor to create and the settings to use in the new object.



When adding sensor types that are natively supported by PrtgAPI, Add-Sensor will validate that all mandatory

parameter fields contain values. If a mandatory field is missing a value, Add-Sensor will throw an

InvalidOperationException, listing the field whose value was missing. When adding unsupported sensor types defined

in RawSensorParameters, Add-Sensor does not perform any parameter validation. As such, it is critical to ensure

that all parameter names and values are valid before passing the parameters to the Add-Sensor cmdlet.



For parameter types that support specifying multiple SensorTarget objects (such as WmiServiceSensorParameters)

PRTG can fail to add all sensors properly if the size of a single request is too large (generally 60 items or

greater). To prevent this issue from happening, PrtgAPI automatically splits your request into a series of smaller

requests, however if you find yourself experiencing issues, this is something to be aware of.



By default, Add-Sensor will attempt to resolve the created sensor(s) to one or more Sensor objects. As PRTG does

not return the ID of the created object, PrtgAPI identifies the newly created group by comparing the sensors under

the parent object before and after the new sensor(s) are created. While this is generally very reliable, in the

event something or someone else creates another new sensor directly under the target object with the same Name,

that object will also be returned in the objects resolved by Add-Sensor. If you do not wish to resolve the created

sensor, this behavior can be disabled by specifying -Resolve:$false.





PARAMETERS

-Destination <Device>

The parent object to create an object under.



Required? true

Position? named

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



-Parameters <NewSensorParameters>

A set of parameters whose properties describe the type of object to add, with what settings.



Required? true

Position? 0

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



-Resolve <SwitchParameter>

Indicates whether or not the new object should be resolved to a PrtgObject. By default this value is Present.



Required? false

Position? named

Default value True

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

PrtgAPI.Device

The parent object to create an object under.



PrtgAPI.Parameters.NewSensorParameters

A set of parameters whose properties describe the type of object to add, with what settings.





OUTPUTS



---------- EXAMPLE 1 ----------



C:\\> $params = New-SensorParameters ExeXml "Monitor Traffic" "TrafficMonitor.ps1"



C:\\> Get-Device *fw* | Add-Sensor $params



Add an EXE/Script Advanced sensor to all firewall devices, using the script "TrafficMonitor.ps1"



---------- EXAMPLE 2 ----------



C:\\> $raw = @{

>> name_ = "my raw sensor"

>> tags_ = "xmlexesensor"

>> priority_ = 4

>> exefile_ = "CustomScript.ps1|CustomScript.ps1||

>> exeparams_ = "arg1 arg2 arg3"

>> environment_ = 1

>> usewindowsauthentication_ = 1

>> mutexname_ = "testMutex"

>> timeout_ = 70

>> writeresult_ = 1

>> intervalgroup = 0

>> interval_ = "30|30 seconds"

>> errorintervalsdown_ = 2

>> sensortype = "exexml"

>> }



C:\\> $params = New-SensorParameters $raw



C:\\> Get-Device dc-1 | Add-Sensor $params



Add a new EXE/Script Advanced sensor to the device named dc-1 using a hashtable containing its raw parameters.



RELATED LINKS

Online version: https://github.com/lordmilko/PrtgAPI/wi ... n#creation

Get-Device

New-SensorParameters