none
Can't get this script to work :( RRS feed

  • Question

  • Guys

    Can someone explain why this doesn't work

    import-csv c:\users.csv | foreach { get-aduser -ldapfilter "(employeeid=$_.employeeid)" | Select samaccountname,employeeid } | export-csv C:\usernameemployeeid.csv

    It just sits there and does nothing

    Cheers

    Alex

    Tuesday, December 23, 2014 2:31 PM

Answers

  • You need to use sub-expression syntax - $()  any time you want to use a property value of an object in an expandable string.

    import-csv c:\users.csv | foreach { get-aduser -ldapfilter "(employeeid=$($_.employeeid))" | Select samaccountname,employeeid } | export-csv C:\usernameemployeeid.csv


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    • Marked as answer by Alexgreen312 Tuesday, December 23, 2014 3:04 PM
    Tuesday, December 23, 2014 2:34 PM
    Moderator

All replies

  • You need to use sub-expression syntax - $()  any time you want to use a property value of an object in an expandable string.

    import-csv c:\users.csv | foreach { get-aduser -ldapfilter "(employeeid=$($_.employeeid))" | Select samaccountname,employeeid } | export-csv C:\usernameemployeeid.csv


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    • Marked as answer by Alexgreen312 Tuesday, December 23, 2014 3:04 PM
    Tuesday, December 23, 2014 2:34 PM
    Moderator
  • Try this:

    import-csv c:\users.csv | foreach { get-aduser -ldapfilter "(employeeid=$($_.employeeid))" -properties Employeeid | Select samaccountname,employeeid } | export-csv C:\usernameemployeeid.csv


    • Edited by Braham20 Tuesday, December 23, 2014 2:38 PM
    Tuesday, December 23, 2014 2:35 PM
  • Hi Alex,

    You need to use a subexpression in your filter. You also need to specify that you want Get-ADUser to return the EmployeeID property:

    Import-Csv .\employeeID.csv | ForEach {
    
        Get-ADUser -LDAPFilter "(employeeid=$($_.EmployeeID))" -Properties EmployeeID |
            Select SamAccountName,EmployeeID
    
    } | Export-Csv .\UserNameEmployeeID.csv -NoTypeInformation


    EDIT: Hah, slow on the submit button. See above.

    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Tuesday, December 23, 2014 2:38 PM
  • That's awesome, I couldn't see it

    Thanks

    Alex

    Tuesday, December 23, 2014 3:05 PM
  • That's awesome, I couldn't see it

    Thanks

    Alex

    Just be aware that you'll still need to add the EmployeeID property to the Get-ADUser command if you want any output.


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Tuesday, December 23, 2014 3:09 PM