Powershell 如何使用WMI获取dhcp租约到期时间?

Powershell 如何使用WMI获取dhcp租约到期时间?,powershell,wmi,dhcp,Powershell,Wmi,Dhcp,现在我使用Get-DhcpServerv4Lease-ComputerName'pc'-ScopeId'id'-AllLeases和$object.leaseExpiryTime来获取租约到期时间 但是有可能通过WMI查询获得它吗?请您举个例子。使用,因为它确实包含DHCPLeaseExpires。例如, gwmi -query "select DHCPLeaseExpires, ipaddress, Description from Win32_NetworkAdapterConfigurat

现在我使用
Get-DhcpServerv4Lease-ComputerName'pc'-ScopeId'id'-AllLeases
$object.leaseExpiryTime
来获取租约到期时间

但是有可能通过WMI查询获得它吗?请您举个例子。

使用,因为它确实包含
DHCPLeaseExpires
。例如,

gwmi -query "select DHCPLeaseExpires, ipaddress, Description from Win32_NetworkAdapterConfiguration where dhcpleaseexpires is not null"
# Output
Description      : Intel(R) Dual Band Wireless-AC 8265
DHCPLeaseExpires : 20200604032809.000000+180
IPAddress        : {192.168.1.104, fe80::...}
要将DHCPLeaseExpires转换为.Net日期时间,请从中使用
ManagementDateTimeConverter.ToDateTime(字符串)
。DateTime支持多个类似的


我知道这个方法:
Get WmiObject-query“SELECT*FROM Win32\u networkadapter配置”
,但看起来我无法用它获取到期时间谢谢你的回答。但是如果我得到了更多的参数,那么我需要什么呢?看,我运行了
gwmi-ComputerName dhcp-query“从Win32\u NetworkAdapterConfiguration中选择DHCPLeaseExpires,其中DHCPLeaseExpires不为null”
并得到以下输出:
\u属:2\u类:Win32\u NetworkAdapterConfiguration超类:\u属性\u计数:1\u派生:{}__服务器:_名称空间:_路径:DHCPLeaseExpires:20200603122700.000000+120 PSComputerName
在输出中,您只获得了所需的内容。但是我得到了很多额外的信息。为什么?为了简洁,我省略了那些。将结果传送到
选择对象
,然后选择您需要的任何对象。请您再告诉我一件事好吗。时间的格式是什么——“20200604032809.000000+180”?有没有办法以任何格式将其与(获取日期)进行比较?
$wlan = gwmi -query "select ..."
Add-Type -AssemblyName System.Management
$t = [Management.ManagementDateTimeConverter]::ToDateTime($wlan.DHCPLeaseExpires)
$t.GetType()                                                                            
IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     DateTime                                 System.ValueType

$t.ToString('u')
2020-06-04 03:28:09Z

$t.ToString('G')                                                                        
4.6.2020 3:28:09