You can create a ZIP package that contains your PowerShell script and dependency modules for use in extensibility actions.
There are two methods of building the script for your extensibility actions:
- Writing your script directly in the extensibility action editor in Automation Assembler.
- Creating your script on your local environment and adding it, with any relevant dependencies, to a ZIP package.
By using a ZIP package, you can create a custom preconfigured template of action scripts and dependencies that you can import to
Automation Assembler for use in extensibility actions.
Note: You do not need to define PowerCLI cmdlets as dependencies or bundle them into a ZIP package. PowerCLI cmdlets come preconfigured with the PowerShell runtime of your
Automation Assembler service.
You can also use a ZIP package to create extensibility actions that contain multiple PowerShell script files. Using multiple script files can be useful for organizing the structure of your extensibility action code.
Prerequisites
Verify that you are familiar with PowerShell and PowerCLI. You can find a Docker image with PowerShell Core, PowerCLI 10, PowerNSX, and several community modules and script examples at Docker Hub .
Procedure
- On your local machine, create a folder for your action script and dependencies.
For example,
/home/user1/zip-action.
- Add your main PowerShell script with a .psm1 extension to the folder.
The following script presents a simple PowerShell function called
main.psm1:
function handler($context, $payload) {
Write-Host "Hello " $payload.target
return $payload
Note: The output of a PowerShell extensibility action is based on the last variable displayed in the body of the function. All other variables in the included function are discarded.
- (Optional) Add a proxy configuration to your main PowerShell script by using
context
parameters. See Using context parameters to add a proxy configuration in your PowerShell script.
- (Optional) Add any dependencies for your PowerShell script.
Note: Your PowerShell dependency script must use the
.psm1 extension. Use the same name for the script and the subfolder where the script is saved.
- Log in to a Linux PowerShell shell.
Note: The runtime of action-based extensibility in
Automation Assembler is Linux-based. Any PowerShell dependencies compiled in a Windows environment might make the generated ZIP package unusable. Any installed third-party dependencies must be compatible with the VMware Photon OS as PowerShell scripts run on Photon OS.
- Navigate to the /home/user1/zip-action folder.
- Download and save the PowerShell module containing your dependencies, by running the Save-Module cmdlet.
Save-Module -Name <module name> -Path ./
- Repeat the previous substep for any additional dependency modules.
- In the assigned folder, select your script elements and, if applicable, your dependency module subfolders and compress them to a ZIP package.
Note: Both your script and dependency module subfolders must be stored at the root level of the ZIP package. When creating the ZIP package in a Linux environment, you might encounter a problem where the package content is not stored at the root level. If you encounter this problem, create the package by running the
zip -r command in your command-line shell.
cd your_script_and_dependencies_folder
zip -r ../your_action_ZIP.zip *
What to do next
Use the ZIP package to create an extensibility action script. See How do I create extensibility actions.