I'm looking for help to do the following: I have hundreds of VM servers, Windows 2003, WIndows 2008 and Windows 2012. Most of these VM are built and pickup a DHCP address which is then "reserved". I do have subnets for clustering and monitoring where the server's IP condiguration is set statically.
I need to....
1. Idenitify all VM servers that are statically configured. Output to a file
2. Use the output to change the Primary and Secondary WINS servers
Thanks in advance.......
Try like this
$wins1 = "1.1.1.1"
$wins2 = "2.2.2.2"
Get-VM | %{
Get-WmiObject -ComputerName $_.Name `
-Query "select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and DHCPEnabled=FALSE" | %{
$_.SetWINSServer($wins1,$wins2)
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You didn't say if all those VMs have the VMware Tools installed.
And the current PowerCLI build doesn't support Windows 2012 for the Get-VMGuestNetworkInterface cmdlet.
An alternative is to use WMI, provided these are all Windows OS VMs.
Something like this
&{Get-VM | %{
Get-WmiObject -ComputerName $_.Name `
-Query "select DNSHostName,IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and DHCPEnabled=FALSE" |
Select DnsHostName,@{N="IP";E={$_.IPAddress -join ','}}
}} | Export-Csv static-ip.csv -NoTypeInformation -UseCulture
Does that work for your VMS ?
If yes, we can use the same WMI interface to change the DNS setting.
Alan has an example in Change DNS and WINS on multiple servers
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, all VMs have VMWare Tools installed. These are all Windows Server VMs. I'm looking to change the WINS Primary and Secondary servers on all server VMs that are statically configured. thanks
If you can reach them with WMI (did you try the script ?), then you also reconfigure them with WMI.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, the script works, I have a test platform with no statically configured servers. Ran the script and the CSV was empty. Statically configured one of the servers, ran the script again and the server was in the CSV
Then you can combine that script with Alan's script to change the DNS servers.
That should do the trick.
Let me know if you need further help with that ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Just one question, how does Alan's script pull the server names from the CSV using your script?
function Set-DNSWINS {
#Get NICS via WMI
$NICs = Get-WmiObject ‘
-Class Win32_NetworkAdapterConfiguration ‘
-ComputerName $_ ‘
-Filter “IPEnabled=TRUE”
foreach($NIC in $NICs) {
$DNSServers = “12.34.5.67″,”76.54.3.21″
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration(“TRUE”)
$NIC.SetWINSServer(“12.34.5.67″, “76.54.3.21″)
}
}
function Get-FileName {
$computer = Read-Host “Filename of computer names?”
return $computer
}
$f = Get-FileName
Get-Content $f foreach {Set-DNSWINS}
Try like this
$wins1 = "1.1.1.1"
$wins2 = "2.2.2.2"
Get-VM | %{
Get-WmiObject -ComputerName $_.Name `
-Query "select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and DHCPEnabled=FALSE" | %{
$_.SetWINSServer($wins1,$wins2)
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This script does both, if I connect to a vCenter server and run the script it changes the WINS servers for only the servers with a static IP address. This is perfect, thank you