diff options
author | nitzmahone <mdavis@ansible.com> | 2016-04-07 18:25:41 -0700 |
---|---|---|
committer | nitzmahone <mdavis@ansible.com> | 2016-04-07 18:25:41 -0700 |
commit | 2f46c35f471b18f369c357016d0e430a65f8429b (patch) | |
tree | 35722ea80787d735a03db6083e3743de5d03f868 /windows | |
parent | ee907623888edbe6db99a870285817c51e904cad (diff) | |
download | ansible-modules-core-2f46c35f471b18f369c357016d0e430a65f8429b.tar.gz |
fix win_user type checking
Fixed type checking to be more idiomatic powershell, also fixes a slew of StrictMode issues and gets error handling back to originally-intended behavior.
Diffstat (limited to 'windows')
-rw-r--r-- | windows/win_user.ps1 | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/windows/win_user.ps1 b/windows/win_user.ps1 index cf3a178c..0ca11c74 100644 --- a/windows/win_user.ps1 +++ b/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] |