5.11.11 Script execution through the vCenter server
Function
In the VMware vSphere environment, executes the non-interactive script that is placed in the guest OS on the virtual server.
The executable scripts are Windows batch files (extension bat), Windows PowerShell scripts (extension ps1), and shell scripts (extension sh).
The script is executed by using the following vSphere PowerCLI commandlet on the execution target server:
Invoke-VMScript -ScriptText "execute-form-of-each-script"
-VM VirtualMachine object#1
-GuestUser "user-name-for-logging-in-to-the-guest-OS-(VMware.guestOSUserName-property)"
-GuestPassword "password-for-logging-in-to-the-guest-OS-(VMware.guestOSUserPassword-property)"
-Confirm:$false#2
#1: Object obtained from the virtual server name (VMware.vmName property) value
#2: This prevents the commandlet from becoming interactive.
For each script, specify the execute form described below in the ScriptText option.
- Windows batch file (extension bat)
"&'path-to-the-script-file-on-the-guest-OS-(VMware.scriptFileOnGuest-property)' 'script-argument-(VMware.scriptParameter-property)' ; exit $LASTEXITCODE"
- Windows PowerShell script (extension ps1)
"Set-ExecutionPolicy RemoteSigned -Scope Process ; & 'path-to-the-script-file-on-the-guest-OS-(VMware.scriptFileOnGuest-property)' 'script-argument-(VMware.scriptParameter-property)' ; exit $LASTEXITCODE"
- Shell script (extension sh)
"/bin/bash 'path-to-the-script-file-on-the-guest-OS-(VMware.scriptFileOnGuest-property)' 'script-argument-(VMware.scriptParameter-property)' "
The standard output and standard error output of each script executed on the virtual server are stored in the file on the execution target server that is specified as the script output file path (VMware.scriptOutputFilePath property).
The return value (ExitCode property) of the Invoke-VMScript commandlet is obtained and output as the return value of the script (common.scriptReturnCode property). If a value other than 0 is output as the return value of the script, the plug-in ends with an error. If the plug-in ends with an error before the script is executed, 255 is output as the return value of the script (common.scriptReturnCode property). Do not use 255 as the return value of the script.
If you are using multiple arguments (VMware.scriptParameter property) in the script, you can use a single-byte comma (,) or a single-byte hyphen (-) to delimit one argument from another. For the argument delimiter of the script (VMware.scriptParamDelimiter property), enter a symbol to be used as the delimiter. A single-byte comma (,) or a single-byte hyphen (-) can be used.
Example: Argument of the script is AAA,BBB,CCC
Argument delimiter of the script is comma (,)
-> " & XXX.bat 'AAA' 'BBB' 'CCC' ; exit $LASTEXITCODE"
The following servers are the prerequisites for this plug-in:
- vCenter server
Server where VMware vCenter Server is installed.
- ESX server
Server where VMware vSphere ESXi is installed.
- vCenter control server (execution target server)
Server where VMware vSphere PowerCLI is installed. Plug-ins are transferred to this server and executed by JP1/AO.
- Virtual server
Virtual server that is managed by the vCenter server and VMware vSphere ESXi.
For details about the Invoke-VMScript commandlet, see Cmdlet Reference in the vSphere PowerCLI Documentation.
Use situation
This plug-in is used to execute the script file for specifying the initial OS settings from the vCenter control server through the vCenter server in an environment where the JP1/AO server cannot communicate with the virtual server managed by the vCenter server.
Use this plug-in together with file transmission through the vCenter server (vsphereSendFileToGuest plug-in) and file deletion through the vCenter server (vsphereDeleteFileOnGuest plug-in) or with folder transmission through the vCenter server (vsphereSendFolderToGuest plug-in) and folder deletion through the vCenter server (vsphereDeleteFolderOnGuest plug-in).
Prerequisites
For the most recent information about the prerequisite products for the system, prerequisite products for the execution-target server, and the supported OSs for the prerequisite products for the execution-target server, see the Release Notes.
Prerequisite products for the system:
JP1/Automatic Operation 11-10 or later
Prerequisite products for the execution-target server:
- VMware vSphere PowerCLI 6.3 Release 1, 6.0 Release 3, 6.0 Release 1, 5.8 Release 1, 5.5 Release 2, 5.5 Release 1, 5.1 Release 2, and 5.0
- VMware PowerCLI 6.5 Release1
- VMware PowerCLI 6.5.1, 6.5.4
- VMware PowerCLI 10.1.0, 10.1.1, 11.3.0, 12.0.0, 12.1.0
Prerequisite products for the execution-target system:
(1) Prerequisite products for the vCenter server
- VMware vCenter Server 7.0, 6.7, 6.5, 6.0, 5.5, 5.1, and 5.0
(2) VMware vSphere ESXi instance that manages the virtual server
- VMware vSphere ESXi 7.0, 6.7, 6.5, 6.0, 5.5, 5.1, and 5.0
(3) Prerequisite OSs for the virtual server
In a configuration that is supported by the prerequisite products for VMware vSphere ESXi and the vCenter control server that manage the prerequisite products for the vCenter server and the virtual server, the following OSs are supported:
- Windows Server 2008 R2 Standard/Enterprise/Datacenter
- Windows Server 2012 Standard/Datacenter, Windows Server 2012 R2 Standard/Datacenter
- Windows Server 2016 Standard/Datacenter
- Windows Server 2019 Standard/Datacenter
- Red Hat Enterprise Linux Server 6 (32-bit x86), Red Hat Enterprise Linux Server 6 (64-bit x86_64)
- Red Hat Enterprise Linux Server 7 (64-bit x86_64)
- Red Hat Enterprise Linux Server 8 (64-bit x86_64)
- CentOS 6 (64-bit x86_64)
- CentOS 7 (64-bit x86_64)
- CentOS 8 (64-bit x86_64)
Supported OSs for the prerequisite products for the execution-target server:
- Windows Server 2008 R2 Standard/Enterprise/Datacenter
- Windows Server 2012 Standard/Datacenter, Windows Server 2012 R2 Standard/Datacenter
- Windows Server 2016 Standard/Datacenter
- Windows Server 2019 Standard/Datacenter
Conditions for using the prerequisite products for the execution-target system:
(1) VMware vSphere ESXi must be managed on VMware vCenter Server.
(2) Conditions related to the settings on VMware vCenter Server
- Virtual servers must have a unique name.
- The VMware-related name shown below is case-sensitive in VMware. However, it is not case-sensitive in a vSphere PowerCLI instance that is executed from this plug-in.
- Virtual server name
(3) Conditions related to the virtual server
- The virtual server must be running.
- If the virtual server OS is Windows, Windows PowerShell 2.0 or later must be installed.
- VMwareTools must be installed on the virtual server.
Cautions
(1) Do not specify a string containing a double quotation mark (") or a single quotation mark (') in a property of this plug-in.
(2) Do not specify a string containing a grave accent mark (`) or a dollar sign ($) for the path to the script file in the guest OS (VMware.scriptFileOnGuest property) or for the argument of the script (VMware.scriptParameter property).
(3) If the file designated by the output file path of the script (VMware.scriptOutputFilePath property) already exists, the existing file is overwritten. In addition, if the file path contains a folder that does not exist, the folder is created before the file is output.
(4) For other cautions, see the cautions about the Invoke-VMScript commandlet, which are provided in Cmdlet Reference in the vSphere PowerCLI Documentation.
(5) Do not execute interactive scripts that require user entry, or scripts that display a GUI and do not end automatically.
Execution privilege
(1) Users who access VMware vCenter Server must have the following permission:
System administrator role
Version
02.50.00
Plug-in tags
Modify VM,VMware vSphere
Plug-in name displayed in the task log
vsphereInvokeScript
Return code
0: Normal
12: Error (Mistake by user) Invalid property
23: Error (Invalid environment) The environment requirements are not met.
27: Error (Check the error details by using the task log.) Unidentified error
41: Error (An error has been detected in the component.) Property not entered (An error has been detected in the component script.)
Property list
The following table lists the properties:
Property key |
Property name |
Description |
Default value |
I/O type |
Required |
---|---|---|---|---|---|
plugin.destinationHost |
Host name of the execution target server |
Specify the host name or IP address of the server on which this plugin will be executed. IPv6 addresses are not supported. |
-- |
Input |
R |
VMware.vCenterServerName |
Host name of the vCenter server |
Specify the host name or IP address of the destination vCenter server. IPv6 addresses are not supported. |
-- |
Input |
R |
VMware.userName |
User name for connecting to the VMware vCenter Server |
Specify the user name for connecting to the VMware vCenter Server. |
-- |
Input |
R |
VMware.password |
Password for connecting to the VMware vCenter Server |
Specify the password for connecting to the VMware vCenter Server. |
-- |
Input |
R |
VMware.portNumber |
Port number for connecting to the VMware vCenter server |
Specify the number of the port for connecting to VMware vCenter Server (for the VMware vCenter Server Web service). |
443 |
Input |
O |
VMware.protocol |
Protocol for connecting to the VMware vCenter server |
Specify either HTTP or HTTPS as the protocol for connecting to VMware vCenter Server. |
https |
Input |
R |
VMware.vmName |
Virtual server name |
Specify the name of the virtual server. (This is the virtual server name in VMware vCenter Server. Do not specify a host name.) |
-- |
Input |
R |
VMware.guestOSUserName |
User name for logging in to the guest OS |
Specify the user name for logging in to the guest OS. |
-- |
Input |
R |
VMware.guestOSUserPassword |
Password for logging in to the guest OS |
Specify the password for logging in to the guest OS. |
-- |
Input |
R |
VMware.scriptFileOnGuest |
Script file on the guest OS |
Specify the full path of the script file to be executed on the guest OS. |
-- |
Input |
R |
VMware.scriptParameter |
Script argument |
Specify a script argument. To specify multiple arguments, separate the arguments by using the specified delimiter for script arguments (a single-byte comma or single-byte hyphen). |
-- |
Input |
O |
VMware.scriptParamDelimiter |
Delimiter for script arguments |
Specify a delimiter for script arguments. You can specify a single-byte comma (,) or a single-byte hyphen (-). If this property is omitted, values specified for the script argument are handled as a single argument. |
, |
Input |
O |
VMware.scriptOutputFilePath |
Script output file path |
Specify the full path of the file on the execution target server to which the standard output and standard error output of the script are output. |
-- |
Input |
R |
common.returnValue |
Return value for the plugin |
The return value of this plugin stored. |
-- |
Output |
O |
common.scriptReturnCode |
Script return value |
Stores the return value of the script executed on the virtual server. |
-- |
Output |
O |