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)
}
How did you call that Set-WinVMIP function?
Which parameters did you pass?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
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
not sure what happened but when i try to reload the function
. .\set-winvmip.psm1
it does not see or recognize the funtion
Why .psm1, and not .ps1?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ok now I get The request operation requires elevation. (run as administrator)
my guest cred is an administrator
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