Samstag, 15. Juni 2013

Powershell and vCenter Orchestrator Webservice with Output parameters

Hi,
here is the the script you need to get all output parameters of your vCO workflow when you call it from powershell.
Better you paste it into an editor, because it is very long:

$vmName = $args[0]; #to launch the script from commandline with parameters

if(!($vmName)) # if no paramteres are set, ask for it
    {
        $vmName = read-host "Please Enter a Server Name"
    }


[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$username = "VCOadmin"
$password = "VCOpassword"
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))

$webservice = New-WebServiceProxy -uri "http://vcoserver:8280/vmware-vmo-webcontrol/webservice?WSDL"  -Credential $cred
$t = $webservice.getType().namespace

$attributes = New-Object ($t + ".WorkflowTokenAttribute")

$attributes.name = "vmName"
$attributes.value = $vmName
$attributes.type = "String"


#$webservice | Get-member
$wf = $webservice.getWorkflowsWithName("*getHotPlugINfo*","$vmName = $args[0];

if(!($vmName))
    {
        $vmName = read-host "Please Enter ServerName"
    }


$webservice = New-WebServiceProxy -uri "http://VCOserver:8280/vmware-vmo-webcontrol/webservice?WSDL"  -Credential $cred
$t = $webservice.getType().namespace

$attributes = New-Object ($t + ".WorkflowTokenAttribute")

$attributes.name = "vmName"
$attributes.value = $vmName
$attributes.type = "String"

#get all workflows, where the name is like getHotPlugInfo, or what ever your name is
$wf = $webservice.getWorkflowsWithName("*getHotPlugINfo*","VCOadmin","VCOpassword")

#start the vCO workflow by its ID
foreach($i in $wf)

    {
       $infos = New-Object psobject
        if($i.name -eq "getHotplugInfo")
           {
           $resp = $webservice.executeWorkflow($i.id,"VCOadmin","VCOpassword",$attributes)
           $WFid = $resp.id            
           $resp.businessState
           
           do{Start-Sleep -Seconds 2}
           while($webservice.getWorkflowTokenStatus(@($WFid), "VCOadmin","VCOpassword") -eq”running”) #get workflow status until it is finished
           
           $status = $webservice.getWorkflowTokenResult(@($WFid),"VCOadmin","VCOpassword") #get the output parameters of your workflow

                $infos | Add-Member NoteProperty Server $status[0].value
                $infos | Add-Member NoteProperty Memoryhotplug $status[1].value
                $infos | Add-Member NoteProperty CPUHotplug $status[2].value
            
            $infos      
           }
    }

The script is self explaining I think, if you have any questions send me an email.

If you are looking for more information about webservice and vCO visit the vcoportal at http://www.vcoportal.de/

Keine Kommentare:

Kommentar veröffentlichen