Skip to content

Commit 151d61e

Browse files
Merge pull request KelvinTegelaar#1894 from kris6673/SID
feat: Add SID conversion to group and role functions
2 parents ac5bf25 + 2512721 commit 151d61e

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-ListGroups.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ function Invoke-ListGroups {
107107
allowExternal = (!$OnlyAllowInternal)
108108
sendCopies = $SendCopies
109109
hideFromOutlookClients = if ($GroupType -eq 'Microsoft 365') { $UnifiedGroupInfo.HiddenFromExchangeClientsEnabled } else { $null }
110+
SID = (Convert-AzureAdObjectIdToSid -ObjectID $((($RawGraphRequest | Where-Object { $_.id -eq 1 }).body).id))
110111
}
111112
} else {
112113
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/groups/$($GroupID)/$($members)?`$top=999&select=$SelectString" -tenantid $TenantFilter | Select-Object *, @{ Name = 'primDomain'; Expression = { $_.mail -split '@' | Select-Object -Last 1 } },
@@ -126,7 +127,8 @@ function Invoke-ListGroups {
126127
elseif (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (-not $_.securityEnabled)) { 'distributionList' }
127128
}
128129
},
129-
@{Name = 'dynamicGroupBool'; Expression = { if ($_.groupTypes -contains 'DynamicMembership') { $true } else { $false } } }
130+
@{Name = 'dynamicGroupBool'; Expression = { if ($_.groupTypes -contains 'DynamicMembership') { $true } else { $false } } },
131+
@{Name = 'SID'; Expression = { Convert-AzureAdObjectIdToSid -ObjectID $_.id } }
130132
$GraphRequest = @($GraphRequest | Sort-Object displayName)
131133
}
132134

Modules/CIPPCore/Public/Entrypoints/Invoke-ListRoles.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function Invoke-ListRoles {
2626
DisplayName = $Role.displayName
2727
Description = $Role.description
2828
Members = @($Members)
29+
SID = (Convert-AzureAdObjectIdToSid -ObjectID $Role.id)
2930
}
3031
}
3132
$StatusCode = [HttpStatusCode]::OK
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function Convert-AzureAdObjectIdToSid {
2+
<#
3+
.SYNOPSIS
4+
Converts an Azure AD / Entra ID Object ID (GUID) to its Windows SID representation.
5+
.DESCRIPTION
6+
Parses the 16-byte GUID of an Azure AD Object ID and re-interprets the bytes as four
7+
unsigned 32-bit integers, producing a SID in the form S-1-12-1-{b0}-{b1}-{b2}-{b3}.
8+
This is the format used by Microsoft when translating cloud identities to on-premises
9+
or hybrid Windows security contexts.
10+
.PARAMETER ObjectID
11+
The Azure AD / Entra ID Object ID (GUID) to convert. Must be a valid GUID string.
12+
.FUNCTIONALITY
13+
Internal
14+
.EXAMPLE
15+
Convert-AzureAdObjectIdToSid -ObjectID '00000000-0000-0000-0000-000000000001'
16+
Returns the Windows SID corresponding to the specified Entra ID Object ID.
17+
#>
18+
param (
19+
[parameter(Mandatory = $true)][string]$ObjectID
20+
)
21+
22+
$Bytes = [Guid]::Parse($ObjectId).ToByteArray()
23+
$Array = New-Object 'UInt32[]' 4
24+
25+
[Buffer]::BlockCopy($Bytes, 0, $Array, 0, 16)
26+
$Sid = "S-1-12-1-$Array".Replace(' ', '-')
27+
return $Sid
28+
}

0 commit comments

Comments
 (0)