Run .bat file using invoke powershell activity

Hi,

Does anyone know how to run .bat file using ‘invoke powershell’ activity?

Hi, or you can try Start Process Activity?

Do you want to directly call the bat file or the Code in the Invoke Bat file

?

I was able to run the .bat file using cmd prompt. But I want to use ‘invoke power shell’ activity since it runs the script behind the scenes. Is this achievable?

Can you tell both the ways, on how you are doing it?

You can run a bat-file with Invoke Powershell like this:

cmd /c hello.bat

Make sure that the option IsScript is checked.

image

image

2 Likes

@ptrobt - Thank you, I worked, but the output is of data type "System.Collections.ObjectModel.Collection`1[System.String]. How do you convert that into string? I took an index of (1) of my output variable and it worked, but I wanted to know, how you would handle it.

You could use a For Each loop to get all the output lines. Or you could use String.Join() to join them to a single string:

strOutput = String.Join(Environment.NewLine, resultPS)

where resultPS is the output variable from the Invoke Power Shell activity.

1 Like

Thank you much @ptrobot

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.