Solved

Running Powershell command within K2 Workflow


Hello,

 

I am interested how could one run any Powershell command using K2 Five Workflow? Please, if someone could write step by step installation/configuration process, that is necessary to execute Powershell commands. I found some old posts how to do this via K2 BlackPearl, but the instructions are not explicitly given for K2 Five version.

 

Thanks.

icon

Best answer by DanielKarlsson 20 May 2019, 08:49

Hi!
I have done this with a powershell broker found here on the market (http://community.k2.com/t5/K2-blackpearl/PowerShell-Service-Object/ba-p/1025). When installed you can call the smartobject from K2 Five workflow, but the script files needs to be accessible from the server since the workflow as a standard is run with the service account.

 

I've wrote a short post about how to get started

https://relight.se/en/blog/make-k2-to-a-multitool

 

Regards

Daniel

View original

6 replies

Hi Primozsisko

 

See the following link below on how to run powershell within workflow:

https://community.k2.com/t5/K2-Blackpearl-Forum-Posts/Running-an-external-application-from-within-a-workflow/td-p/91140?nobounce=

 

Should you find the information from the article useful or leading you to the answer please mark as "Solution and/or Kudo", as it will assist other k2 developers with relevant information in the near future.

 

Best Regards

Elvis

 

[K2 will not accept any liability for any issues arising from actions taken in respect of the information provided by any forum member]

Hi!
I have done this with a powershell broker found here on the market (http://community.k2.com/t5/K2-blackpearl/PowerShell-Service-Object/ba-p/1025). When installed you can call the smartobject from K2 Five workflow, but the script files needs to be accessible from the server since the workflow as a standard is run with the service account.

 

I've wrote a short post about how to get started

https://relight.se/en/blog/make-k2-to-a-multitool

 

Regards

Daniel

Hi  @primozs;

 

Please see the following recent article regarding execution of k2 five workflow instance using powershell commands :-

https://mikerodionov.com/category/tech/k2/ and also check out with the k2 Management shell(https://community.k2.com/t5/General-K2-Utilities/K2-Management-Shell/ba-p/100805) installation which "provides PowerShell cmdlets as wrapper around the K2 API?s so that administrators and developers can more easily manipulate K2 in a programmatic fashion. This solution was developed specifically for K2 4.7 and K2 Five".

 

Should you find any of the above information useful kindly mark such as "Kudo, Accepted Solution and/or MeToo options", as assistance for future k2 researchers.

 

Thank you.

 

Kind regards;

Widson.

Additionally:-https://help.k2.com/onlinehelp/k2five/devref/5.2/default.htm#runtime/wf-client/ps-startprocess.html

Hello  @primozs

 

The PowerShell wizard allows you to run PowerShell commands from your K2 process. The PowerShell commands are run on the K2 server itself.

PowerShell must be installed on the K2 Server and on the K2 machine designing the K2 workflow (this is because of the assemblies required).

The wizard allows users to specify input variables and output variables. With the normal Run-As feature, you can run the powershell in another users' context.

 

Installation (if you build yourself):

  1. Build the solution in DEBUG mode (it has some build events which copy assemblies)
  2. Check the changes in ConfigurationManager.config and apply them to the configurationmanager file in c:programdatasourcecodeconfigurationmanager.config
  3. Copy the CodeExtender folder (from the design project) to C:Program FilesK2 blackpearlBinDesignTemplatesCSharp; this will add some files to the folder structure.
  4. Start K2 studio and use the wizard.
  5. Start Visual Studio - Use right mouse button on the toolbox and select 'reset toolbox'

Installation (if you do not build yourself):

      

  1. Copy the SourceCode.Wizard.PowerShell.*.dll files from the bin
    elease(S) to c:programdatasourcecode
  2. Check the changes in ConfigurationManager.config and apply them to the configurationmanager file in c:programdatasourcecodeconfigurationmanager.config
  3. Copy the CodeExtender folder (from the design project) to C:Program FilesK2 blackpearlBinDesignTemplatesCSharp; this will add some files to the folder structure.
  4. Start K2 studio and use the wizard.
  5. Start Visual Studio - Use right mouse button on the toolbox and select 'reset toolbox' 

Version 1.2 is released!

The V1.2 release improves the following:

  • System.Management.Automation assembly was taken from a directory on disk, this was changed when we 'added' 32-bit support and was actually wrong in the first place. Now, it takes the assembly from the GAC, where it will be located. This also means the designer tools do not need the SDK anymore.
  • Upgrade AssemblyVersion to 1.2
  • Moved the CodeExtender files into another directory as the directory name was wrong.
  • Improved icons.
  • Very simple syntax error checking was added. This will now note very simple powershell errors. Because any word (or even a single character) can be a commandlet, it's still looks very stupid if you enter "X" into the script dialog and it validates correctly.  X could be a commandlet (that you load at runtime) and can thus be valid powershell script. The script checking does however check if you had your quote's correctly etc. Powershell simply does not provide more options to do better checking.
  • Error handling at runtime has been improved a little bit.

Instructions to install available here: http://old.k2underground.com/groups/powershell_wizard/default.aspx

 

Known  issues / Feature requests

See github page!

 

Regards,

BesM

 

i downloaded the zip, and copied the powershell.dll to the servicebroker folder

restarted K2, unable to see it to register within the service object tester

any ideas?

Reply