Hi All
Currently i have a resource pool where the VM's only have one DNS entry
I need to create a script to add the second DNS entry (not change the first one, just leave it as it is)
I have started with the below to connect to VC, take the resouce pool in question and get all the VM's in that resource pool. Then for each VM in vms i will run an invoke vmscript command , does anyone how the syntax to add the second dns server ?
# Connect to vCenter silently
#
try {
Write-Host "Connecting to..." $vCenter -ForegroundColor Yellow
Connect-VIServer -Server $vCenter -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null
if ($? -eq $false) {throw $error[0].exception}
}
catch [Exception]{
exit
}
$rp = Read-Host -Prompt "What Resource Pool do you want to gather information for "
$vms = get-resourcepool -Name $rp | get-vm | where {$_.Powerstate -eq 'Poweredon'}
foreach ($vm in $vms){
invoke-vmscript -vm $vm -ScriptText ......
}
What type of guest OS do you have running in those VMs?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If it concerns guest OS from the Windows family, you could do something like this.
This assumes that the interface inside the guest OS is named 'Local Area Connection' and that there currently only is 1 DNS server configured on that interface.
It also assumes that the credentials under which you run the script have admin access to the guest OS.
$interface = 'Local Area Connection'
$dns2 = '192.168.1.2'
$code = @"
netsh interface ip add dns name="$interface" addr=$dns2 index=2
"@
# Connect to vCenter silently
#
try {
Write-Host "Connecting to..." $vCenter -ForegroundColor Yellow
Connect-VIServer -Server $vCenter -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null
if ($? -eq $false) {throw $error[0].exception}
}
catch [Exception]{
exit
}
$rp = Read-Host -Prompt "What Resource Pool do you want to gather information for "
$vms = Get-ResourcePool -Name $rp | Get-VM | where {$_.Powerstate -eq 'Poweredon'}
foreach ($vm in $vms){
Invoke-VMScript -VM $vm -ScriptText $code -ScriptType Bat
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
they are all windows 2008 / 2012
Thanks ,will give it a try and let you know
