WMI and Network Adapters: 10
Posted by: Richard Siddaway
In episode 10 we saw how to renew the lease of a DHCP enabled NIC. What about dropping the lease all together?
Lets go back to the NIC we are experimenting on.
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′" | gm -MemberType method
show us that we have a ReleaseDHCPLease method.
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′" | select *dhcp
shows
DHCPLeaseExpires : 20101009175810.000000+060
DHCPLeaseObtained : 20101008175810.000000+060
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′" |
Invoke-WmiMethod -Name ReleaseDHCPLease
We can then try
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′" | select *dhcp
which gives us
DHCPLeaseExpires : 20101009175810.000000+060
DHCPLeaseObtained : 20101008175810.000000+060
Huh? If you check your NIC the lease has been released but the information WMI holds doesn’t get updated. Woops. Need to be careful of that one.
To generate a new lease we use the same method as episode 9
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′" |
Invoke-WmiMethod -Name RenewDHCPLease
A return code of 0 indicates success and we can test the lease
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′" | select *dhcp
DHCPLeaseExpires : 20101009192845.000000+060
DHCPLeaseObtained : 20101008192845.000000+060




