Assign the value of ObjectGUID to a string variable in Powershell

The ObjectGUID property of an AD object is weird. I tried using -Expand and foreach{$_.ObjectGUID} to extract the value, but neither did quite what I expected. Here’s how I was able to get the value of that property into a string variable that I could then use for something useful.

$uGuid = (Get-ADUser <username> | Select -Expand ObjectGUID).toString()

The value of $uGuid will be the string value of ObjectGUID and not the System.Object Guid or System.Object objectguid.

Leave a Reply

Your email address will not be published. Required fields are marked *