diff options
author | Hans-Joachim Kliemeck <git@kliemeck.de> | 2015-10-17 23:10:56 +0200 |
---|---|---|
committer | Hans-Joachim Kliemeck <git@kliemeck.de> | 2015-10-17 23:10:56 +0200 |
commit | cda7e96fcc277ecf285bb61264882a60f91ab9a9 (patch) | |
tree | d30fb22e314968a2ceb77bd6911bbdcbf52ae469 /windows/win_owner.ps1 | |
parent | 7c8e3f4da1acb4f1c5b341e476faa7db288c1531 (diff) | |
download | ansible-modules-extras-cda7e96fcc277ecf285bb61264882a60f91ab9a9.tar.gz |
added userprincipal support
Diffstat (limited to 'windows/win_owner.ps1')
-rw-r--r-- | windows/win_owner.ps1 | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/windows/win_owner.ps1 b/windows/win_owner.ps1 index 5af5072b..519d6fe5 100644 --- a/windows/win_owner.ps1 +++ b/windows/win_owner.ps1 @@ -48,8 +48,7 @@ Function UserSearch $accountname = $env:COMPUTERNAME + "\" + $AccountName $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; |