用于 dhcp config win server 2003 的 WMIC 命令
WMIC command for dhcp config win server 2003
我想使用 wmic 在 windows 服务器 2003 上远程配置一些服务,如 dhcp 和 dns。
为此,我使用 java 并连接到 windows 服务器 2003 上的 wmic,但我不知道如何在 Windows 服务器 2003 中通过 wmic 配置 dhcp。
用于此目的的命令是什么?
提前致谢
不确定 Java,但您可以使用 WMIC 执行 powershell 命令。如果您有 Windows Server 2003 SP2,您应该能够安装 PowerShell 2。
你需要的命令是: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”)
}
这里是 class 的 M$ 参考:
https://msdn.microsoft.com/en-us/library/aa394217(v=vs.85).aspx
我想使用 wmic 在 windows 服务器 2003 上远程配置一些服务,如 dhcp 和 dns。
为此,我使用 java 并连接到 windows 服务器 2003 上的 wmic,但我不知道如何在 Windows 服务器 2003 中通过 wmic 配置 dhcp。
用于此目的的命令是什么?
提前致谢
不确定 Java,但您可以使用 WMIC 执行 powershell 命令。如果您有 Windows Server 2003 SP2,您应该能够安装 PowerShell 2。
你需要的命令是: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”)
}
这里是 class 的 M$ 参考: https://msdn.microsoft.com/en-us/library/aa394217(v=vs.85).aspx