How to use a Rocky Linux PowerShell Host with VCF Automation Orchestrator. Linux ❤️ PowerShell!
Streamline VMware Automation with VCF Automation, a Rocky Linux PowerShell host, custom workflows, and the simplicity of PowerCLI.
I like using PowerShell on Linux in my Lab:
In most cases, a PowerShell Host for VCF Automation Orchestrator is set up on a Windows Server, which works seamlessly. Having spent much of my career working with Microsoft Windows Server, I’m well-versed in its capabilities. However, in my lab, where resource efficiency is a priority, I prefer to run Linux VMs whenever possible. I keep these Linux VMs lean and mean for maximum performance.
I set out to explore how a Rocky Linux VM could function as a PowerShell Host. By default, VCF Automation Orchestrator includes a workflow called “Run SSH Command”, designed to execute SSH commands on a server. I began testing with this built-in workflow and customized it to better align with my requirements.
To keep the setup simple, I wanted to create a single workflow where I could specify the PS script path and name. The Linux VM details—such as hostname, username, password, and port—would remain static.
For 2025, I’ve been invited to be a VMware Community {code} Coach! This year, my blogs will feature even more code examples to help others get started with automation, VMware solutions, and much more…
Running PowerShell from the CLI and Executing a Script:
Click arrow to expand the PowerShell code:
1
2
3
4
pwsh -file /home/administrator/Home-Lab-PS.ps1
# If you want to use Script Parameterspwsh -file /home/administrator/Home-Lab-PS.ps1 -vmName "VM-01" -PowerState "On"
varsession=null;try{if(port){session=newSSHSession(hostNameOrIP,username,port);}else{System.log("A port value is not provided! Using default port 22");session=newSSHSession(hostNameOrIP,username);}if(passwordAuthentication){System.log("Connecting with password");}else{if(path==null||path==""){System.log("using default");path=defaultKeyPairPath;}System.log("Connecting with key pair ("+path+")");password=passphrase;}session.connectWithPasswordOrIdentity(passwordAuthentication,password,path);System.log("Connected!");System.log("Executing '"+cmd+"' using encoding '"+(encoding?encoding:"Default System Encoding")+"'");session.setEncoding(encoding);session.executeCommand(cmd,true);output=session.getOutput();System.log("Output: '"+output+"'");}catch(e){throw"Unable to execute command: "+e;}finally{if(session){session.disconnect();}}
# Ensure required modules are installed before proceeding$requiredModules=@("powershell-yaml","VMware.PowerCLI")foreach($modulein$requiredModules){if(-not(Get-Module-ListAvailable-Name$module)){Write-Host"$module is not installed. Install it using 'Install-Module $module'."-ForegroundColorRedexit}}# Read YAML configuration$cfgFile="Home-Lab-Config.yaml"$cfg=Get-Content-Path$cfgFile-Raw|ConvertFrom-YamlWrite-Host"Executing Script"# Connect to vCenterWrite-Host"Connecting to vCenter..."try{$credential=New-ObjectPSCredential($cfg.vCenter.username,(ConvertTo-SecureString$cfg.vCenter.password-AsPlainText-Force))$vCenter=Connect-VIServer-Server$cfg.vCenter.server-Credential$credential-ForceWrite-Host"Running commands..."$vmNames=Get-VM|Select-ObjectName,PowerState|Sort-ObjectName$vmNames.NameDisconnect-VIServer-Server*-Confirm:$falseWrite-Host"Disconnecting from vCenter..."return"Script Completed"}catch{Write-Host"An error occurred: $_"return"Error: $_"}
VCF Automation Catalog with an Option to run the Orchestrator Workflow that was created to run the script on Rocky Linux
Click to see Larger Image of Screen Shot
Orchestrator Workflow as a Catalog Item
This is a simple example to give you ideas. The script that will run could bascially Automate anything
Script Parameters become fields on a custom form
If you can write a script for the process, you can Automate it with Orchestrator
Click to see Larger Image of Screen Shot
Install PowerShell on Rocky Linux:
Click arrow to expand the PowerShell code:
1
2
3
4
5
6
7
8
9
10
11
12
13
# Install PowerShell on Rocky Linuxsudo dnf install -y powershell
# Ensure OpenSSH is installed and runningsudo dnf install -y openssh-server
sudo systemctl enable --now sshd
# Create a PowerShell subsystem entry in the SSH daemon configecho"Subsystem powershell /usr/bin/pwsh -sshs -NoProfile"| sudo tee -a /etc/ssh/sshd_config
# Restart the SSH servicesudo systemctl restart sshd
Lessons Learned:
If you like to use Linux for Servers, this is a good use case for running PowerShell scripts
If you have existing PowerShell scripts that run on a Windows Server, most scripts should run on Linux with little to no modifications
I enjoy bringing consistency to my scripts by leveraging a YAML file, similar to the approach used in automation platforms I work with
All the scripts in this blog were created and tested on a Mac using PowerShell
Don’t dismiss PowerShell just because it was created by Microsoft. Embrace it to enhance your automation journey!
Info
In my blogs, I often emphasize that there are multiple methods to achieve the same objective. This article presents just one of the many ways you can tackle this task. I’ve shared what I believe to be an effective approach for this particular use case, but keep in mind that every organization and environment varies. There’s no definitive right or wrong way to accomplish the tasks discussed in this article.
Lab
Always test new setups and processes, like those discussed in this blog, in a lab environment before implementing them in a production environment.
Tips and Tricks
If you found this blog helpful, consider buying me a coffee to kickstart my day.