none
Help with Powershell piping query

    Pergunta

  • We are using Quest Powershell. An object has SIDvalue 1234. The name is User1.

    So if I run:

    get-QADUser -identity User1 | fl

    One of the returned values is:

    objectGUID: 1234

    Now, what I need to do is find a Powershell command that will return the "DisplayName" attribute if I know the objectGUID.

    Does anyone know how I can do this?

    And, if I have a list of objectGUID's in a file named GUID.csv, how can I do the above?

    Any help really appreciated!
    domingo, 11 de março de 2012 20:38

Respostas

Todas as Respostas

  • You can directly query AD using get-qadobject -identity objectguid

    Get-QADObject -Identity "d9cd9083-cb47-4f63-bfc2-1a7670ef511e"


    Shaba

    domingo, 11 de março de 2012 20:49
  • If you have a CSV file with GUID,

    Import-Csv .\guid.csv |ForEach-Object {Get-QADObject $_.guid}

    The CSV file I used is as below.

    [PS] C:\Users\exadmin>Import-Csv .\guid.csv

    Guid
    ----
    82185384-3399-4357-bd0e-7fe651bfd3bc
    9ba314aa-54e9-465a-8bba-4b912b119461

    Good luck !



    Shaba

    domingo, 11 de março de 2012 20:52
  • Hello

    No, this command doesn't work:

    get-qadobject -identity objectguid

    It works for GUID, but not objectGUID (two different values in our case).

    domingo, 11 de março de 2012 21:08
  • PS > (Get-QADUser kazun).objectGUID
    1B89525A63CA2248BF68DA5F68A9101E
    PS > Get-QADUser -LdapFilter "(objectGUID=\1B\89\52\5A\63\CA\22\48\BF\68\DA\5F\68\A9\10\1E)"
    
    Name                           Type            DN
    ----                           ----            --
    Kazun                          user            CN=Kazun....
    
    
    PS > Get-QADUser -LdapFilter "(objectGUID=\1B\89\52\5A\63\CA\22\48\BF\68\DA\5F\68\A9\10\1E)" | fl
    displayname
    
    DisplayName : Kazun
    
    Convert objectguid from Get-QADUser to LDAP:
    PS >  "1B89525A63CA2248BF68DA5F68A9101E" -replace "(\w{2})",'\$1'
    \1B\89\52\5A\63\CA\22\48\BF\68\DA\5F\68\A9\10\1E
    
    or second variant using param Identity
    
    PS > (Get-QADUser kazun).objectGUID
    1B89525A63CA2248BF68DA5F68A9101E
    
    #Show nothing,because you must reverse byte order in array
    PS > Get-QADUser -Identity 1B89525A63CA2248BF68DA5F68A9101E
    
    PS >  $guid = "1B89525A63CA2248BF68DA5F68A9101E"
    PS >  -join (([GUID]$guid).ToByteArray() |% {"{0:x}" -f $_})
    5a52891bca634822bf68da5f68a9101e
    
    PS > Get-QADUser -Identity 5a52891bca634822bf68da5f68a9101e | fl  displayname
    
    DisplayName : Kazun
    

    domingo, 11 de março de 2012 21:11
  • Thanks, but do you know how I would run that second variant in a script if I have a bunch of objectGUID's?

    Also, would it not be easier to write a query that says:

    i. get-qaduser where objectGUID is equal to first objectGUID in csv file

    ii. for the value returned, give DisplayName

    domingo, 11 de março de 2012 21:23
  • #For all guids
    
    Import-Csv C:\objectguid.csv | Foreach {
    	Get-QADUser -Identity (-join (([GUID]$_.objectguid).ToByteArray() |% {"{0:x}" -f $_}))
    } | Format-Table DisplayName
    
    #First only
    
    Import-Csv C:\user.csv | Select -First 1 | Foreach {
    	Get-QADUser -Identity (-join (([GUID]$_.objectguid).ToByteArray() |% {"{0:x}" -f $_}))
    } | Format-Table DisplayName

    domingo, 11 de março de 2012 21:30
  • Shorter I thing:

    $guid = get-QADuser 'user' |%{$_.DirectoryEntry.objectGuid} | convert-QADAttributeValue -outputTypeName 'Guid'

    $u = get-qaduser -identity $guid

    domingo, 11 de março de 2012 23:26
  • Hi Kazun

    So I ran the below:

    Import-Csv C:\guid.csv | Foreach {Get-QADUser -Identity (-join (([GUID]$_.objectguid).ToByteArray() |% {"{0:x}" -f $_}))} | Format-Table DisplayName

    But I am not getting any results back? Even though the objectGUID listed in the CSV file definately matches that of an AD user?

    terça-feira, 13 de março de 2012 01:03
  • Hi,

    I would like suggest you refer to the below links for more information about changing objectGUID to GUID:

    http://www.powergui.org/thread.jspa?threadID=7680

    And

    Using objectGUID to Bind to an Object

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms677985(v=vs.85).aspx

    Best Regards,

    Yan Li


    Yan Li

    TechNet Community Support


    sexta-feira, 16 de março de 2012 07:41
    Moderador