Skip to content

Instantly share code, notes, and snippets.

@drlsdee
Last active December 24, 2023 16:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save drlsdee/713171eb3eb847b7b30e2dc6ab4f27ee to your computer and use it in GitHub Desktop.
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
# 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
}
@drlsdee
Copy link
Author

drlsdee commented Feb 9, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment