SwanseaUni
Enthusiast
Enthusiast

How do i run a simple Powershell script on a machine during deployment in VRA8

we need to run a simple powershell command on machines as they are provisioned, we have tried creating workflows to do this but its saying the powershell applets dont exist ? 

Get-Disk we are using, surely this should be something that is simple to do but we cant get it to run successfully at all ?

prior to vra8 people were saying about using guest tools to do this but this doesnt seem to exist for vra 8 ? the documentation is quite lacking in direction on these things so any advise/help on this matter would be gratefully appreciated 

 

0 Kudos
9 Replies
emacintosh
Enthusiast
Enthusiast

Have you tried using the "Run program in guest" workflow?  I think you can just specify the local path to powershell as the program and the script as arguments.  I could try to come up with a simple example if needed, when I find the time.

How simple is your simple script?

johnbowdre
Enthusiast
Enthusiast

I've been doing this with ABX actions and Invoke-VMScript.

Example: https://github.com/jbowdre/misc-scripts/blob/main/vRealize/configure_guest.ps1

SwanseaUni
Enthusiast
Enthusiast

i will give it a go and let you know, we jsut want to execute a command to install sql server etc 

EugeneZaytsev
Contributor
Contributor

Hey, John!

Is it possible to get the vcenter address or fqdn from the vRA in the ABX code?

0 Kudos
johnbowdre
Enthusiast
Enthusiast

@EugeneZaytsev it seems like it should be but I wasn't able to find a way to do that short of passing it in as a custom property from the cloud template. I put together some notes on how I'm handling it here, in case you're interested.

EugeneZaytsev
Contributor
Contributor

Thanks, @johnbowdre!

0 Kudos
hhc_rleefyi
Contributor
Contributor

I use subscriptions to run Powershell code to install applications, AD work post build. I have found ABX has some issues/limits with Powershell.

I have a Workflow that has several Actions that run Powershell scripts.

One of the custom properties in the subscription is vcUuid which I pass into a workflow which returns the "targetvcenterConnection" (See below), once I have the targetVcenterConnection I use that in my vRO Actions to connect to vCenter using normal PowerCLI.

$vcfqdn $inputs.targetVcenterConnection;
 

Connect-VIServer $vcfqdn -User $vcUser -Password $vcPass -Force;

$vmname = "VMNAME";
$vm = Get-vm -name $vmname;

$script = "yourscript";
$runscript = Invoke-VMScript -VM $vm -ScriptText $script -GuestUser $vcUser -GuestPassword $vcPass -ToolsWaitSecs 300;

You can then check the Exit code

 if($runscript.ExitCode -eq 0)
    {
        $result = 'Complete'
    }
    else
    {
        $result = 'Falied'
    }
 
###### Get vCenter connection by UUID  Workflow ####
### input:string targetVcenterUuid | output:string: targetVcenterConnection ########
##############################################################
var connections = VcPlugin.allSdkConnections;
for (i=0; i<connections.length;i++) {
  if (connections[i].about.instanceUuid == targetVcenterUuid) {
    targetVcenterConnection = connections[i].id;
  }
}
 
 
Hope this helps.
EugeneZaytsev
Contributor
Contributor

@hhc_rleefyiwow, that's cool. One thing I don't get - how do you move from inputProperties.customProperties.vcUuid in the payload to targetVcenterUuid in your workflow?

0 Kudos
hhc_rleefyi
Contributor
Contributor

 $targetVcenterUuid = $inputs.inputProperties.customProperties.vcUuid;
 
 $output=@{'targetVcenterUuid' = $targetVcenterUuid}

 return $output
 
Make sure in the scriptTask you have the targetVcenterUUid in the Outputs.