locked
Get-Aduser CSV Import RRS feed

  • Question

  • Hi,

    Try to perform a get-aduser where their UPN is like the value provided in a CSV file.

    I am trying:

    Import-Csv c:\upncheck.csv | ForEach {
    Get-ADUser -Filter {UserPrincipalName -like $_.UPN} -Properties name, emailAddress, SAMAccountName | `
        Select Name, emailAddress, SamAccountName | `
        Export-CSV c:\upncheckoutput.csv -NoTypeInformation
    }

    Even with various escapes around the $ variable i cannot get this to work. Can anyone advise why?

    Tuesday, October 24, 2017 1:22 PM

All replies

  • You should use the "*" wildcard character with the -Like operator, and enclose in quotes.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Tuesday, October 24, 2017 1:35 PM
  • You also do not need to specify Name and sAmAccounName on the Properties parameter as these are defualt properties returned automatically.

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Tuesday, October 24, 2017 2:02 PM
  • Import-Csv c:\upncheck.csv | 
    	ForEach-Object {
    		Get-ADUser -Filter "UserPrincipalName -eq '$($_.UPN)'" -Properties emailAddress
    	} |
    	Select-Object Name, emailAddress, SamAccountName |
    	Export-CSV c:\upncheckoutput.csv -NoTypeInformation
    


    \_(ツ)_/

    • Proposed as answer by clayman2 Tuesday, October 24, 2017 2:18 PM
    Tuesday, October 24, 2017 2:14 PM
  • Hi,

    Try to perform a get-aduser where their UPN is like the value provided in a CSV file.

    I am trying:

    Import-Csv c:\upncheck.csv | ForEach {
    Get-ADUser -Filter {UserPrincipalName -like $_.UPN} -Properties name, emailAddress, SAMAccountName | `
        Select Name, emailAddress, SamAccountName | `
        Export-CSV c:\upncheckoutput.csv -NoTypeInformation
    }

    Even with various escapes around the $ variable i cannot get this to work. Can anyone advise why?

    So:
    Get-ADUser -Filter {UserPrincipalName -like "*"} ....
    ?
    • Edited by Dan Davey Wednesday, October 25, 2017 9:38 AM
    Wednesday, October 25, 2017 9:38 AM
  • I just posted the answer.  You need to spend some time learning how to use it.  Perhaps you have no UPNs in your file.


    \_(ツ)_/

    Wednesday, October 25, 2017 9:42 AM