-
Notifications
You must be signed in to change notification settings - Fork 52
/
Get-SIDFromAccount.ps1
61 lines (57 loc) · 2.24 KB
/
Get-SIDFromAccount.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function Get-SIDFromAccount {
<#
.SYNOPSIS
Fce pro zjisteni SID zadaneho uzivatele ci skupiny.
.DESCRIPTION
Ve vychozim nastaveni preklada lokalni ucty. Pro domenove je potreba zadat i nepovinny parametr domain.
Ale pozor, pokud dany ucet nebude nalezen lokalne, tak se zkusi nalezt v domene.
.PARAMETER AccountName
Jmeno uzivatele ci skupiny.
.PARAMETER Domain
Switch, ktery se pouziva pokud chci prekladat domenove ucty.
.PARAMETER ComputerName
Jmeno stroje, na kterem ma dojit k prekladu loginu.
.EXAMPLE
Get-SIDFromAccount administrator
.EXAMPLE
Get-SIDFromAccount administrator -domain
.EXAMPLE
Get-SIDFromAccount -accountname _sokrates05 -computername sokrates05
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = "zadej jmeno uzivatele ci skupiny")]
$AccountName
,
[switch]$Domain
,
[string]$computerName
)
if ($computerName) {
Invoke-Command -ComputerName $ComputerName -ScriptBlock {
if ($using:Domain) {
# ziskani jmena domeny do ktere je stroj zapojeny
$DomainName = (gwmi WIN32_ComputerSystem).Domain
} else {
$DomainName = ""
}
try {
((New-Object System.Security.Principal.NTAccount("$DomainName", "$using:AccountName")).Translate([System.Security.Principal.SecurityIdentifier])).Value
} catch {
throw "Ucet $using:AccountName se nepodarilo prelozit. Bud neexistuje nebo jste spatne zvolili jeho typ (lokalni|domenovy)."
}
}
} else {
if ($Domain) {
# ziskani jmena domeny do ktere je stroj zapojeny
$DomainName = (gwmi WIN32_ComputerSystem).Domain
} else {
$DomainName = ""
}
try {
((New-Object System.Security.Principal.NTAccount("$DomainName", "$AccountName")).Translate([System.Security.Principal.SecurityIdentifier])).Value
} catch {
throw "Ucet $AccountName se nepodarilo prelozit. Bud neexistuje nebo jste spatne zvolili jeho typ (lokalni|domenovy).`nPokud jde o computer ucet, nezapomente dat za jmeno $"
}
}
}