Not seeing any output in Get-ADUser -Filter

New to PowerShell! I am not seeing any output from the below foreach query. It appears to run but there is no output to the console or redirecting output to a file. I structured the filter syntax as per a Q&A found here on “Trouble with Get-Aduser from CSV” but the recommendation does not work for me. What I am I doing wrong?

Partial CSV File:


$dirs=Import-Csv .\user-dirs.csv
foreach ($line in $dirs) {
Get-ADUser -Filter “homedirectory -like ‘$($’” -Properties * |format-table name, enabled, lastlogondate -Autosize

Code works, are you sure the homedirectory attribute has a value?

The code is also working for me.

You might want to try something like:

import-csv $path  get-aduser  -filter {homedirectory -like $ }Properties homedirectory,name, enabled,lastlogondate | format-table -autosize

You don’t need to do for each as each entry will go through the pipe line.

In line 3 of your code you have “$”. You try to access the name property of the object that the $line variable holds. That property does not exist. Therefor no output.

$line = "0915_jc"
$line | get-member

Try to keep it simple. Delete to lines from the csv (Name + ____) and use txt.
See if this works for you (I didn’t test it)

$dirs=get-content .\user-dirs.txt
 foreach ($dir in $dirs) {
 Get-ADUser -Filter "homedirectory -like '*$dir*'" -Properties name,enabled,lastlogondate

Thank you all for the responses and suggestions! Seeing that this worked for other people, I looked outside of the command structure and focussed on my CSV file. In the file, the headings had a row beneath them that were populated with dashes (underlining). I removed that row and it all worked fine. Pretty much garbage in, garbage out.

_____ <— This row was the cause of my problem