Cannot use Invoke-VMScript to configure IP Address


I am using below commands, changing IP works, but DNS command fails, error ‘unable to connect to remote computer’. I think as IP has changed invoke-vmscript is not able to connect to machine, is there any better way, please advise;

$changingIp = ‘%WINDIR%\system32\netsh.exe interface ipv4 set address name="’ + $adapterName + ‘" source=static address=’ + $newIP + ’ mask=’ + $newMask + ’ gateway=’ + $newGateWay + ’ gwmetric=1 store=persistent’
$cmdDNS = ‘%WINDIR%\system32\netsh.exe interface ipv4 set dnsservers name="’ + $adapterName + ‘" source=static address=’ + $newDNS + ’ index=1’

Invoke-VMScript -VM $vm -ScriptType Bat -ScriptText $changingIp -GuestCredential $serverCredential
Invoke-VMScript -VM $vm -ScriptType Bat -ScriptText $cmdDNS -Verbose -GuestCredential $serverCredential



This won’t be a PowerShell related issue. You can try executing the DNS address setting cmd by logging into the VM once.
when you find a working cmd you can set it via Invoke-VMScript.