Hello,I have a CSV file with a column without a header that contains numbers.
I would like to use them in a Get-ADUser request.I have tried several things but without success.Here is the last code tested:
Import file CSV with adding header Numero
$Users = Import-Csv -Path c:\test\compare.csv -Header 'Numero'
Clear the contents of the Result.csv output file which may contain old data
clear-content C:\test\powershell\result.csv
Query on the AD to find the name and the first name of the users who are present in the file Numero.csv
$List = ($Users | ForEach-Object {
Get-ADUser -Filter 'attribute -Like "$_.Numero"' -Properties * | select-object givenname,sn,attribute
})
Export du contenu de $List dans le fichier final Result.csv
$List | Export-CSV -Path "C:\test\powershell\Result.csv" -NoTypeInformation -Encoding UTF8 -Delimiter ";"
Single qoutes are literal, nothing will be expanded
PS C:\Users\rasim>
$numero = 123
'attribute -Like "$Numero"'
attribute -Like "$Numero" #with single qoute, you are literally searching for this
PS C:\Users\rasim>
$numero = 123
"attribute -eq $Numero"
attribute -eq 123 #the double qoutes will expand the filter. This should work without qoutes.
PS C:\Users\rasim>
$numero = 123
"attribute -eq '$Numero'"
attribute -eq '123' #if the above format doesn't work, try this
Just as a tip: To reduce the stress you put on your AD running your query you should only query attributes with the -Properties parameter you’re going to use afterwards. GivenName and Surname already belong to the property set Get-ADUser outputs by default. So that the following should be enough then …