none
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

    Einzelkind

    Thursday, May 5, 2016 1:33 PM

Answers

  • 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:

    https://technet.microsoft.com/en-us/library/ee617241.aspx

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

    http://social.technet.microsoft.com/wiki/contents/articles/12031.active-directory-powershell-ad-module-properties.aspx

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

    http://social.technet.microsoft.com/wiki/contents/articles/12037.active-directory-get-aduser-default-and-extended-properties.aspx


    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
    Moderator

All replies