Invoke Power Shell: This command cannot be run due to the error: The directory name is invalid

Hi all,

I’m currently writing an automation that pulls data from a queue (an email address) and uses it as a parameter in a PowerShell script to update a security group. The PowerShell script needs to be run as a service account user so I am attempting to invoke PowerShell activity with the output of a read text file activity which starts PowerShell as the service account and then executes a ps script. here is the activity in question:

param ($UserEmailInput)

$PSFile = ‘\Scripts\AddAdobeCC_UiPath.ps1’
$credential = New-Object System.Management.Automation.PsCredential(“Domain\service.account”, (ConvertTo-SecureString “Password” -AsPlainText -Force))
Start-Process powershell -ArgumentList ‘-ExecutionPolicy’, ‘bypass’, $PSFile, ‘-UserEmailInput’, $UserEmailInput -Credential $credential

Write-Host $UserEmailInput

This is read into the “Input” variable and then passed to the invoke PowerShell activity.

for some reason, I keep getting “Invoke Power Shell: This command cannot be run due to the error: The directory name is invalid.” error. the service account user has permissions to the folder and script files.
my setup is identical to what has been posted at While running powershell using invoke activity it throws exception "windows powershell run as administrator" - #2 by loginerror
Can anyone offer any advice? I will upload my project file once i have worked out how.

Is this working from powershell ISE or console?

Also can you try giving full path of your .ps1 file instead of giving relative path like “\Scripts\AddAdobeCC_UiPath.ps1”

1 Like

Thanks for taking a look Surya, i have tested the AddAdobeCC_UIPath.ps1 and the script above that runs it as the service account with arguments from ISE and console it it works perfectly. Initially i had the full path referenced but was getting the same error. I moved the scripts into the root file of the project and put the relative paths in an attempt to troubleshoot.

EDIT: Here is my project if it helps (17.6 KB)

Ok, I managed to figure it out. because my run_as_admin.ps1 file which invokes the AddAdobeCC_UIPath.ps1 were both in the same \Scripts directory i needed to just call “AddAdobeCC_UIPath.ps1” instead of “\Scripts\AddAdobeCC_UIPath.ps1”.

I did also find that I had not set the permissions correctly on the project folder and the service account didn’t in fact have permissions to the folder. after setting these permissions the process progressed a little further but the PowerShell script still didn’t execute as expected with the following error:

Provider Health: Attempting to perform the NormalizeRelativePath operation on the ‘FileSystem’ provider failed for path c:\path\to\file

If you are experiencing this error - it helps to move your project out of your user directory (I was running my project from My Documents) and run it from c:\temp. I haven’t tested if just moving the ps script to c:\temp will work or if you have to move the whole project, I’ll leave that up to someone else to test and confirm… I’m burnt out.

Thanks Surya for your help, you were able to reassure me that I was moving in the right direction.

1 Like

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