This cmdlet runs a script in the guest OS of each of the specified virtual machines. To run Invoke-VMScript, the user must have read access to the folder containing the virtual machine and a Virtual Machine.Interaction.Console Interaction privilege. The virtual machines must be powered on and have VMware Tools installed. Network connectivity to the ESX system hosting the virtual machine on port 902 must be present. To authenticate with the host or the guest OS, one of the HostUser/HostPassword (GuestUser/GuestPassword) pair and HostCredential (GuestCredential) parameters must be provided. The guest account you use to authenticate with the guest operating system must have administrator's privileges. This cmdlet supports only Windows XP 32bit SP3, Windows Server 2003 32bit SP2, Windows Server 2003 64bit SP2, Windows 7 64bit, Windows Server 2008 R2 64bit and Redhat Enterprise 5 operating systems.

To run this cmdlet against vCenter Server/ESX/ESXi versions earlier than 5.0, you need to meet the following requirements:
*You must run the cmdlet on the 32-bit version of Windows PowerShell.
*You must have access to the ESX that hosts the virtual machine over TCP port 902.
*For vCenter Server/ESX/ESXi versions earlier than 4.1, you need VirtualMachine.Interact.ConsoleInteract privilege. For vCenter Server/ESX/ESXi 4.1 and later, you need VirtualMachine.Interact.GuestControl privilege.

To run this cmdlet against vCenter Server/ESXi 5.0 and later, you need VirtualMachine.GuestOperations.Modify and VirtualMachine.GuestOperations.Execute privileges.

Parameters

Name

Type

Description

Required?

Pipeline Input

Default Value

ScriptText

String

Provides the text of the script you want to run. You can also pass to this parameter a string variable containing the path to the script.

Specifies the virtual machines on whose guest operating systems you want to run the script.

true

true (ByValue)

Confirm

SwitchParameter

If the value is $true, indicates that the cmdlet asks for confirmation before running. If the value is $false, the cmdlet runs without asking for user confirmation.

false

false

$true

GuestCredential

PSCredential

Specifies a PSCredential object containing the credentials you want to use for authenticating with the virtual machine guest OS.

false

false

GuestPassword

SecureString

Specifies the password you want to use for authenticating with the virtual machine guest OS.

false

false

GuestUser

String

Specifies the user name you want to use for authenticating with the virtual machine guest OS.

false

false

HostCredential

PSCredential

Specifies a PSCredential object containing the credentials you want to use for authenticating with the host. You need to specify host credentials only if the version of the vCenter Server or ESX you are authenticating with is earlier than 4.0, or the VIX version you have installed is earlier than 1.10.

false

false

HostPassword

SecureString

Specifies the password you want to use for authenticating with the host. You need to specify host credentials only if the version of the vCenter Server or ESX you are authenticating with is earlier than 4.0, or the VIX version you have installed is earlier than 1.10.

false

false

HostUser

String

Specifies the user name you want to use for authenticating with the host. You need to specify host credentials only if the version of the vCenter Server or ESX you are authenticating with is earlier than 4.0, or the VIX version you have installed is earlier than 1.10.

false

false

RunAsync

SwitchParameter

Indicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter run "help About_RunAsync" in the vSphere PowerCLI console.

Specifies the type of the script. The valid values are PowerShell, Bat, and Bash. If the virtual machine OS is Windows, the default value is PowerShell. If the virtual machine OS is Linux, the default value is Bash.

Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of Connect-VIServer.

false

false

ToolsWaitSecs

Int32

Specifies how long in seconds the system waits for connecting to the VMware Tools. The default value is 20.

false

false

20

WhatIf

SwitchParameter

Indicates that the cmdlet is run only to display the changes that would be made and actually no objects are modified.

Runs a PowerShell script. In PowerShell, to access environment variables, you must use the following syntax: $env:<environment variable> (for example, $env:ProgramFiles). Also, to run the program, you must specify an ampersand (&) in front of the program path.
The outer quotes ($script = '...') are required because this is how you define a string variable in PowerShell. The inner double quotes are required because there are spaces in the path.