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.
This commit is contained in:
parent
ee90762388
commit
2f46c35f47
1 changed files with 7 additions and 7 deletions
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue