added userprincipal support
This commit is contained in:
parent
71dc569566
commit
21c564848d
1 changed files with 12 additions and 8 deletions
|
@ -52,7 +52,6 @@ Function UserSearch
|
||||||
$IsLocalAccount = $true
|
$IsLocalAccount = $true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($IsLocalAccount -eq $true)
|
if ($IsLocalAccount -eq $true)
|
||||||
{
|
{
|
||||||
# do not use Win32_UserAccount, because e.g. SYSTEM (BUILTIN\SYSTEM or COMPUUTERNAME\SYSTEM) will not be listed. on Win32_Account groups will be listed too
|
# do not use Win32_UserAccount, because e.g. SYSTEM (BUILTIN\SYSTEM or COMPUUTERNAME\SYSTEM) will not be listed. on Win32_Account groups will be listed too
|
||||||
|
@ -62,13 +61,19 @@ Function UserSearch
|
||||||
return $localaccount.SID
|
return $localaccount.SID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ElseIf (($IsDomainAccount -eq $true) -and ($IsUpn -eq $false))
|
ElseIf ($IsDomainAccount -eq $true)
|
||||||
{
|
{
|
||||||
#Search by samaccountname
|
#Search by samaccountname
|
||||||
$Searcher = [adsisearcher]""
|
$Searcher = [adsisearcher]""
|
||||||
$Searcher.Filter = "sAMAccountName=$($accountname.split("\")[1])"
|
|
||||||
$result = $Searcher.FindOne()
|
|
||||||
|
|
||||||
|
If ($IsUpn -eq $false) {
|
||||||
|
$Searcher.Filter = "sAMAccountName=$($accountname.split("\")[1])"
|
||||||
|
}
|
||||||
|
Else {
|
||||||
|
$Searcher.Filter = "userPrincipalName=$($accountname)"
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $Searcher.FindOne()
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$user = $result.GetDirectoryEntry()
|
$user = $result.GetDirectoryEntry()
|
||||||
|
@ -80,7 +85,6 @@ Function UserSearch
|
||||||
return (New-Object System.Security.Principal.SecurityIdentifier($binarySID,0)).Value
|
return (New-Object System.Security.Principal.SecurityIdentifier($binarySID,0)).Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$params = Parse-Args $args;
|
$params = Parse-Args $args;
|
||||||
|
|
Loading…
Reference in a new issue