From 21a5f8f4e72080deff6c26d7bad681ca4f9bfce7 Mon Sep 17 00:00:00 2001 From: Joshua Rose <49696165+Joshua-rose@users.noreply.github.com> Date: Thu, 9 Jan 2020 17:08:44 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=A4=20user=20mapping=20error=20vs=20ot?= =?UTF-8?q?her=20system=20errors=20=F0=9F=92=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In my application, I needed to differentiate between users not mapped and domain trust issues. I thought the change may be useful for others too. Thanks for writing a terrific script. --- ConvertFrom-SID.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ConvertFrom-SID.ps1 b/ConvertFrom-SID.ps1 index 14b09055..d2d956d5 100644 --- a/ConvertFrom-SID.ps1 +++ b/ConvertFrom-SID.ps1 @@ -149,9 +149,13 @@ function ConvertFrom-SID { $objSID = New-Object System.Security.Principal.SecurityIdentifier($id) $name = ( $objSID.Translate([System.Security.Principal.NTAccount]) ).Value } + Catch [System.Security.Principal.IdentityNotMappedException] { + $name = "Not a valid SID. Could not be mapped to an user account" + Write-Verbose "$id is not a valid SID. $id could not be mapped to a user account." + } Catch{ $name = "Not a valid SID or could not be identified" - Write-Verbose "$id is not a valid SID or could not be identified" + Write-Verbose "$id is not a valid SID or could not be identified due to a system error" } }