diff --git a/lib/ansible/modules/windows/win_user.ps1 b/lib/ansible/modules/windows/win_user.ps1 index cf3a178c6b..0ca11c743a 100644 --- a/lib/ansible/modules/windows/win_user.ps1 +++ b/lib/ansible/modules/windows/win_user.ps1 @@ -102,10 +102,10 @@ If ($account_locked -ne $null) { $groups = Get-Attr $params "groups" $null If ($groups -ne $null) { - If ($groups.GetType().Name -eq "String") { + If ($groups -is [System.String]) { [string[]]$groups = $groups.Split(",") } - ElseIf ($groups.GetType().Name -ne "Object[]") { + ElseIf ($groups -isnot [System.Collections.IList]) { Fail-Json $result "groups must be a string or array" } $groups = $groups | ForEach { ([string]$_).Trim() } | Where { $_ } @@ -125,7 +125,7 @@ $user_obj = Get-User $username If ($state -eq 'present') { # Add or update user try { - If (-not $user_obj -or -not $user_obj.GetType) { + If (-not $user_obj) { $user_obj = $adsi.Create("User", $username) If ($password -ne $null) { $user_obj.SetPassword($password) @@ -190,7 +190,7 @@ If ($state -eq 'present') { ForEach ($grp in $current_groups) { If ((($groups_action -eq "remove") -and ($groups -contains $grp)) -or (($groups_action -eq "replace") -and ($groups -notcontains $grp))) { $group_obj = $adsi.Children | where { $_.SchemaClassName -eq 'Group' -and $_.Name -eq $grp } - If ($group_obj -and $group_obj.GetType) { + If ($group_obj) { $group_obj.Remove($user_obj.Path) $result.changed = $true } @@ -204,7 +204,7 @@ If ($state -eq 'present') { ForEach ($grp in $groups) { If ($current_groups -notcontains $grp) { $group_obj = $adsi.Children | where { $_.SchemaClassName -eq 'Group' -and $_.Name -eq $grp } - If ($group_obj.GetType) { + If ($group_obj) { $group_obj.Add($user_obj.Path) $result.changed = $true } @@ -223,7 +223,7 @@ If ($state -eq 'present') { ElseIf ($state -eq 'absent') { # Remove user try { - If ($user_obj -and $user_obj.GetType) { + If ($user_obj) { $username = $user_obj.Name.Value $adsi.delete("User", $user_obj.Name.Value) $result.changed = $true @@ -236,7 +236,7 @@ ElseIf ($state -eq 'absent') { } try { - If ($user_obj -and $user_obj.GetType) { + If ($user_obj -and $user_obj -is [System.DirectoryServices.DirectoryEntry]) { $user_obj.RefreshCache() Set-Attr $result "name" $user_obj.Name[0] Set-Attr $result "fullname" $user_obj.FullName[0]