Hi,
Need help with script to update/add DNS ip of all esxi host in vcenter. Need to configure three DNS IP's.
Best Regards,
Deepak Koshal
Ok, got it, there was a typo, it said $esxci and it should say $esxcli.
I corrected the script above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
$dnsServers = '192.168.1.2','192.168.1.3','192.168.1.4'
Get-VMHost | %{
$esxcli = Get-EsxCli -VMHost $_ -V2
$esxcli.network.ip.dns.server.list.Invoke() | select -ExpandProperty DNSServers | %{
$sOldDns = @{
server = $_
}
$esxcli.network.ip.dns.server.remove.Invoke($sOldDns)
}
$dnsServers | %{
$sDns = @{
server = $_
}
$esxcli.network.ip.dns.server.add.Invoke($sDns)
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
getting error message :
You cannot call a method on a null-valued expression.
At C:\denverdns.ps1:9 char:5
+ $esxcli.network.ip.dns.server.list.Invoke() | select -ExpandProperty
DNSServ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\denverdns.ps1:29 char:9
+ $esxcli.network.ip.dns.server.add.Invoke($sDns)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
Which PowerCLI version are you running, do a Get-PowerCLIVersion?
And can you show the script your are using, the .ps1 file?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes it is .ps1 script.
Ok, that's an older version, but supports the V2 option.
Can you show your script?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
just replaced the ip with x here.
$dnsServers = 'x.x.x.x','1x.x.x.x','x.x.x.x '
Get-VMHost | %{
$esxci = Get-EsxCli -VMHost $_ -V2
$esxcli.network.ip.dns.server.list.Invoke() | select -ExpandProperty DNSServers | %{
$sOldDns = @{
server = $_
}
$esxcli.network.ip.dns.server.remove.Invoke($sOldDns)
}
$dnsServers | %{
$sDns = @{
server = $_
}
$esxcli.network.ip.dns.server.add.Invoke($sDns)
}
}
Does Get-VMHost actually return any objects?
Are you connected to a vCenter? Check $global:defaultviserver.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Both the command works first list the host and second list the vcenter server.
Ok, got it, there was a typo, it said $esxci and it should say $esxcli.
I corrected the script above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you. It worked.