get-aduser and csv files

This topic contains 7 replies, has 3 voices, and was last updated by  nkaretnikov 3 months, 3 weeks ago.

  • Author
    Posts
  • #75911

    nkaretnikov
    Participant

    Hello!
    I got a very easy script

    Get-ADUser -SearchBase "OU=users,OU=orgunit,DC=org,DC=local" -LDAPFilter "((!userAccountControl:1.2.840.113556.1.4.803:=2))" `
         -Properties * | Select IDIdentifierType, sAMAccountName, Mail | `
        Export-Csv -Path c:\Users.csv -NoTypeInformation
    

    as a result I got
    "IDIdentifierType","sAMAccountName","Mail"
    "Microsoft.ActiveDirectory.Management.ADPropertyValueCollection","truhachev_iu","truhachev_iu@mrsks.ru"
    How should I modify the script to get
    "IDIdentifierType","sAMAccountName","Mail"
    "","truhachev_iu","truhachev_iu@mrsks.ru"
    ?
    I would like to create a csv file that is filled in with some default values ("" in this case), but I do not know how to tell powershell use empty values instead of AD properties.
    Any ideas?

  • #75928

    Max Kozlov
    Participant

    ... select @{n="AnySynteticPropertyName"; e={ "Any" + ($valid) + 'scriptblock' } }, AnyRealProperty ...

  • #75931

    Max Kozlov
    Participant

    in your case, if you want empty properties, even better 🙂

    Get-ADUser -SearchBase "OU=users,OU=orgunit,DC=org,DC=local" -LDAPFilter "((!userAccountControl:1.2.840.113556.1.4.803:=2))" `
         -Properties * | Select * | Select IDIdentifierType, sAMAccountName, Mail | `
        Export-Csv -Path c:\Users.csv -NoTypeInformation
    
  • #75940

    nkaretnikov
    Participant

    за оба варианта спасибо большое!
    Первый (с Label и Evaluations )успел сам нагуглить, правда 🙂

  • #76306

    nkaretnikov
    Participant

    Hello!
    In case someone know 🙂
    Got a script

    $filename = "c:\users" + (Get-Date -Format "yyyy-MM-dd-HH-mm-ss") + ".csv"
    $mRecordNumber = $null # or set integer to limit number of lines in the resulting CSV file
    $mSearchBase = "OU=Users, OU=orgunit, DC=dc,DC=local"
    Get-ADUser  `
                -ResultSetSize $mRecordNumber  `
                -SearchBase $mSearchBase  `
                -LDAPFilter "((!userAccountControl:1.2.840.113556.1.4.803:=2))" `
                -Properties * | `
          Select `
          @{L='Manager'; E={""}}| `
        Export-Csv -Path $filename -NoTypeInformation -Encoding UTF8
    

    and the manager field contains
    Manager : CN=ivanov,OU=orgunit,DC=dc, DC=local
    string.
    Is there a way to get GivenName of that particular user in the run-time?

  • #76307

    nkaretnikov
    Participant

    smth like

    @{L='Manager'; E={Get-ADUser $.Manager -Properties .GivenName }}|
    

    ?

  • #76345

    edwin arlington
    Participant

    You can try below given script :

    Get-ADUser -Filter * -SearchBase 'OU=Users & Computers, DC=aaaaaaa, DC=com' -Properties DisplayName | select -expand displayname | Export-CSV "ADUsers.csv"

    or

    Get-ADUser -Filter * -SearchBase "ou=OU,dc=Domain,dc=com" -Properties Enabled, CanonicalName, Displayname, Givenname, Surname, EmployeeNumber, EmailAddress, Department, StreetAddress, Title | select Enabled, CanonicalName, Displayname, GivenName, Surname, EmployeeNumber, EmailAddress, Department, Title | Export-CSV "C:\output.csv"

  • #76348

    nkaretnikov
    Participant

    Thanks a great deal!

You must be logged in to reply to this topic.