4.2.1

Table Of Contents
Compare Types
The following JavaScript example checks whether an object matches a given object type.
var path = 'myurl/test';
if(typeof(path, string)){
throw("string");
else {
throw("other");
}
Run a Command in the Orchestrator Server
The following JavaScript example allows you to run a command line on the Orchestrator server. Use the same
credentials as those used to start the server.
NOTE Access to the file system is limited by default. To access the file server from Orchestrator, see “Accessing
the Orchestrator Server File System from JavaScript and Workflows,” on page 111.
var cmd = new Command("ls -al") ;
cmd.execute(true) ;
System.log(cmd.output) ;
File System Scripting Examples
Workflow scripted elements, actions, and policies require scripting of common file system tasks. You can cut,
paste, and adapt these examples into your scripted elements.
NOTE Access to the file system is limited by default. To access the file server from Orchestrator, see “Accessing
the Orchestrator Server File System from JavaScript and Workflows,” on page 111.
Add Content to a Simple Text File
The following JavaScript example adds content to a text file.
var tempDir = System.getTempDirectory() ;
var fileWriter = new FileWriter(tempDir + "/readme.txt") ;
fileWriter.open() ;
fileWriter.writeLine("File written at : "+new Date()) ;
fileWriter.writeLine("Another line") ;
fileWriter.close() ;
Obtain the Contents of a File
The following JavaScript example obtains the contents of a file from the Orchestrator server host machine.
var tempDir = System.getTempDirectory() ;
var fileReader = new FileReader(tempDir + "/readme.txt") ;
fileReader.open() ;
var fileContentAsString = fileReader.readAll();
fileReader.close() ;
Chapter 2 Scripting
VMware, Inc. 115