Issue while invoking powershell script with Uipath

I am simply invoking Powershell script for fetching data from database with using below points :slight_smile:

  1. Reading text file where powershell script in it
  2. Then Invoking Powershell script

but i am getting below exception:
Invoke Power Shell: The term '#This script pulls User data from LDAP for external client IDs
#Setup eDirectory Connection Variables
Clear-Variable CSVoutput
Clear-Variable stopwatch
$eDirPath =
$eDirUser =
$eDirPWD =
$eDirAuthType = ‘None’
#$stopwatch = [system.diagnostics.stopwatch]::StartNew()

#Establish eDirectory Connection and Enumerate
$Root = New-Object System.DirectoryServices.DirectoryEntry -argumentlist $eDirPath,$eDirUser,$eDirPWD,$eDirAuthType
$Query = New-Object System.DirectoryServices.DirectorySearcher
$Query.SearchRoot = $Root

#$Query.SizeLimit = 5000 #limits results for testing purposes

Query Filter Samples

#$Query.Filter = “(cn=7950*)”
#$Query.Filter = “(cn=8942*)”
#$Query.Filter = “(|(!(mlogo=ALL_EPOC))(!(cn=9*)))” #where mlogo is not "all_epoc’
#$Query.Filter = “(!(mlogo=ALL_EPOC)(cn=3*))” #where mlogo is not "all_epoc’
#$Query.Filter = “(|(cn=999*)(cn=333*)(cn=49*))” #user IDs beginning with 999* or 333* or 49*
#$Query.Filter = “(cn=3*)” #where user ID starts with 3
#$Query.Filter = “(|(cn=)(objectClass=user)(directReports=)(!(mlogo=ALL_EPOC)))”

$Query.Filter = “(&(!(mlogo=ALL_EPOC))(!(cn=attributeTestuser)))” #this filters out internal users with ALL_EPOC, and filters out “attributeTestuser”

$SearchResults = $Query.FindAll()
$ldapIDs = @() # creates an empty $ldapIDs variable
ForEach ($Result in $SearchResults) `
#Add each ldap attribute to the empty $CSVoutput variable
$CCGroupALL = [PSCustomObject]$Result.Properties
ForEach ($Item in $CCGroupALL)
$fn = $Item.givenname # first name
$fn = $fn -Replace ‘(\s+$|,)’,‘’ #strip trailing space or comma
$ln = $ # last name
$ln = $ln -Replace ‘(\s+$|,)’,‘’ #strip trailing space or comma
#$inst = $Item.l # institution name
#$inst = $inst -Replace ‘(\s+|,)’,‘’ #strip any space or comma from inst
#$fiid = $Item.fiid
$mcfiid = $Item.mcfiid # mcfiid
$mlogo = $Item.mlogo # mlogo
#$modTime = $Item.modifiedportaltimestamp # last modified timestamp
#$modTime = $modTime -Replace ‘( EDT| EST)’,‘’
#$modBy = $Item.modifiersportalid # last modified by
#$create = $Item.createtimestamp
#$ltime = $Item.logintime # last logon timestamp

            ForEach ($cn in $
                {ForEach ($mlogo in $Item.mlogo) #foreach logo in user ID
                 #Write-Host "$cn",",","$fn",",","$ln",",","$inst",",","$mcfiid",",","$mlogo"
                 $ldapIDs += "$cn,$fn,$ln,$mcfiid,$mlogo"
            $CSVoutput = "cn,fn,ln,mcfiid,logo" , $ldapIDs  #output data with header row


#Enter desired destination for output CSV
$CSVoutput | Out-File ‘D:\Users\F127ZWP\Desktop\CVI User Audit\CWSiClients_2022-01-09_v5.csv’

#v4 took 45 minutes’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Any help would be appreciated here !
Thanks in Advance …

Hi @mittal.abhishek066
The error message you’re seeing is because you’re trying to run a PowerShell script that contains a number of syntax errors.

Follow below steps to fix the issue:

  1. You should replace these with standard quotes (“”) and apostrophes (') and make sure that there are no other syntax errors in the script.
  2. There are a lot of variables and functions used in the script that are not defined. For example, $eDirPath , $eDirUser , $eDirPWD etc…

Kaviyarasu N

Hello @Kaviyarasu_N - Thanks for solution .

  1. For first point i need to replace all double quotes with single quotes ?
  2. I removed intentional beacause of security reasons value is defined in script