Get-ADUser Against CSV File RRS feed

  • Question

  • Hi guys,

    Have been sent a CSV file containing a list of users names under column 'Name'.

    Trying to compare these names against AD to see if they're enabled or not but having some trouble, I'm completely new to PowerShell/any scripting in general.

    So far I have:

    Import-CSV c:\users.csv | foreach {

    Get-ADUser -filter {name -eq '$'}


    Was expecting some output at this point before piping in to some other command to check if they're enabled or not but nothing's happening, script runs and gives no output.

    • Moved by Bill_Stewart Friday, July 7, 2017 4:32 PM Abandoned
    Tuesday, May 2, 2017 2:48 PM

All replies

  • Close -

    Import-CSV c:\users.csv | 
    	ForEach-Object {
    		Get-ADUser -filter "name -eq '$($'"


    Tuesday, May 2, 2017 2:55 PM
  • Thanks that worked great :)

    Just need to filter out the disabled users now, at the moment I've got:

    get-aduser -filter "displayname -eq '$($' -and enabled -eq $false"

    but is throwing up a syntax error, am I using '-and' properly?

    Thursday, May 4, 2017 9:55 AM
  • "Enabled" is not an attribute.  It is a derived property added by PowerShell.

    Using both a name and enabled doesn't make much sense anyway except if you want to ignore enabled accounts.

    if (-not (get-aduser -filter "name -eq '$($'").Enabled) {
    	'found user as disabled'
    	'user not found or user enabled'


    Thursday, May 4, 2017 8:01 PM