Invoke-VMScript: Permission to perform this operation was denied.

During the process of creating an automation tool for a clent, I needed to run few scripts inside the guest virtual machines. To accomplsh the task Invoke-VMscript was a perfect candidate. Invoke-VMScript cmdlet runs a script in the guest OS of each of the specified virtual machines. For more details about the cmdlet, please refer to the link:
https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FInvoke-VMScript.html

However, once tried to run the cmdlet, it failed with the below error:

Invoke-VMScript : YYYY/MM/DD HH:MM:SS AM Invoke-VMScript Permission to perform this operation was denied. Required
privilege ‘VirtualMachine.GuestOperations.Modify’ on managed object with id ‘VirtualMachine’.
At line:2 char:1
+ Invoke-VMScript -VM “VM NAME” -ScriptText “dir” -GuestCredential $guest …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-VMScript], NoPermission
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_RunScriptInGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Invo
keVmScript

invokevmscript_error

SOLUTION:
For the user running the cmdlet, you need to allow access to the Guest Operations priviliges in VCenter as illustrated below:

guest_oper_privs

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s