Not seeing any output in Get-ADUser -Filter

This topic contains 5 replies, has 5 voices, and was last updated by Profile photo of Michael Krupa Michael Krupa 6 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #37092
    Profile photo of Michael Krupa
    Michael Krupa
    Participant

    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 powershell.org "Trouble with Get-Aduser from CSV" but the recommendation does not work for me. What I am I doing wrong?

    Partial CSV File:
    Name
    _____
    0915_jc
    0923_ja
    1008_ha
    1071_bd
    1169_hm
    1173_km
    1599_my
    1810_ih

    Code:
    $dirs=Import-Csv .\user-dirs.csv
    foreach ($line in $dirs) {
    Get-ADUser -Filter "homedirectory -like '*$($line.name)*'" -Properties * |format-table name, enabled, lastlogondate -Autosize
    }

    #37094
    Profile photo of David Senior
    David Senior
    Participant

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

    #37095
    Profile photo of Bob McCoy
    Bob McCoy
    Participant

    The code is also working for me.

    #37097
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan
    Participant

    You might want to try something like:

    
    import-csv $path  get-aduser  -filter {homedirectory -like $_.name }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.

    #37098
    Profile photo of Hermann Lüpfert
    Hermann Lüpfert
    Participant

    In line 3 of your code you have "$line.name". 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.name
    $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
     }
    
    #37103
    Profile photo of Michael Krupa
    Michael Krupa
    Participant

    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.

    Name
    _____ <— This row was the cause of my problem 0915_jc ...

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.