Copy AD User Object GUID to Clipboard

Thomas M 26 Reputation points
2021-05-18T21:23:55.88+00:00

My PowerShell skills are not very strong so I am struggling with something that I suspect is fairly straight-forward. I have the following simple code:

 $User = Read-Host "Enter the User ID"

 Get-ADUser -Identity $User | Select ObjectGUID | Set-Clipboard

This almost does what I want. The below line is what I am getting for output (I have sanitized the GUID out of an abundance of caution, but the code does pull the actual GUID):

 @{ObjectGUID=##a###a#-a#aa-##aa-#aaa-###aaa#a####}

What I would really like is to get rid of everything up to and including the "=" and the trailing "}" bracket, so that only the actual GUID is copied to the clipboard.

What am I missing?

Thanks in advance for any help that you can offer!

--Tom

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2021-05-18T21:49:54.28+00:00

    Hi @Thomas M ,

    could you please test this (here it works):

     $User = Read-Host "Enter the User ID"  
     (Get-ADUser -Identity $User).ObjectGUID | Set-Clipboard  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


1 additional answer

Sort by: Most helpful
  1. Anonymous
    2021-05-19T03:47:11.117+00:00

    Hi,

    You could just add the "-ExpandProperty" switch to the "select" cmdlet.

    Get-ADUser -Identity $User | Select -ExpandProperty ObjectGUID | Set-Clipboard  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.