Search code examples
wmidhcpwmic

WMIC command for dhcp config win server 2003


I want to remotely config some services like dhcp and dns on windows server 2003 using wmic.

For this goal I using java and connect to wmic on windows server 2003 but I don't know how can I config dhcp via wmic in Windows Server 2003.

What's the command for this purpose?

Thanks in advance


Solution

  • Not sure about Java, but you could do powershell commands with WMIC. If you have Windows Server 2003 SP2 you should be able to install PowerShell 2.

    The command you need is:Get-WMIObject Win32_NetworkAdapterConfiguration

    $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername . | 
    where{$_.IPEnabled -eq $true -and $_.DHCPEnabled -eq $true} 
    Foreach($NIC in $NICs) { 
        $ip = ($NIC.IPAddress[0]) 
        $gateway = $NIC.DefaultIPGateway 
        $subnet = $NIC.IPSubnet[0] 
        $dns = $NIC.DNSServerSearchOrder 
        $NIC.EnableStatic($ip, $subnet) 
        $NIC.SetGateways($gateway) 
        $NIC.SetDNSServerSearchOrder($dns) 
        $NIC.SetDynamicDNSRegistration(“FALSE”) 
    }
    

    Here is M$ reference for the class: https://msdn.microsoft.com/en-us/library/aa394217(v=vs.85).aspx