VMware Cloud Community
moorthyragav
Contributor
Contributor

invoke-vmscript netsh command requires build-in administrator

$netshDNS2 = "C:\windows\system32\netsh.exe interface ip add dns $NetworkAdapter $DNS2 index=2"

Invoke-VMScript –VM $GuestVMname -guestuser $GuestUsername -guestpassword $GuestUserpwd -ScriptType bat -ScriptText $netshDNS2

In the above script the -guestuser (user name) is the administrator privileged user(the user is in the local administrator Group).

But i getting the error "the requested operation requires elevation (run as administrator)"

we are not able to use build-in administrator account.

Please help on the issue

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

The script you are launching is run under the VMware Tools service, hence the message.

There are a number of ways to run the script in elevated mode in this community.

Did you do a search?


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

Reply
0 Kudos
moorthyragav
Contributor
Contributor

I m using

C:\> $SetIP = "Start-Process powershell -ArgumentList 'C:\windows\system32\netsh.exe interface ip set address $Adapter static $IP $mask $DGW' -verb RunAs"

C:\> Invoke-VMScript –VM $GuestVM  -guestuser $GuestUsername -guestpassword $GuestPassword -ScriptType powershell -ScriptText $SetIP

ScriptOutput

----------------------------------------------------------------------------------------------------------------------------

Start-Process : This command cannot be run due to the error: This operation requires an interactive window station.

|  At line:1 char:4

|  + & {Start-Process powershell -ArgumentList 'C:\windows\system32\netsh.exe interfa ...

|  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

|      + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException

|      + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

|

|

----------------------------------------------------------------------------------------------------------------------------

Is there any other way to  achieve.

Reply
0 Kudos
LucD
Leadership
Leadership

Have a look at the method used in Re: Update DNS

But be aware it requires local administrator account (if UAC is enabled)


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

Reply
0 Kudos