VMware Cloud Community
fabd
Contributor
Contributor
Jump to solution

Execute powershell script in VCO Workflow

Hi guys,

I'm pretty new to VCO and i'm facing some difficulties to get what i want. For you it will be a basic... but here is my question :

I have a WF that i use in the WFStubmachineprovisionning that can generate me a VM name based on user selection while he ask for a VM in VRA.

The provisionned VM name is like this : W203PKLXXX and i need to replace the XXX by a number that is available on the network.

To do this, i need to query the DNS to check if 001 is available, if not, 002... And so on... until one available, and i send the full VM name to the WF Stubprovisionning.

This my first try to interact between VCO and a Powershell script. I can run PS script on my configured host, but don't know how to send variable from the personalised WF that generate the name to the PS script, and send the VM Name from the PS script to the next step.

Can anyone give me a sample to manage variable ? I didn't find anything around the net

0 Kudos
1 Solution

Accepted Solutions
fabd
Contributor
Contributor
Jump to solution

Just to tell you that i successed.

the PS returned an XML object, not a string. I had to use the javascript property getxml() and parse the string to get the value i need

i also had to blind correctly the output (PS) and input (getxml)

if needed i can send you some screenshoot

View solution in original post

0 Kudos
4 Replies
carl1
Expert
Expert
Jump to solution

Just a suggestion for a completely different solution.  Assuming vRO is the only one creating these VMs, you could use a configuration parameter to keep track of the next VM number to use.  It is by no means complete, but I have attached some sample code that might help you.  That way, you eliminate a lot of dependencies on external systems (which may or may not be up at that point).

Carl L.

0 Kudos
fabd
Contributor
Contributor
Jump to solution

Hi Carl,

Thanks for your reply. But in our case, we already have several thousand of active server that can potentional have a name like the one being provisionned. And we also have physical servers that are manually by my colleague.

0 Kudos
fabd
Contributor
Contributor
Jump to solution

Here is my working PS script that i want to CALL

Clear-Host

$VMname="l000rsy002"

$suffixe=1

Do {

    Try

    {

        Resolve-DnsName "$VMname" -ErrorAction Stop |Out-Null

        $VMstatus="exists"

    }

    Catch

    {

      $VMstatus="available"

    }

    if($VMstatus -eq "exists")

        {

        $VMname=$VMname.Substring(0,7)

        $suffixe=[int]$suffixe+1

        $suffixe="{0:000}" -f $suffixe

        $VMname="$VMname$suffixe"

        }

    }

Until ($VMstatus -eq "available")

Write-Host "$vmname"

So, how to retrieve the $VMname from the WF (line 2)

and how to send the vmname to the next step (line 25)

thanks every one Smiley Happy

0 Kudos
fabd
Contributor
Contributor
Jump to solution

Just to tell you that i successed.

the PS returned an XML object, not a string. I had to use the javascript property getxml() and parse the string to get the value i need

i also had to blind correctly the output (PS) and input (getxml)

if needed i can send you some screenshoot

0 Kudos