I'm new to PowerShell. I'm trying to pull a users Active Directory info based on their job title and place it in a csv file. I have two corresponding arrays, $title and $csvfile. $title[0] corresponds with $csvfile[0] and $title[1] to $csvfile[1] and so on. This loop creates all my .csv files but doesn't pull any user data. I can manually enter any of the $title items into the script and it works but when used as an array I get nothing.
Does an array add any leading or ending spaces, quotations, delimiters, anything that might keep the -and statement from working?
$title = @(
'Director of Nursing'
'Assistant Director of Nursing'
'Activities Director'
)
$csvfile = @(
'DON'
'ADON'
'ACTIVITIES'
)
for($i=0; $i -lt $title.Count; $i++)
{
#Get-ADUser -Filter { (Title -like "Director of Nursing") -and (Company -like "location1") }| Export-Csv c:\temp\$($csvfile[$i]).csv"
Get-ADUser -filter { (Title -like "$($title[$i])") -and (Company -like "Location1") }| Export-Csv "c:\tempPath\$($csvfile[$i]).csv"
}