Contributor
Contributor

Invoke-VMScript Netsh (run as elevated)

Hi all

I am having a problem running a remote netsh command to change the IP, Subnet Mask, Default Gateway and DNS addresses. The script does work if I am logged into the workstation however it doesnt work remotely. I get 'The requested operation requires elevation (Run as administrator).' on the script output. The account that I am executing the script from is in the administrator group.

Here is my script example (data has been changed)

$Username = 'Administrator'

$LocalAdmin = 'Admin'
$Password ='<Hidden>'
$AdminPW = '<Hidden>'
$VMName = 'LANCOMP1'
$AdapterName ='Ethernet0 2'
$IPAddress = '192.168.1.100'
$SubnetMask = '255.255.252.0'
$DefaultGateway = '192.168.1.254'
$CombinedAddresses = $IPAddress + " " + $SubnetMask + " " + $DefaultGateway
$DNS1 = '192.168.1.253'
$DNS2 = '192.168.1.252'

$VC = 'myvcenter.mydomain.net'

#Loads the VMWare Plugin
Get-Command -PSSnapin VMware.VimAutomation.Core
Get-Command -PSSnapin VMware.VimAutomation.Vds

#VC Connection
$VIServer = Connect-VIServer -Server "$VC" -user $Username -Password $Password

$VIServer

#Change NIC Settings using Remote VM SCripting
$IPScript = "netsh interface ipv4 set address ""$AdapterName"" static $CombinedAddresses"
$DNSScript1 = "netsh interface ip add dns ""$AdapterName"" $DNS1 index=1"
$DNSScript2 = "netsh interface ip add dns ""$AdapterName"" $DNS2 index=2"

Invoke-VMScript -VM $VMNAme -ScriptText "$IPScript" -GuestUser $LocalAdmin -GuestPassword $AdminPW
Invoke-VMScript -VM $VMNAme -ScriptText "$DNSScript1" -GuestUser $LocalAdmin -GuestPassword $AdminPW
Invoke-VMScript -VM $VMNAme -ScriptText "$DNSScript2" -GuestUser $LocalAdmin -GuestPassword $AdminPW

Any help would be greatly appreciated.

Thanks

Kev

0 Kudos
3 Replies
Leadership
Leadership

Afaik, the only way around this is to disable UAC.


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

0 Kudos
Contributor
Contributor

I have disabled UAC but doesnt make a difference
0 Kudos
Leadership
Leadership

Did you reboot after you disabled UAC?


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

0 Kudos