locked
Retrieve information about users and manager guid RRS feed

  • Question

  • Hi trying to get some information about all users from a certain AD-Group and export that into a csv file. Everything works except that when I get the information about the manager I get the whole path like "CN=user01, OU=..." I would like to have the managers guid there instead, how can I accomplish that.

    My current code is:

    $Users = Get-ADGroupMember -Identity "GRP01" | Get-AdUser -Properties * | Select-Object ObjectGUID, SamAccountName, EmployeeID, Sn, GivenName, Mail, Manager
    
    $Users | Export-Csv -Path "D:\Dump\Dump.csv" -Encoding UTF8 -NoTypeInformation

    Thanks!
    • Edited by [zid] Tuesday, September 25, 2018 8:32 AM
    Tuesday, September 25, 2018 8:26 AM

Answers

  • Similar to:

    $Results = @()
    $Users = Get-ADGroupMember -Identity "GRP01" | Get-ADUser -Properties employeeID, sn, givenName, mail, manager | Select-Object objectGUID, sAMAccountName, employeeID, sn, givenName, mail, manager
    ForEach ($User In $Users)
    {
        If ($User.manager)
        {
            $ManagerGUID = (Get-ADObject -Identity $User.manager).objectGUID 
        }
        Else {$ManagerGUID = "None"}
        $Results += New-Object PsObject -Property @{
            ObjectGUID = $User.objectGUID
            SamAccountName = $User.sAMAccountName
            EmployeeID = $User.employeeID
            SN = $User.sn
            GivenName = $User.givenName
            Mail = $User.mail
            Manager = $ManagerGUID
        }
    }
    $Results | Export-CSV -Path "D:\Dump\Dump.csv" -Encoding UTF8 -NoTypeInformation
    


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Marked as answer by [zid] Tuesday, September 25, 2018 12:32 PM
    Tuesday, September 25, 2018 12:29 PM

All replies

  • You have to use the DN to get the manager account then get the GUID from the account.


    \_(ツ)_/

    Tuesday, September 25, 2018 9:01 AM
  • yea but how... =P
    Tuesday, September 25, 2018 11:37 AM
  • Get-AdUser <managerDN> | select -Expand objectGUID


    \_(ツ)_/

    Tuesday, September 25, 2018 12:00 PM
  • hi jrv,

    i got that part but how to pull that into the other code so that my export will include that result instead...

    Tuesday, September 25, 2018 12:17 PM
  • Similar to:

    $Results = @()
    $Users = Get-ADGroupMember -Identity "GRP01" | Get-ADUser -Properties employeeID, sn, givenName, mail, manager | Select-Object objectGUID, sAMAccountName, employeeID, sn, givenName, mail, manager
    ForEach ($User In $Users)
    {
        If ($User.manager)
        {
            $ManagerGUID = (Get-ADObject -Identity $User.manager).objectGUID 
        }
        Else {$ManagerGUID = "None"}
        $Results += New-Object PsObject -Property @{
            ObjectGUID = $User.objectGUID
            SamAccountName = $User.sAMAccountName
            EmployeeID = $User.employeeID
            SN = $User.sn
            GivenName = $User.givenName
            Mail = $User.mail
            Manager = $ManagerGUID
        }
    }
    $Results | Export-CSV -Path "D:\Dump\Dump.csv" -Encoding UTF8 -NoTypeInformation
    


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Marked as answer by [zid] Tuesday, September 25, 2018 12:32 PM
    Tuesday, September 25, 2018 12:29 PM
  • wow, thanks alot, that was more code than I was expecting, so it might be more complicated than I thought.

    Thanks!

    Tuesday, September 25, 2018 12:32 PM