Share via


Monitor DHCP Server Statistics via WMI

Question

Tuesday, December 15, 2015 3:10 PM

Hi All,

I am trying to monitor DHCP scopes via WMI.
I've found only this name space that provides useful DHCP information: root\microsoft\windows\dhcp
The class that I'm looking at is PS_DhcpServerv4Scopestatistics.

The below string is retrieving info about all Scopes:
(gwmi -ClassName PS_DhcpServerv4Scopestatistics -Namespace root\microsoft\windows\dhcp -list).get().cmdletoutput

However, due to a monitor tool that we are using, I am restricted to use WQL queries for WMI:
Get-WmiObject -Namespace ROOT\Microsoft\Windows\DHCP -Query 'select * from PS_DhcpServerv4Scopestatistics'
Unfortunately, this command doesn't return anything (I used "list" parameter in the first command)

Could you please advise, how can I get DHCP Server Statistics from WMI using WQL queries?

Thanks for your help!

All replies (2)

Tuesday, December 15, 2015 3:32 PM ✅Answered

Here's the progress of commands I wrote to pull back some information. At no point did I need to specify the -Filter or -Query parameter (the two parameters that run the WMI Query Language [WQL]). Will these help?

Get-WmiObject -Namespace ROOT\Microsoft\Windows\DHCP -List

Get-WmiObject -Namespace ROOT\Microsoft\Windows\DHCP -List | Where-Object Name -eq 'PS_DhcpServerv4ScopeStatistics'

(Get-WmiObject -ComputerName DHCPSERV01 -Namespace ROOT\Microsoft\Windows\DHCP -List | Where-Object Name -eq 'PS_DhcpServerv4ScopeStatistics').Get()

(Get-WmiObject -ComputerName DHCPSERV01 -Namespace ROOT\Microsoft\Windows\DHCP -List | Where-Object Name -eq 'PS_DhcpServerv4ScopeStatistics').Get() | Select-Object -ExpandProperty cmdletOutput

(Get-WmiObject -ComputerName DHCPSERV01 -Namespace ROOT\Microsoft\Windows\DHCP -List | Where-Object Name -eq 'PS_DhcpServerv4ScopeStatistics').Get() | Select-Object -ExpandProperty cmdletOutput | Select-Object __SERVER,ScopeId,SuperscopeName,AddressesInUse,AddressesFree

(Get-WmiObject -ComputerName DHCPSERV01 -Namespace ROOT\Microsoft\Windows\DHCP -List | Where-Object Name -eq 'PS_DhcpServerv4ScopeStatistics').Get() | Select-Object -ExpandProperty cmdletOutput | Select-Object __SERVER,ScopeId,SuperscopeName,AddressesInUse,AddressesFree,PercentageInUse | Format-Table -AutoSize

Edit: Typo that needed to be corrected.


Wednesday, January 16, 2019 3:20 PM

Moved to DHCP forum.  Ignore the extra message as it was moved badly by the software.

WMIC is not a PowerShell script.  It is a system utility.

\(ツ)_/