Script execution through the vCenter server: Service details

Ops Center Automator User Guide

Version
10.8.x
File Size
3.6 MB
Audience
anonymous
Part Number
MK-99AUT001-14

This service template functions in the VMware vSphere environment to transmit the specified non-interactive script file from the target server to the guest OS on the virtual server through the vCenter server, and then runs the script file on the guest OS. The script file can be deleted if it is no longer needed.

The following is an overview of the processing:

  1. Run the PowerCLI commandlet Copy-VMGuestFile on the target server to transmit the specified script from the target server to the guest OS on the virtual server.
  2. Run the PowerCLI commandlet Invoke-VMScript on the target server to run the script transmitted in (1). Then, run the scripts on the virtual server by using the following codes.

    Windows batch file (extension .bat):

    "& 'script-file-path-on-the-guest-OS-(vmware.scriptFileOnGuest-property)' 'script-argument-(vmware.scriptParameter-property)' ; exit $LASTEXITCODE"

    Windows PowerShell script (extension .ps1):

    "Set-ExecutionPolicy RemoteSigned -Scope Process ; & 'script-file-path-on-the-guest-OS-(vmware.scriptFileOnGuest-property)' 'script-argument-(vmware.scriptParameter-property)' ; exit $LASTEXITCODE"

    Shell script (extension .sh):

    "/bin/bash 'script-file-path-on-the-guest-OS-(vmware.scriptFileOnGuest-property)' 'script-argument-(vmware.scriptParameter-property)' "

    The standard output and standard error output of each script run on the virtual server is stored in the file on the target server that is specified as the output file path (vmware.scriptOutputFilePath property) of the script.

  3. If yes is specified for whether to delete the script (vmware.deleteScriptEnabled property), the script transmitted from the target server to the guest OS on the virtual server can be deleted. To delete the script, use the following code applicable to the virtual server environment.

    Windows-based OS:

    "Remove-Item -LiteralPath 'script-file-path-on-the-guest-OS-(vmware.scriptFileOnGuest-property)' -Force "

    Linux OS:

    "/bin/rm -f 'script-file-path-on-the-guest-OS-(vmware.scriptFileOnGuest-property)' "

Server requirements

The following servers are needed:

  • 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 run by this product.

  • Virtual server

    Virtual server that is managed by the vCenter server and VMware vSphere ESX.

Prerequisites

  • VMware vSphere ESXi must be managed by VMware vCenter Server.
  • Conditions related to the settings on VMware vCenter Server:
    • Virtual servers must have a unique name.
    • Server names are case-sensitive in VMware, but not in the vSphere PowerCLI instance run from this plug-in.
  • Conditions related to the virtual server:
    • The virtual server must be running.
    • If the virtual server OS is a Windows-based OS, Windows PowerShell 2.0 or later must be installed.
    • VMwareTools must be installed on the virtual server.

Software requirements

One of the following is required:

  • VMware vSphere PowerCLI 6.3 Release1, 6.0 Release3, 6.0 Release1
  • VMware PowerCLI 6.5 Release1
  • VMware PowerCLI 6.5.1, 6.5.4
  • VMware PowerCLI 10.1.0, 10.1.1

Usage guidelines

  • If a file with the same name exists in the location specified by the path to the script file on the guest OS (vmware.scriptFileOnGuest property) or the path to the output file for the script (vmware.scriptOutputFilePath property), the existing file is overwritten. If any of the folders specified by the file path do not exist, that folder is created and the file is transmitted. Delete the created folder if it is no longer necessary.
  • If a folder with the same name exists in the location specified by the path to the script file on the guest OS (vmware.scriptFileOnGuest property), the target script file is transmitted and stored in the existing folder without any change to the file name. If this occurs, the script fails and the service ends abnormally.
  • If an error occurs during file transmission, the file that is being transmitted to the virtual server is not deleted automatically. Delete this file if it is not necessary.
  • Do not run interactive scripts that need user entry, or scripts that display a UI and do not end automatically.
  • Do not run this service template on the same virtual server simultaneously.
  • The script specified as the script file on the VMware vCenter control server (vmware.scriptFileOnHost property) is transferred to the guest OS in binary format. Create the script in advance on the guest OS by using executable line break codes and character codes.

Service Definition Properties

The following table lists the properties shown in the Service Definition window.

Note: Consider the following precautions when setting properties:
  • You can specify the following script files for the script file path on the guest OS (vmware.scriptFileOnGuest property): Windows batch file (extension .bat), Windows PowerShell script (extension .ps1), and shell script (extension .sh).
  • When you specify multiple arguments for the script argument (vmware.scriptParameter property), you can separate arguments by using a single-byte comma (,) or single-byte hyphen (-).
Property key Property name Description Required or optional
vmware.targetHost Host name of VMware vCenter control server Specify the host name or IP address of the server (a server with vSphere PowerCLI installed) that will be used to control VMware vCenter. You cannot specify an IPv6 address. R
vmware.vCenterServerName VMware vCenter server name Specify the host name or IP address of the VMware vCenter server. You cannot specify an IPv6 address. R
vmware.userName User name for VMware vCenter Server connection Specify the user name to use when connecting to the VMware vCenter server. R
vmware.password Password for VMware vCenter Server connection Specify the password to use when connecting to the VMware vCenter server. R
vmware.portNumber Port number for VMware vCenter Server connection Specify the port number to use when connecting to the VMware vCenter server (specifically, the port number of the VMware vCenter server's Web service). If you omit this property, the default value of the VMware vCenter server applies. O
vmware.protocol Protocol for VMware vCenter Server connection Specify the protocol to use when connecting to the VMware vCenter server. R

Service Definition and Submit Service Properties

The following table lists the properties shown in the Service Definition window and the Submit Service window.

Property key Property name Description Required or optional
vmware.vmName Virtual server name Specify the name of the virtual server. This name is used to represent the virtual server in VMware vCenter server. It is not used as a host name by the OS. R
vmware.guestOSUserName User name for logging in to the guest OS Specify the user name for logging in to the guest OS. R
vmware.guestOSUserPassword Password for logging in to the guest OS Specify the password for logging in to the guest OS. R
vmware.scriptFileOnHost Script file on the VMware vCenter control server Specify the full path of the script file on the VMware vCenter control server that is the transmission source. R
vmware.scriptFileOnGuest Script file on the guest OS Specify the full path of the script file on the guest OS that is the transmission destination. The script file specified for this property is run after transmission. 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). 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. O
vmware.scriptOutputFilePath Script output file path Specify the full path of the file on the VMware vCenter control server in which the standard output and standard error output of the script are stored. R
vmware.deleteScriptEnabled Whether to delete the script Specify whether to delete the script after execution. If yes is selected, the script is deleted. If no is selected, the script is not deleted. R