I am simply invoking Powershell script for fetching data from database with using below points
- Reading text file where powershell script in it
- 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-Host
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 = $Item.sn # 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 $Item.cn)
{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’
#$stopwatch.Stop()
#$stopwatch.Elapsed
#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 …