You are viewing limited content. For full access, please sign in.

Question

Question

powershell script won't run correctly when executed from Workflow.

asked on May 17, 2017

Hi!

I have a powershell script that i need to run from a workflow. It pulls together some information and creates a document. This document is pulled back into the repo with Import agent.

I realise the way i'm doing it is using extra steps, but i have only very basic c#/VB knowledge.

This external script (Process.ps1) needs several parameters passed in. I am getting WF to create them and make another file  (Run.ps1) file with all paths, parameters etc ready.

If i run my 'run.ps1' by rclick->run in powershell, it works. If i execute in PS ISE, works.

If i run it from a workflow script activity, it gets most of the way through and gives an error trying to save the output file. I have my 'run.ps1' logging all output to a file. i can see most of the 'process.ps1' runs correctly, just not the save.
I'm logged in as domain\administrator. so i figure its permissions. i've set the 'run.ps1' to specify administrator credentials when it starts the 'process.ps1'. Seems to work, but doesn't fix the issue.

As i'm using 'start-process' i was told to use -Verb runAs, but i can't get this to run at all to test.

Also, when the workflow service is set to 'local system' it executes in windows\system32. ive also changed this, but still no good.

I realise i can replace my 'run.ps1' with c#/VB, but i'm not convinced it won't do the same issue.

Has anyone seen this type of problem?

Thanks

Mark

0 0

Replies

replied on May 18, 2017

How do you call the PowerShell script file in your script activity? It might be trying to launch the PowerShell window and probably can't since it's running as the service without a user session.

0 0
replied on May 21, 2017

Hi!

i'm running the 'run.ps1' using a c# command

System.Diagnostics.Process.Start("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"," -file C:\\scripts\\run.ps1")

is there a way for me to run it differently? to get around 'no user session'?

Thanks

Mark.

0 0
replied on June 5, 2017

Hi!

Well, its now working, so i thought i should put some information back up here in case it helps someone else avoid the same frustration.

The powershell command was running, but one of the sections was using Microsoft word. It seems this really doesn't like being run without a proper user session, even if there are no popups or windows opening.

in the end it turned out that the following directory needs to be created;
for 64bit               %systemroot%\SysWOW64\config\systemprofile\Desktop
for 324bit             %systemroot%\System32\config\systemprofile\Desktop

The 'desktop' folder doesn't wasn't there but i think it was trying to use it as a temp area.

The service is running as 'local system' with the 'interact with desktop' off and its running fine now.

i've made some other changes to how it runs and commands it uses, but this 'desktop' directory was the main holdup.

Mark.

3 0
replied on September 26, 2018

Mark,

Were you able to get this to work correctly? We have a client that is launching a powershell script using Workflow as well, but it doesn't seem to be working correctly when run automatically by Workflow. If they run it manually it works as expected.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.