VMware Cloud Community
mwpreston
Hot Shot
Hot Shot
Jump to solution

Import Workflow with PowerShell

So I've been working on a powershell script to export all of my workflows out of one vCO server and then import them back in to another

I've got the export working great!

That said, can't figure out the code to import back in - wondering if anyone knows how to do so....

$body = "file=$(get-content C:\workflows\ConfigureNTP.zip -raw)"

Invoke-RestMethod -URi $categoryuri -Method POST -body $body -Credential $cred

-ContentType "application/zip" -Headers @{"Content-Disposition"="form-data";"name"="configureNTP";"filename"="configureNTP.zip";}

Keep getting a 415 status - server refused this request because the request entity is in a format not supported by the requested resource for the requested method...

I have no clue Smiley Happy  - but I'm trying Smiley Happy  Just wondering if anyone has accomplished this before with the Invoke-RestMethod cmdlet

Reply
0 Kudos
1 Solution

Accepted Solutions
igaydajiev
VMware Employee
VMware Employee
Jump to solution

This one worked on my PC Smiley Happy

See attached script & sample workflow

.\import-workflow.ps1 -vcoHost xx.xx.xx.xx -user vcoadmin-pass vcoadmin -categoryId 8a978cc84509e09c01450a18f9bc0013 -file C:\Temp\Content_byte1.workflow

View solution in original post

Reply
0 Kudos
6 Replies
mwpreston
Hot Shot
Hot Shot
Jump to solution

and/or curl syntax would do?  And/or vCO javascript syntax Smiley Happy

Reply
0 Kudos
igaydajiev
VMware Employee
VMware Employee
Jump to solution

This one worked on my PC Smiley Happy

See attached script & sample workflow

.\import-workflow.ps1 -vcoHost xx.xx.xx.xx -user vcoadmin-pass vcoadmin -categoryId 8a978cc84509e09c01450a18f9bc0013 -file C:\Temp\Content_byte1.workflow

Reply
0 Kudos
igaydajiev
VMware Employee
VMware Employee
Jump to solution

And sample request should look like so

https://10.23.12.72:8281/vco/api/workflows?overwrite=true

== Headers ==

Authorization                  Basic YWRtaW5pc3RyYXRvcjp2bXdAcmUx                                                                                    

Accept                         application/zip                                                                                                       

Accept-Encoding                gzip,deflate,sdch                                                                                                     

====Body ====

------WebKitFormBoundaryYz07MRfkf3U6aWBB

Content-Disposition: form-data; name="categoryId"

8a978cc84509e09c01450a18f9bc0013

------WebKitFormBoundaryYz07MRfkf3U6aWBB

Content-Disposition: form-data; name="file"; filename="Content_byte1.workflow"

Content-Type: application/octet-stream

binary file content

------WebKitFormBoundaryYz07MRfkf3U6aWBB--


Reply
0 Kudos
mwpreston
Hot Shot
Hot Shot
Jump to solution

You are a savior!!!!!

I had to change line 71 to $file.FullName instead of $file.Name since I wasn't running under the same directory as the workflow exports - but all in all - works perfectly!!!!

$b = [System.IO.File]::ReadAllBytes($file.FullName)

You are awesome!  Thanks so much!  Now I just need to learn what you did Smiley Happy

Thanks so much!  I'm working on a couple of scripts for migration, in which I'll probably end up posting on my blog - none the less I'll post back here and give you the credit due!!!

Thanks again!

Reply
0 Kudos
igaydajiev
VMware Employee
VMware Employee
Jump to solution

Glad to hear that.

Here is also corresponding export-workfow.ps1

In case anyone need it.

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

NOTE: there were a couple minor errors in the export script that I have resolved.

I have added both the import-workflow.ps1 (with updated line 71) and export-workflow.ps1 to my github repository here: http://bit.ly/vroClientScripts

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
Reply
0 Kudos