Run Powershell command changing values of variable

jfinn
Kilo Expert

I am testing a few powershell commands and one of these needs to pass through a file path so that we can check the permissions on it.   Currently I have a variable in which I enter my file path but when this gets passed through to the "Run Powershell" activity, the variable loses parts of the drive path.

Here is my code as it stands in the Run Powershell activity.   For testing purposes, on this occasion, I am passing the variable directly.

Powershell Issue.JPG

However, when I run the workflow and check, it fails with the following message:

Get-Acl : Cannot find path 'c:Userstestuser' because it does not exist.At C:\Users\SERVIC~1\AppData\Local\Temp\script.6618372681266526755.PS1:1 char:8+ Get-Acl <<<<   $Folder_Path | Format-List+ CategoryInfo                   : ObjectNotFound: (:) [Get-Acl], Ite

Note how it removes the \ after c: and also between users and testuser in the path.

Am I doing something wrong here or is is not possible to pass a path through as a variable?

11 REPLIES 11

jfinn
Kilo Expert

Just to add some additional information to this, If I change the code in the powershell script to the following, it works perfectly:



$PSFolder = "$FolderPath"


Get-Acl c:\Users\testuser | Format-List



So, if I enter the path directly into the powershell code, it works fine, however, if I try to pass that same path through as a variable, some of the path gets removed and the powershell command fails.


jfinn
Kilo Expert

And here is an example of the ECC Queue output:



<?xml version="1.0" encoding="UTF-8"?><parameters><parameter name="powershell_param_FolderPath" value="c:erstestuser"/><parameter name="skip_sensor" value="true"/><parameter name="probe_name" value="Windows - Powershell"/><parameter name="script.ps1" value="$PSFolder = &quot;$FolderPath&quot;&#13;&#10;Get-Acl $PSFolder"/><parameter name="debug" value="true"/><parameter name="workflow" value="3777ef896f025200f63108c6eb3ee4c3"/><parameter name="probe" value="ca9edfec0a0a0baa011fe82922346887"/></parameters>


rebecca_dias
ServiceNow Employee
ServiceNow Employee

Hi James,



I would recommend using the Activity Template for PowerShell, not the Run PowerShell Activity. The Run PowerShell Activity is considered legacy at this point.   What version of the platform are you on?



I have successfully run your PowerShell command using Activity Designer.



Steps on Geneva:


- Under Custom, Select '+' to and Create a new PowerShell Activity


- Have two inputs: Host and Folder


- Drag and drop host into the target host field


- Use the following PowerShell command (Be sure to escape folders e.g. c:\\users\\rebecca.dias)


- Save it, Test your inputs and get your output payload to use for parsing.


- I am just playing around with some parsing options... Do you have a regex you are planning on using for the output? May be easier to pump it into an XML format.


Windows Folder ACLs.png


tx


becky


- Product Manager, Orchestration


Hi James,



I created an update set for you on Geneva. I tried the update set on Fuji and while the activities and workflow loaded, I didn't test it successfully. It just hung. I think it is because my mid server is Geneva. But the workflow and activity loaded cleanly.



Take a look. Below you can see the activity output from my reusable activity.



I am not good with RegEx, so I opted to format the output into XML so I could use the XPath Parsing rules.



Windows ACLs running context.png



Let me know what you think.


becky


P.S. Attaching a link to share on this thread was pretty challenging, hope I got it after a few tries.