vbscript to grap company field from users RRS feed

  • Question

  • Hello,

    I need a script that will grab the company field of all users in a particular OU in my AD. I'am really new to scripting and I hope it isn't really difficult for you guys! :)

    Best Regards


    Thursday, May 5, 2016 1:33 PM


  • Do it using powershell.

    Import-Module ActiveDirectory
    Get-ADUser -SearchBase "ou=yourOU,dc=dc,dc=com" -Properties * | Export-Csv "C:\file.csv" -NoTypeInformation

    Thursday, May 5, 2016 1:39 PM
  • Mike is correct. Once you learn Powershell , you will realize  how easily  these tasks can be accomplished unlike the VB way.

    To get all user from  OU=Finance,OU=Users,DC=DOMAIN,DC=COM.
    Import-Module ActiveDirectory
    Get-ADUser -SearchBase "OU=Finance,OU=Users,DC=DOMAIN,DC=COM" -Properties * |select-object Name,Company| Export-Csv "C:\file.csv" -NoTypeInformation

    Thursday, May 5, 2016 2:41 PM
  • I would suggest that you only export the property values you need, rather than all. The DistinguishedName and SamAccountName properties are default, so the Get-ADUser cmdlet always retrieves them. But the Company property is extended, meaning it needs to be specified with the -Properties parameter (unless you specify -Properties *, in which case all properties that have values are retrieved). It is also more efficient to  only retrieve what you need. My suggestion:

    Import-Module ActiveDirectory
    Get-ADUser -SearchBase "ou=yourOU,dc=dc,dc=com" -Properties Company | Select DistinguishedName, SamAccountName, Company | Export-Csv "C:\file.csv" -NoTypeInformation

    You many not need both DistinguishedName and SamAccountName, in which case you can modify the Select. Or, you can add properties to the Select (and to the -Properties parameter if needed). Help for Get-ADUser:

    Explanation of Default and Extended properties here, plus a table of Default properties exposed by Get-ADUser (and other AD cmdlets):

    And, documentation of all Default and Extended properties exposed by Get-ADUser:

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Marked as answer by Einzelkind1 Friday, May 6, 2016 3:00 PM
    Thursday, May 5, 2016 2:53 PM

All replies