@@ -10,27 +10,42 @@ Function Show-UserSID {
10
10
Specifies the user name for which to retrieve the SID.
11
11
12
12
. EXAMPLE
13
- Show-UserSID -UserName "your_user"
13
+ "your_user" | Show-UserSID
14
+ Show-UserSID -UserName "your_user" -OutputFormat List
14
15
15
16
. NOTES
16
- v0.0.2
17
+ v0.0.3
17
18
#>
18
19
[CmdletBinding ()]
19
20
param (
20
- [Parameter (Mandatory , Position = 0 , ValueFromPipeline = $true , HelpMessage = " Specify the user name" )]
21
+ [Parameter (Mandatory = $true , Position = 0 , ValueFromPipeline = $true , HelpMessage = " Specify the user name" )]
21
22
[ValidateNotNullOrEmpty ()]
22
23
[Alias (" u" )]
23
- [string ]$UserName
24
+ [string ]$UserName ,
25
+
26
+ [Parameter (Mandatory = $false , Position = 1 , HelpMessage = " Specify the output format. Options: 'Table' (default), 'List', 'JSON'" )]
27
+ [ValidateSet (" Table" , " List" , " JSON" )]
28
+ [string ]$OutputFormat = " Table"
24
29
)
25
- process {
30
+ PROCESS {
26
31
try {
27
32
$NTAccount = New-Object System.Security.Principal.NTAccount($UserName )
28
33
$UserSID = $NTAccount.Translate ([System.Security.Principal.SecurityIdentifier ]).Value
29
34
$Result = [PSCustomObject ]@ {
30
35
UserName = $UserName
31
36
SID = $UserSID
32
37
}
33
- Write-Output - InputObject $Result
38
+ switch ($OutputFormat ) {
39
+ " List" {
40
+ Write-Output $Result.PSObject.Properties | ForEach-Object { " $ ( $_.Name ) : $ ( $_.Value ) " }
41
+ }
42
+ " JSON" {
43
+ $Result | ConvertTo-Json
44
+ }
45
+ default {
46
+ Write-Output $Result | Format-Table - AutoSize
47
+ }
48
+ }
34
49
}
35
50
catch {
36
51
Write-Error - Message " Failed to get SID for user '$UserName '. $_ "
0 commit comments