Last active
December 24, 2023 16:53
-
-
Save drlsdee/713171eb3eb847b7b30e2dc6ab4f27ee to your computer and use it in GitHub Desktop.
Generates an object identifier (OID) using a GUID and the OID prefix 1.2.840.113556.1.8000.2554 (or any other you like). Inspired by this: https://gallery.technet.microsoft.com/scriptcenter/Generate-an-Object-4c9be66a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspired by this: https://gallery.technet.microsoft.com/scriptcenter/Generate-an-Object-4c9be66a | |
# Generates an object identifier (OID) using a GUID and the OID prefix 1.2.840.113556.1.8000.2554 (or any other). | |
function New-ADCustomAttributeOID { | |
[CmdletBinding()] | |
[OutputType([string])] | |
param ( | |
# OID Prefix | |
[Parameter()] | |
[string] | |
$Prefix = '1.2.840.113556.1.8000.2554' | |
) | |
[string]$GUID = [System.Guid]::NewGuid().Guid.ToString('N') # See: https://learn.microsoft.com/en-us/dotnet/api/system.guid.tostring | |
[int]$step = 4 | |
[string[]]$Parts = ,$Prefix + @( | |
for ($i = 0; $i -le 26; $i += $step) { | |
if ($i -ge 20) { | |
[int]$step = 6 | |
} | |
[uint64]::Parse($GUID.Substring($i,$step),[System.Globalization.NumberStyles]::AllowHexSpecifier) # See: https://learn.microsoft.com/ru-ru/dotnet/api/system.globalization.numberstyles | |
} | |
) | |
[string]$OID = [string]::Join('.', $Parts) | |
return $OID | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
About OID prefix:Microsoft Learn
BTW, I suspect that everybody use the sample root OID "1.2.840.113556.1.8000.2554" from the article.
Yes, it's base OID for customer usage, but I think it would be better to append some child bytes before creating custom attributes and classes in the your AD schema.