PowerShell for Windows Admins

Oct 6 2010   2:53PM GMT

WMI and Network Adapters: 9



Posted by: Richard Siddaway
Network, PowerShell v2

We have seen how to test if a NIC is DHCP enabled but what about manipulating the DHCP settings.  First off lets look at renewing a DHCP lease.

We can see the lease information

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′"  | select *dhcp*

The important properties are:

DHCPEnabled       : True
DHCPLeaseExpires  : 20101007180829.000000+060
DHCPLeaseObtained : 20101006180829.000000+060

The system can be told to get a new lease by using the RenewDHCPLease method

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′"  |

Invoke-WmiMethod -Name RenewDHCPLease

We can then test the lease again

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index=’11′"  | select *dhcp*

DHCPEnabled       : True
DHCPLeaseExpires  : 20101007214733.000000+060
DHCPLeaseObtained : 20101006214733.000000+060

Job done

Comment on this Post

Leave a comment: