2 minute read

Oh My GUID!

Convert GUIDs into human-readable User Naming Attributes with the help of PowerShell

:information_source: A Globally Unique Identifier or GUID is a special type of identifier used in software applications in order to provide a reference number which is unique in any context (hence, “Globally”), for example, in defining the internal reference for a type of access point in a software application, or for creating unique keys in a database.

Here’s how you get the GUIDs from all AD-users in a specific Organizational Unit in Active Directory if you haven’t got any GUIDs laying around :wink:

$OUpath = "OU=Users,OU=cloud-lab,DC=cloudpilot,DC=local"

Get-ADUser -Properties * -Filter * -SearchBase $OUpath | Select-Object -ExpandProperty ObjectGUID |  Export-Csv -Path C:\Temp\GUIDs.csv

The code above will result in a nice formatted list. I recommend copying it out or using PowerShells own cmdlet, Export-CSV for saving it to a file for later use.

GUID,
5739d233-dcd3-4749-848f-11f12bdaf799,
f914a952-b7dc-4397-9dc6-db696b6fcb52,
98b07a42-00fc-4043-b9b8-20b730c5e5e5,
7ea2e1ff-33c2-4762-a4ff-254d587d93e6,
e203ec74-e1a3-413b-81ca-814217049ca4,
a3e57ede-7c18-4f32-abc1-79e7c4718234,
c10c4f61-f292-4392-9ea6-8e04504055f1,
c92e1aad-08d2-4497-9d97-e3e6a81995f7,
b9abe513-8367-474a-9ecc-3fac0d636b29,
bb442ef4-632e-4499-acf8-70e861396845,
b0bd6849-7007-41ab-8d11-4423e335d52e,
36c817c0-7b76-4e17-88c0-b0ba7c58d141,
6e43c9a4-7e6c-440b-aabf-d0e3db7c4416,
9cceebe7-1158-4722-8464-af663fa867aa,
2257618f-cbc0-4679-a1c7-f1f61f6f197c,
ce129d69-1072-4972-b44b-f6bd0a764892,
83549a03-aff2-495f-a421-7a7cbcf531d4,
57085c9b-e7af-4893-a360-76a51e7d6f2f,
1e2c17e6-ccee-411d-b7b9-b0a7994113cb,
1a41b622-ec3a-490b-bd84-84a41f3f844a,

After you have successfully saved a list containing your GUIDs, it’s time to obtain their sAMAccountName.

Below you can see my approch to achieve this:

I make a variable (called $GUID) who points to my newly exported CSV-list containing all my GUIDs. Then I use a foreach-loop who iterates through every GUID in my list, obtaining the AD-user it belongs to, and then saves it to my $ADuser variable.

For convenience I’ve put in a simple Write-Host at the end. It writes out the sAMAccountName and their corresponding GUID. Handy to have both values at the same line.

$GUID = Import-CSV C:\Temp\GUIDs.csv

foreach ($G in $GUID) {

$ADuser = Get-ADUser "$($G.GUID)"

Write-Host "GUID for user $($ADuser.samAccountName) is $($ADuser.ObjectGUID)"

}

Final output:

GUID for user ksnowling0 is 5739d233-dcd3-4749-848f-11f12bdaf799
GUID for user htibbotts1 is f914a952-b7dc-4397-9dc6-db696b6fcb52
GUID for user arene2 is 98b07a42-00fc-4043-b9b8-20b730c5e5e5
GUID for user tbaleine3 is 7ea2e1ff-33c2-4762-a4ff-254d587d93e6
GUID for user cburnsell4 is e203ec74-e1a3-413b-81ca-814217049ca4
GUID for user stiron5 is a3e57ede-7c18-4f32-abc1-79e7c4718234
GUID for user lparlour6 is c10c4f61-f292-4392-9ea6-8e04504055f1
GUID for user lshackle7 is c92e1aad-08d2-4497-9d97-e3e6a81995f7
GUID for user mgiordano8 is b9abe513-8367-474a-9ecc-3fac0d636b29
GUID for user lmccorry9 is bb442ef4-632e-4499-acf8-70e861396845
GUID for user sdafta is b0bd6849-7007-41ab-8d11-4423e335d52e
GUID for user nturfusb is 36c817c0-7b76-4e17-88c0-b0ba7c58d141
GUID for user cgiroldoc is 6e43c9a4-7e6c-440b-aabf-d0e3db7c4416
GUID for user djaradd is 9cceebe7-1158-4722-8464-af663fa867aa
GUID for user ffrackiewicze is 2257618f-cbc0-4679-a1c7-f1f61f6f197c
GUID for user hsmithf is ce129d69-1072-4972-b44b-f6bd0a764892
GUID for user astoreyg is 83549a03-aff2-495f-a421-7a7cbcf531d4
GUID for user vmurtyh is 57085c9b-e7af-4893-a360-76a51e7d6f2f
GUID for user dcowapi is 1e2c17e6-ccee-411d-b7b9-b0a7994113cb
GUID for user kgiannasij is 1a41b622-ec3a-490b-bd84-84a41f3f844a

Now you know how to retrieve AD-usernames from GUIDs! :blush:

Comments