Cannot use Invoke-VMScript to configure IP Address

Welcome Forums General PowerShell Q&A Cannot use Invoke-VMScript to configure IP Address

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
2 weeks, 6 days ago.

  • Author
    Posts
  • #126062

    Participant
    Points: 57
    Rank: Member

    Hi,

    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

    Rgds,

    Kishor

  • #126089

    Participant
    Points: 819
    Helping Hand
    Rank: Major Contributor

    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.

You must be logged in to reply to this topic.