# 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?

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