From 53fbbe7bf34d77d9f936cb2ecc565ec859adbd89 Mon Sep 17 00:00:00 2001 From: Tony Pagliaro Date: Thu, 4 Feb 2021 14:19:39 -0500 Subject: [PATCH] Substitute replace method for join operator Hi. Just came across your script, it didn't work for me. I made this change and then it worked on my end. Also I added another way to get the info added to the existing object in your sample below. --- Convert-AzureAdObjectIdToSid.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Convert-AzureAdObjectIdToSid.ps1 b/Convert-AzureAdObjectIdToSid.ps1 index a49ee6b..ae3a342 100644 --- a/Convert-AzureAdObjectIdToSid.ps1 +++ b/Convert-AzureAdObjectIdToSid.ps1 @@ -18,7 +18,7 @@ The Object ID to convert $array = New-Object 'UInt32[]' 4 [Buffer]::BlockCopy($bytes, 0, $array, 0, 16) - $sid = "S-1-12-1-$array".Replace(' ', '-') + $sid = "S-1-12-1-$($array -join '-')" return $sid } @@ -29,4 +29,7 @@ Write-Output $sid # Output: -# S-1-12-1-1943430372-1249052806-2496021943-3034400218 \ No newline at end of file +# S-1-12-1-1943430372-1249052806-2496021943-3034400218 + +# You must be connected to AzureAD first, then run this: +Get-AzureADUser | foreach {$_ | Select *, @{n='SID';e={Convert-AzureAdObjectIdToSid -ObjectId ($_.ObjectId)}}}