Embedded PowerShell Scripting
On Windows Collectors, LogicMonitor supports embedded scripting using PowerShell. Although we typically recommend Groovy for most tasks that required scripting, PowerShell is advantageous when you need to monitor Windows-specific metrics that might be accessible only via PowerShell Cmdlets. With some configuration PowerShell can also be used for "Remoting" which allow one to invoke commands on remote systems, which can be useful for some types of metric collection.
Unlike our embedded Groovy scripting functionality, PowerShell scripts are run by the interpreter provided by the underlying OS. Because the underlying features and capabilities vary across versions of Windows, it may be difficult to guarantee complete portability of a PowerShell script. For broad compatibility, we recommend judicious use of the extended PowerShell feature set.
Using Device Properties in PowerShell Scripts
Unlike Groovy, we don't have any seamless way to pass device properties into a PowerShell script. Instead, we can substitute any property into an embedded PowerShell script that is coded as ##DEVICE.PROPERTY##.
Instance properties are not currently supported in PowerShell.
Example - Using PowerShell for Datasource Active Discovery
The following is sample PowerShell code used to perform Scripted Active Discovery. In scripted Active Discovery, the goal is to return instance data of the form:
by printing one instance per line to stdout. In this example, we're going to enumerate the DHCP scopes provided by a Windows DHCP server.
Example - Using PowerShell for Datasource Data Collection
In the above example, we illustrate how to identify the DHCP scopes available on a Windows DHCP server. Next, we'll continue with that same device to get additional data on the IP addresses in each scope.
From here we create four datapoints, and use the key-value post-processor to extract the relevant data with keys "AddressesFree", "AddressesInUse", "PendingOffers", and "ReservedAddress".
See our page on Powershell Tips & Tricks for more examples and sample code.