mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
added userprincipal support
This commit is contained in:
parent
65d5658553
commit
de4a271dd0
1 changed files with 11 additions and 7 deletions
|
@ -49,7 +49,6 @@ Function UserSearch
|
|||
$IsLocalAccount = $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
|
||||
|
@ -59,13 +58,19 @@ Function UserSearch
|
|||
return $localaccount.SID
|
||||
}
|
||||
}
|
||||
ElseIf (($IsDomainAccount -eq $true) -and ($IsUpn -eq $false))
|
||||
ElseIf ($IsDomainAccount -eq $true)
|
||||
{
|
||||
#Search by samaccountname
|
||||
$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)
|
||||
{
|
||||
$user = $result.GetDirectoryEntry()
|
||||
|
@ -77,7 +82,6 @@ Function UserSearch
|
|||
return (New-Object System.Security.Principal.SecurityIdentifier($binarySID,0)).Value
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$params = Parse-Args $args;
|
||||
|
|
Loading…
Reference in a new issue