We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Using Run Command tool to execute PowerShell scirpt

john_dwyer
6 - Meteoroid

I have searched high and low trying to figure out how to output the results for a simple PowerShell script file named Admin.ps1 that contains the cmdlet Get-ADDefualtDomainPasswordPolicy from the Run Command tool to an output tool, in this case the Browse tool.  However, when I do this I get this well documented error.

 

Error 1.JPG

 

All of the solutions I've read indicate you have to identify a Read source when you have a Write Source, even if it’s not technically necessary.  So, in my workflow I made the Admin.ps1 file the read source and now workflow runs and I can see PowerShell opening and running with no error codes returned.

pic2.png

However, what appears in the Browse tool is the Cmdlet found in the Admin.ps1 file.  This is obviously not what I want.  I want to see the results from the Cmdlet.

pic3.png

If anyone can show me how to do this, you're automatically on my Christmas list.

 

 

 

15 REPLIES 15
BS_THE_ANALYST
15 - Aurora
15 - Aurora

Glad to hear @john_dwyer

All the best,

BS

All the best,
BS

LinkedIN

Bulien
curator_at_work
8 - Asteroid

hi buddy
how u created this file _externals\1\PowerShellHelloAndDate.ps1 ?

curator_at_work
8 - Asteroid

hi buddy how u created this .ps1 file that u used in input data tool

curator_at_work
8 - Asteroid

or what you did, first u wrote the script then run it in powershell then u get a txt (storing response from ) file and then you use it as read result in run command, 

or you just wrote the script and didn't run and u directly use in w/f? 

curator_at_work
8 - Asteroid

hi @BS_THE_ANALYST 

I tried to as your purposed solution but getting error

 

1: if i am using "powershell" in command the i get error "

Run Command (1) The external program "powershell" returned an error code: 1"
 
2: if I am leaving command empty then i get error "Can't find the file: "C:\downloads\DriveContent9_txt.txt". Make sure the file path is correct." its related to input of run command tool. 
 
points: 
1: I write script first in notepad and save it as DriveContent9.ps.ps1 and used it in input data tool
2: in run command the file i use in output and input anchor, I just give it directly into run commnad tool.
BS_THE_ANALYST
15 - Aurora
15 - Aurora

Hi @curator_at_work, I'm definitely not an expert with this Run tool but let's break down what I previously did

Screenshot 2025-02-06 123801.png

 

1) I opened notepad++ and created the script in there. I saved the file as a .ps1 as this was an acceptable extension for a powershell script.

2) I read the script into alteryx using a file input

3) I realised that each line of the script was split out onto a new line in alteryx. Therefore, I used the summarise tool to concatenate all the lines into a single cell (this helped as I wanted to pass this into the run tool)

Screenshot 2025-02-06 124007.png

4) Last step was the Run Command tool. I've got numbers on the picture which I'll explain below

Screenshot 2025-02-06 124118.png

(1) This takes the script from the single cell I created from the summarise tool and outputs it to a file called RandomFile.ps1 in the temporary directory

(2) I want to tell the Run Command I want to use Powershell, so I write "Powershell"

(3) I want Powershell to then run this RandomFile.ps1 I created in step one. So I call on it again! (as it's now been created..)

(4) I display the results in the Alteryx window, although, you don't need this step to be honest:

 

I've reuploaded the example file so you can download it and try it out yourself.

 

Hopefully that gets you further along with the problem at hand.

All the best,
BS

LinkedIN

Bulien
Labels
Top Solution Authors