Convert-SIDToUser.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function Convert-SIDToUser
{
    <#
        .SYNOPSIS
        Converts SID to user name
 
        .DESCRIPTION
        Converts a security identifier (SID) to a real user name
 
        .PARAMETER SID
        The security identifier to convert
 
        .EXAMPLE
        "S-1-5-32-544" | Convert-SIDToUser
        Converts the sid to a user name
 
        .EXAMPLE
        Convert-SIDToUser -SID "S-1-5-32-544"
        Converts the sid to a user name
    #>



  param
  (
    [string]
    [Parameter(Mandatory,ValueFromPipeline)]
    $SID
  )
  process
  {
    (New-Object System.Security.Principal.SecurityIdentifier($SID)).Translate( [System.Security.Principal.NTAccount]).Value
  }
}