Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Embed powershell script in workflow

tanja90
7 - Meteor

Hello,

 

I have .xlsb file which has to be converted to .xlsx file so that workflow is able to perform further logic. I have PowerShell script which I would like to embed in workflow, so that it does conversion and creates xlsx file before workflow starts execution. Also, I would like to pass file name as an argument. How can I embed code below in workflow (not import script)?

Here is my script:

$file = 'C:\Users\Test\Desktop\Example'

$xlApp = New-Object -Com Excel.Application
$xlApp.Visible = $false
$xlApp.Workbooks.Open($file + '.xlsb').SaveAs($file, [Microsoft.Office.Interop.Excel.xlFileFormat]::xlOpenXMLWorkbook)
$xlApp.Quit()

 Thank you for your time.

4 REPLIES 4
PhilipMannering
16 - Nebula
16 - Nebula

Hi @tanja90 

 

Why not add the script to run before the Workflow as an Event?

You can click the Canvas > Workflow - Configuration Events > Add > Run Command...

PhilipMannering_0-1606921111340.png

 

tanja90
7 - Meteor

Hi @PhilipMannering 

 

Thank you for your reply. 

 

Here is the thing... the workflow will be upload on client's server and client will run this workflow. I'm trying to avoid uploading script to the server which is not under my control - in other words I'm avoiding submitting tickets, explanations, etc. That's why I was hoping it will be possible to embed code directly in workflow. 

 

 

tanja90
7 - Meteor

In case somebody else needs the script code embedded in command line, do as @PhilipMannering suggested but instead importing script do the following:

 

Command: powershell

Command Arguments:

"$file = 'C:\Users\Test\Desktop\Example;$xlApp = New-Object -Com Excel.Application;$xlApp.Visible = $false;$xlApp.Workbooks.Open($file + '.xlsb').SaveAs($file, [Microsoft.Office.Interop.Excel.xlFileFormat]::xlOpenXMLWorkbook);$xlApp.Quit()"

Put double quotes and separate lines with ;

Note that this is not good approach in case you will reuse the script or there is a lot of code..

 

Zaruba_6
6 - Meteoroid

I am leveraging the events feature to open a connection to an external db.  Is there a way to ensure the connection stays in tact while the full workflow runs?  I seem to be connecting but the workflow is not kicking off until I disable the powershell script that is running the command to enable the db connection.  

Labels