Hi,
I am looking at running some powershell on VRO, my syntax is as follows. However I am not sure which powershell action to use or whether I need to have a custom one.
I am currently using VRO, however this script was written for the older version which is VCO
var psScript = ''
//#trap:
psScript +='\ntrap { \n';
psScript +=' foreach ($err in $error) {\n';
psScript +=' write-output $err\n';
psScript +=' }\n'
psScript +=' if ( $session -ne $null) {\n';
psScript +=' remove-pssession -session $session \n';
psScript +=' }\n';
psScript +=' exit 1\n';
psScript +='}\n';
psScript +='$ErrorActionPreference = \'Stop\'\n';
psScript +='import-module sqlps -WarningAction:SilentlyContinue -ErrorAction:Stop \n';
//#create session to targethost:
psScript +='$username = \''+buildaccount+'\'\n';
psScript +="$password = Get-Content '"+buildaccountpwdfile+"' | ConvertTo-SecureString\n";
psScript +='$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$password\n';
psScript +='$session = new-pssession -computerName '+targethost+' -credential $credential -authentication credssp\n';
//obtain server name
psScript +='$sqlserver_server_name = \'select servername from [dbo].[buildlog] where buildno=\'\''+buildno+'\'\'\'\n';
psScript +='$instancename = invoke-sqlcmd -QueryTimeout 30 -ConnectionTimeout 30 -ServerInstance '+buildinstance+' -Database inventory -Query $sqlserver_server_name\n';
psScript += 'get-pssession -ComputerName '+targethost+'| remove-pssession\n';
System.getModule("").executePowershellDirectOnVCOServer(psScript, "Server Identification", null);
System.log(psScript);
I am currently using VRO, however this script was written for the older version which is VCO
If you read the release notes for vRealize Orchestrator 7.0 (VMware vRealize Orchestrator 7.0 Release Notes ) you will see:
VMware vRealize Orchestrator 7.0 is available as a preconfigured virtual appliance. The appliance significantly reduces the time and skills required to deploy vRealize Orchestrator and provides a low-cost alternative to a traditional Windows-based installation.
Is PowerShell installed on the vRO appliance? Based on Microsoft's documentation (Installing PowerShell Core on Linux | Microsoft Docs) it doesn't appear that Suse Enterprise Linux 11 is supported.
My thoughts are:
1) See if the Linux version of PowerShell will install and run on the vRO appliance and then make the necessary changes to 'executePowershellDirectOnVCOServer' or write something from scratch.
.... or ....
2) Leverage the PowerShell vRO plugin to call PowerShell on a remote Windows system. I realize that this is not what you asked about.
A few tips based on my recent experience with PowerShell from vRO
//Get The PowerShell Script from Resource Element (psScript is a workflow attributed linked to a Resource)
var scriptMime = psScript.getContentAsMimeAttachment();//The PowerShell script consists of only function(s) so we concatenate the command we want to execute onto the end
var script = scriptMime.content + "Test-IPv4SubnetUsage -NetworkAddress '" + NetworkAddress + "' -NetworkNumber '" + NetworkNumber + "' -RouterAddress '" + RouterAddress + "'"//Concatenate any conditional parameters
if (StartRange != ""){
script = script + " -StartRange '" + StartRange + "'"
}if (EndRange != ""){
script = script + " -EndRange '" + EndRange + "'"
}//Open session to PowerShell host passing creds from Global Configuration attributes
var session = host.openSessionAs(hostUser, hostPassword);//Execute script and return results
var result = session.invokeScript(script)