Hi there, and welcome back to another Tutorial Tuesday!
In today's tutorial, we will be looking at how you can run PowerShell code in your workflows.
I designed Koupi to make it easy for anyone to create automation workflows. However, in the absence of the ability to do absolutely anything you can dream of, I had to give you this ability somehow: the Command step type.
The Command step type enables you to run either batch or PowerShell commands. Unfortunately, however, those results cannot be passed on to other steps, even though they may show up as an option :( It's a bug I have to address.
The reason for the inability to return any result is because you can produce absolutely any result through this step type. Adding support for this is a daunting task that may not be worth it in the long run. I will talk more about step type results in a future Fun Fact Friday installment.
Let's get back to the matter at hand: the Command step type. The goal of this command is to give you abilities you may not have when creating a workflow.
This step type gives you the ability to either run a single command or an entire script. You do have to hardcode the script in there and cannot run it with input parameters. However, you can use variables and previous step results as "input."
Let's start with a simple command of listing the contents of a directory and build up from there.
As you can see, this is running as expected, but that's not a useful result.
Simple Command With Variable
Even though I mentioned that it's not really possible to add input to the Command step type, but let's see how that can be done.
Right now, we can use the variables. So let's take a look and set a variable.
Let's set it to the following parameters:
Variable Friendly Name: My Folder
Variable Name: My_Folder
Variable Default Value: C:\
As you can see, our variable worked.
More Advanced use of Command
Now we know how to run a PowerShell command in the Command step, and we know how to use a variable to input data into a command. Let's see how we can use those two things to build some logic into our workflows.
In this example, let's try and see if a computer on the network is responding, and then let's do something if it responds to a ping.
Currently, the Test step type only supports testing for files, so we just need to use our Command step to output a file and we can test for it.
Let's create two variables:
Variable Friendly Name: Computer IP Address
Variable Name: IP_Address
Variable Default Value: 127.0.0.1
Variable Friendly Name: Successful Ping File
Variable Name: Ping_Success
Variable Default Value: C:\temp\pingsuccess.txt