VMware Cloud Community
tdubb123
Expert
Expert

Invalid address parameter ($IP). It should be valid IPv4 address

tryig to setup static ip on windows VM using alan script. but not working...

 

Function Set-WinVMIP {
     param(
        [string]$VM,

        [string]$IP,

        [string]$SNM,

        [string]$GW,

        [string]$DNS1,

        [string]$DNS2

      )

   

$cmd = @"

netsh interface ip set address "Ethernet0" static $IP $SNM $GW 1"

netsh interface ip add dns name="Ethernet0" source=static addr=$DNS1 register=primary

netsh interface ip add dns name="Ethernet0" source=static addr=$DNS2 index=2

"@

 

invoke-vmscript -scripttext $cmd -scriptType bat -vm $VM -guestcredential (import-clixml .\my.cred)

}
0 Kudos
9 Replies
LucD
Leadership
Leadership

How did you call that Set-WinVMIP function?
Which parameters did you pass? 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tdubb123
Expert
Expert

hi luc

 

set-winvmip -VM myvmname -IP 192.168.0.100 -SNM 255.255.255.0 -GW 192.168.0.1 -DNS1 8.8.8.8 -DNS2 4.4.4.4

0 Kudos
LucD
Leadership
Leadership

Seems to work ok for me.

How and from where do you run that code?
Can you provide a screenshot with the full error mesage?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tdubb123
Expert
Expert

Screen Shot 2022-04-13 at 9.11.03 AM.png

0 Kudos
LucD
Leadership
Leadership

Ok, the error is coming from the script running inside the Guest OS.
For one reason or another the variable substitution on $cmd didn't work.

Try doing it like this

  Invoke-VMScript -ScriptText ($ExecutionContext.InvokeCommand.ExpandString($cmd)) -ScriptType bat -VM $VM -GuestCredential (Import-Clixml .\my.cred)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tdubb123
Expert
Expert

not sure what happened but when i try to reload the function

 

. .\set-winvmip.psm1

 

it does not see or recognize the funtion

0 Kudos
LucD
Leadership
Leadership

Why .psm1, and not .ps1?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tdubb123
Expert
Expert

ok now I get The request operation requires elevation. (run as administrator)

 

my guest cred is an administrator

0 Kudos
LucD
Leadership
Leadership

Then you should probably look at what the UAC settings inside the Guest OS are.

The best bypass is disabling UAC, if that is permitted.

You could also try something like Re: Invoke-VMScript to run ps commands as an admin... - VMware Technology Network VMTN


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos