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

Senior Moderator
9 months ago.

  • Author
  • #126062

    Topics: 15
    Replies: 21
    Points: 72
    Rank: Member


    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



  • #126089

    Senior Moderator
    Topics: 8
    Replies: 1008
    Points: 3,275
    Helping Hand
    Rank: Community Hero

    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.

The topic ‘Cannot use Invoke-VMScript to configure IP Address’ is closed to new replies.