Windows pslint: Re-enable PSPossibleIncorrectComparisonWithNull (#55065)
* pslint fixes * Fix up remaining sanity issues * now fix silly errors I made
This commit is contained in:
parent
a2eb227970
commit
025e9afe58
38 changed files with 269 additions and 272 deletions
|
@ -27,7 +27,7 @@ Function Get-BecomeFlags($flags) {
|
|||
$logon_type = [Ansible.Become.LogonType]::LOGON32_LOGON_INTERACTIVE
|
||||
$logon_flags = [Ansible.Become.LogonFlags]::LOGON_WITH_PROFILE
|
||||
|
||||
if ($flags -eq $null -or $flags -eq "") {
|
||||
if ($null -eq $flags -or $flags -eq "") {
|
||||
$flag_split = @()
|
||||
} elseif ($flags -is [string]) {
|
||||
$flag_split = $flags.Split(" ")
|
||||
|
|
|
@ -288,7 +288,7 @@ if($gather_subset.Contains('interfaces')) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($gather_subset.Contains("local") -and $factpath -ne $null) {
|
||||
if ($gather_subset.Contains("local") -and $null -ne $factpath) {
|
||||
# Get any custom facts; results are updated in the
|
||||
Get-CustomFacts -factpath $factpath
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ Function New-CertFile($module, $cert, $path, $type, $password) {
|
|||
}
|
||||
if ($type -eq "pkcs12") {
|
||||
$missing_key = $false
|
||||
if ($cert.PrivateKey -eq $null) {
|
||||
if ($null -eq $cert.PrivateKey) {
|
||||
$missing_key = $true
|
||||
} elseif ($cert.PrivateKey.CspKeyContainerInfo.Exportable -eq $false) {
|
||||
$missing_key = $true
|
||||
|
@ -97,7 +97,7 @@ Function New-CertFile($module, $cert, $path, $type, $password) {
|
|||
$cert_bytes = $file_encoding.GetBytes($cert_content)
|
||||
} elseif ($type -eq "pkcs12") {
|
||||
$module.Result.key_exported = $false
|
||||
if ($cert.PrivateKey -ne $null) {
|
||||
if ($null -ne $cert.PrivateKey) {
|
||||
$module.Result.key_exportable = $cert.PrivateKey.CspKeyContainerInfo.Exportable
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,11 +122,11 @@ Function Get-DnsClientMatch {
|
|||
|
||||
$current_dns_v4 = ($current_dns_all | Where-Object AddressFamily -eq 2 <# IPv4 #>).ServerAddresses
|
||||
|
||||
If (($current_dns_v4 -eq $null) -and ($ipv4_addresses -eq $null)) {
|
||||
If (($null -eq $current_dns_v4) -and ($null -eq $ipv4_addresses)) {
|
||||
$v4_match = $True
|
||||
}
|
||||
|
||||
ElseIf (($current_dns_v4 -eq $null) -or ($ipv4_addresses -eq $null)) {
|
||||
ElseIf (($null -eq $current_dns_v4) -or ($null -eq $ipv4_addresses)) {
|
||||
$v4_match = $False
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ Function Set-DnsClientAddresses
|
|||
|
||||
Write-DebugLog ("Setting DNS addresses for adapter {0} to ({1})" -f $adapter_name, ($ipv4_addresses -join ", "))
|
||||
|
||||
If ($ipv4_addresses -eq $null) {
|
||||
If ($null -eq $ipv4_addresses) {
|
||||
Set-DnsClientServerAddress -InterfaceAlias $adapter_name -ResetServerAddress
|
||||
}
|
||||
|
||||
|
|
|
@ -59,13 +59,13 @@ if ($check_mode -and $installed) {
|
|||
|
||||
# Check that we got a valid domain_mode
|
||||
$valid_domain_modes = [Enum]::GetNames((Get-Command -Name Install-ADDSForest).Parameters.DomainMode.ParameterType)
|
||||
if (($domain_mode -ne $null) -and -not ($domain_mode -in $valid_domain_modes)) {
|
||||
if (($null -ne $domain_mode) -and -not ($domain_mode -in $valid_domain_modes)) {
|
||||
Fail-Json -obj $result -message "The parameter 'domain_mode' does not accept '$domain_mode', please use one of: $valid_domain_modes"
|
||||
}
|
||||
|
||||
# Check that we got a valid forest_mode
|
||||
$valid_forest_modes = [Enum]::GetNames((Get-Command -Name Install-ADDSForest).Parameters.ForestMode.ParameterType)
|
||||
if (($forest_mode -ne $null) -and -not ($forest_mode -in $valid_forest_modes)) {
|
||||
if (($null -ne $forest_mode) -and -not ($forest_mode -in $valid_forest_modes)) {
|
||||
Fail-Json -obj $result -message "The parameter 'forest_mode' does not accept '$forest_mode', please use one of: $valid_forest_modes"
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ if (-not $forest) {
|
|||
$install_params.DomainNetBiosName = $domain_netbios_name
|
||||
}
|
||||
|
||||
if ($create_dns_delegation -ne $null) {
|
||||
if ($null -ne $create_dns_delegation) {
|
||||
$install_params.CreateDnsDelegation = $create_dns_delegation
|
||||
}
|
||||
|
||||
|
|
|
@ -27,17 +27,17 @@ If (-not $sam_account_name.EndsWith("$")) {
|
|||
$enabled = Get-AnsibleParam -obj $params -name "enabled" -type "bool" -default $true
|
||||
$description = Get-AnsibleParam -obj $params -name "description" -default $null
|
||||
$domain_username = Get-AnsibleParam -obj $params -name "domain_username" -type "str"
|
||||
$domain_password = Get-AnsibleParam -obj $params -name "domain_password" -type "str" -failifempty ($domain_username -ne $null)
|
||||
$domain_password = Get-AnsibleParam -obj $params -name "domain_password" -type "str" -failifempty ($null -ne $domain_username)
|
||||
$domain_server = Get-AnsibleParam -obj $params -name "domain_server" -type "str"
|
||||
$state = Get-AnsibleParam -obj $params -name "state" -ValidateSet "present","absent" -default "present"
|
||||
|
||||
$extra_args = @{}
|
||||
if ($domain_username -ne $null) {
|
||||
if ($null -ne $domain_username) {
|
||||
$domain_password = ConvertTo-SecureString $domain_password -AsPlainText -Force
|
||||
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $domain_username, $domain_password
|
||||
$extra_args.Credential = $credential
|
||||
}
|
||||
if ($domain_server -ne $null) {
|
||||
if ($null -ne $domain_server) {
|
||||
$extra_args.Server = $domain_server
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ $diff_mode = Get-AnsibleParam -obj $params -name "_ansible_diff" -type "bool" -d
|
|||
$name = Get-AnsibleParam -obj $params -name "name" -type "str" -failifempty $true
|
||||
$display_name = Get-AnsibleParam -obj $params -name "display_name" -type "str"
|
||||
$domain_username = Get-AnsibleParam -obj $params -name "domain_username" -type "str"
|
||||
$domain_password = Get-AnsibleParam -obj $params -name "domain_password" -type "str" -failifempty ($domain_username -ne $null)
|
||||
$domain_password = Get-AnsibleParam -obj $params -name "domain_password" -type "str" -failifempty ($null -ne $domain_username)
|
||||
$description = Get-AnsibleParam -obj $params -name "description" -type "str"
|
||||
$category = Get-AnsibleParam -obj $params -name "category" -type "str" -validateset "distribution","security"
|
||||
$scope = Get-AnsibleParam -obj $params -name "scope" -type "str" -validateset "domainlocal","global","universal"
|
||||
|
@ -40,12 +40,12 @@ if (-not (Get-Module -Name ActiveDirectory -ListAvailable)) {
|
|||
Import-Module ActiveDirectory
|
||||
|
||||
$extra_args = @{}
|
||||
if ($domain_username -ne $null) {
|
||||
if ($null -ne $domain_username) {
|
||||
$domain_password = ConvertTo-SecureString $domain_password -AsPlainText -Force
|
||||
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $domain_username, $domain_password
|
||||
$extra_args.Credential = $credential
|
||||
}
|
||||
if ($domain_server -ne $null) {
|
||||
if ($null -ne $domain_server) {
|
||||
$extra_args.Server = $domain_server
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ try {
|
|||
Fail-Json $result "failed to retrieve initial details for group $($name): $($_.Exception.Message)"
|
||||
}
|
||||
if ($state -eq "absent") {
|
||||
if ($group -ne $null) {
|
||||
if ($null -ne $group) {
|
||||
if ($group.ProtectedFromAccidentalDeletion -eq $true -and $ignore_protection -eq $true) {
|
||||
$group = $group | Set-ADObject -ProtectedFromAccidentalDeletion $false -WhatIf:$check_mode -PassThru @extra_args
|
||||
} elseif ($group.ProtectedFromAccidentalDeletion -eq $true -and $ignore_protection -eq $false) {
|
||||
|
@ -69,7 +69,7 @@ if ($state -eq "absent") {
|
|||
} catch {
|
||||
Fail-Json $result "failed to remove group $($name): $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
if ($diff_mode) {
|
||||
$result.diff.prepared = "-[$name]"
|
||||
|
@ -77,7 +77,7 @@ if ($state -eq "absent") {
|
|||
}
|
||||
} else {
|
||||
# validate that path is an actual path
|
||||
if ($organizational_unit -ne $null) {
|
||||
if ($null -ne $organizational_unit) {
|
||||
try {
|
||||
Get-ADObject -Identity $organizational_unit @extra_args | Out-Null
|
||||
} catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
|
||||
|
@ -86,12 +86,12 @@ if ($state -eq "absent") {
|
|||
}
|
||||
|
||||
$diff_text = $null
|
||||
if ($group -ne $null) {
|
||||
if ($null -ne $group) {
|
||||
# will be overriden later if no change actually occurs
|
||||
$diff_text += "[$name]`n"
|
||||
|
||||
# change the path of the group
|
||||
if ($organizational_unit -ne $null) {
|
||||
if ($null -ne $organizational_unit) {
|
||||
$group_cn = $group.CN
|
||||
$existing_path = $group.DistinguishedName -replace "^CN=$group_cn,",''
|
||||
if ($existing_path -ne $organizational_unit) {
|
||||
|
@ -112,7 +112,7 @@ if ($state -eq "absent") {
|
|||
$group | Set-ADObject -ProtectedFromAccidentalDeletion $true -WhatIf:$check_mode -PassThru @extra_args | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
$diff_text += "-DistinguishedName = CN=$group_cn,$existing_path`n+DistinguishedName = CN=$group_cn,$organizational_unit`n"
|
||||
|
||||
|
@ -129,7 +129,7 @@ if ($state -eq "absent") {
|
|||
$run_change = $false
|
||||
$set_args = $extra_args.Clone()
|
||||
|
||||
if ($scope -ne $null) {
|
||||
if ($null -ne $scope) {
|
||||
if ($group.GroupScope -ne $scope) {
|
||||
# you cannot from from Global to DomainLocal and vice-versa, we
|
||||
# need to change it to Universal and then finally to the target
|
||||
|
@ -148,26 +148,26 @@ if ($state -eq "absent") {
|
|||
}
|
||||
}
|
||||
|
||||
if ($description -ne $null -and $group.Description -cne $description) {
|
||||
if ($null -ne $description -and $group.Description -cne $description) {
|
||||
$set_args.Description = $description
|
||||
$run_change = $true
|
||||
$diff_text += "-Description = $($group.Description)`n+Description = $description`n"
|
||||
}
|
||||
|
||||
if ($display_name -ne $null -and $group.DisplayName -cne $display_name) {
|
||||
if ($null -ne $display_name -and $group.DisplayName -cne $display_name) {
|
||||
$set_args.DisplayName = $display_name
|
||||
$run_change = $true
|
||||
$diff_text += "-DisplayName = $($group.DisplayName)`n+DisplayName = $display_name`n"
|
||||
}
|
||||
|
||||
if ($category -ne $null -and $group.GroupCategory -ne $category) {
|
||||
if ($null -ne $category -and $group.GroupCategory -ne $category) {
|
||||
$set_args.GroupCategory = $category
|
||||
$run_change = $true
|
||||
$diff_text += "-GroupCategory = $($group.GroupCategory)`n+GroupCategory = $category`n"
|
||||
}
|
||||
|
||||
if ($managed_by -ne $null) {
|
||||
if ($group.ManagedBy -eq $null) {
|
||||
if ($null -ne $managed_by) {
|
||||
if ($null -eq $group.ManagedBy) {
|
||||
$set_args.ManagedBy = $managed_by
|
||||
$run_change = $true
|
||||
$diff_text += "+ManagedBy = $managed_by`n"
|
||||
|
@ -190,7 +190,7 @@ if ($state -eq "absent") {
|
|||
}
|
||||
}
|
||||
|
||||
if ($attributes -ne $null) {
|
||||
if ($null -ne $attributes) {
|
||||
$add_attributes = @{}
|
||||
$replace_attributes = @{}
|
||||
foreach ($attribute in $attributes.GetEnumerator()) {
|
||||
|
@ -227,7 +227,7 @@ if ($state -eq "absent") {
|
|||
}
|
||||
$result.changed = $true
|
||||
|
||||
if ($extra_scope_change -ne $null) {
|
||||
if ($null -ne $extra_scope_change) {
|
||||
try {
|
||||
$group = $group | Set-ADGroup -GroupScope $extra_scope_change -WhatIf:$check_mode -PassThru @extra_args
|
||||
} catch {
|
||||
|
@ -242,7 +242,7 @@ if ($state -eq "absent") {
|
|||
}
|
||||
} else {
|
||||
# validate if scope is set
|
||||
if ($scope -eq $null) {
|
||||
if ($null -eq $scope) {
|
||||
Fail-Json $result "scope must be set when state=present and the group doesn't exist"
|
||||
}
|
||||
|
||||
|
@ -251,34 +251,34 @@ if ($state -eq "absent") {
|
|||
$add_args.Name = $name
|
||||
$add_args.GroupScope = $scope
|
||||
|
||||
if ($description -ne $null) {
|
||||
if ($null -ne $description) {
|
||||
$add_args.Description = $description
|
||||
$diff_text += "+Description = $description`n"
|
||||
}
|
||||
|
||||
if ($display_name -ne $null) {
|
||||
if ($null -ne $display_name) {
|
||||
$add_args.DisplayName = $display_name
|
||||
$diff_text += "+DisplayName = $display_name`n"
|
||||
}
|
||||
|
||||
if ($category -ne $null) {
|
||||
if ($null -ne $category) {
|
||||
$add_args.GroupCategory = $category
|
||||
$diff_text += "+GroupCategory = $category`n"
|
||||
}
|
||||
|
||||
if ($managed_by -ne $null) {
|
||||
if ($null -ne $managed_by) {
|
||||
$add_args.ManagedBy = $managed_by
|
||||
$diff_text += "+ManagedBy = $managed_by`n"
|
||||
}
|
||||
|
||||
if ($attributes -ne $null) {
|
||||
if ($null -ne $attributes) {
|
||||
$add_args.OtherAttributes = $attributes
|
||||
foreach ($attribute in $attributes.GetEnumerator()) {
|
||||
$diff_text += "+$($attribute.Name) = $($attribute.Value)`n"
|
||||
}
|
||||
}
|
||||
|
||||
if ($organizational_unit -ne $null) {
|
||||
if ($null -ne $organizational_unit) {
|
||||
$add_args.Path = $organizational_unit
|
||||
$diff_text += "+Path = $organizational_unit`n"
|
||||
}
|
||||
|
@ -292,12 +292,12 @@ if ($state -eq "absent") {
|
|||
}
|
||||
|
||||
# set the protection value
|
||||
if ($protect -ne $null) {
|
||||
if ($null -ne $protect) {
|
||||
if (-not $check_mode) {
|
||||
$group = Get-ADGroup -Identity $name -Properties * @extra_args
|
||||
}
|
||||
$existing_protection_value = $group.ProtectedFromAccidentalDeletion
|
||||
if ($existing_protection_value -eq $null) {
|
||||
if ($null -eq $existing_protection_value) {
|
||||
$existing_protection_value = $false
|
||||
}
|
||||
if ($existing_protection_value -ne $protect) {
|
||||
|
@ -311,7 +311,7 @@ if ($state -eq "absent") {
|
|||
}
|
||||
}
|
||||
|
||||
if ($diff_mode -and $diff_text -ne $null) {
|
||||
if ($diff_mode -and $null -ne $diff_text) {
|
||||
$result.diff.prepared = $diff_text
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ if ($state -eq "absent") {
|
|||
$result.group_scope = ($group.GroupScope).ToString()
|
||||
$result.category = ($group.GroupCategory).ToString()
|
||||
|
||||
if ($attributes -ne $null) {
|
||||
if ($null -ne $attributes) {
|
||||
$result.attributes = @{}
|
||||
foreach ($attribute in $attributes.GetEnumerator()) {
|
||||
$attribute_name = $attribute.Name
|
||||
|
|
|
@ -247,7 +247,7 @@ Try {
|
|||
Write-DebugLog "adding hostname change to domain-join args"
|
||||
$join_args.new_hostname = $hostname
|
||||
}
|
||||
If($domain_ou_path -ne $null){ # If OU Path is not empty
|
||||
If($null -ne $domain_ou_path){ # If OU Path is not empty
|
||||
Write-DebugLog "adding domain_ou_path to domain-join args"
|
||||
$join_args.domain_ou_path = $domain_ou_path
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ $state = Get-AnsibleParam -obj $params -name "state" -type "str" -default "prese
|
|||
$update_password = Get-AnsibleParam -obj $params -name "update_password" -type "str" -default "always" -validateset "always","on_create"
|
||||
$groups_action = Get-AnsibleParam -obj $params -name "groups_action" -type "str" -default "replace" -validateset "add","remove","replace"
|
||||
$domain_username = Get-AnsibleParam -obj $params -name "domain_username" -type "str"
|
||||
$domain_password = Get-AnsibleParam -obj $params -name "domain_password" -type "str" -failifempty ($domain_username -ne $null)
|
||||
$domain_password = Get-AnsibleParam -obj $params -name "domain_password" -type "str" -failifempty ($null -ne $domain_username)
|
||||
$domain_server = Get-AnsibleParam -obj $params -name "domain_server" -type "str"
|
||||
|
||||
# User account parameters
|
||||
|
@ -59,20 +59,20 @@ $user_info = @{
|
|||
$attributes = Get-AnsibleParam -obj $params -name "attributes"
|
||||
|
||||
# Parameter validation
|
||||
If ($account_locked -ne $null -and $account_locked) {
|
||||
If ($null -ne $account_locked -and $account_locked) {
|
||||
Fail-Json $result "account_locked must be set to 'no' if provided"
|
||||
}
|
||||
If (($password_expired -ne $null) -and ($password_never_expires -ne $null)) {
|
||||
If (($null -ne $password_expired) -and ($null -ne $password_never_expires)) {
|
||||
Fail-Json $result "password_expired and password_never_expires are mutually exclusive but have both been set"
|
||||
}
|
||||
|
||||
$extra_args = @{}
|
||||
if ($domain_username -ne $null) {
|
||||
if ($null -ne $domain_username) {
|
||||
$domain_password = ConvertTo-SecureString $domain_password -AsPlainText -Force
|
||||
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $domain_username, $domain_password
|
||||
$extra_args.Credential = $credential
|
||||
}
|
||||
if ($domain_server -ne $null) {
|
||||
if ($null -ne $domain_server) {
|
||||
$extra_args.Server = $domain_server
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ If ($state -eq 'present') {
|
|||
|
||||
# If the account does not exist, create it
|
||||
If (-not $user_obj) {
|
||||
If ($path -ne $null){
|
||||
If ($null -ne $path){
|
||||
New-ADUser -Name $username -Path $path -WhatIf:$check_mode @extra_args
|
||||
}
|
||||
Else {
|
||||
|
@ -114,29 +114,29 @@ If ($state -eq 'present') {
|
|||
}
|
||||
|
||||
# Configure password policies
|
||||
If (($password_never_expires -ne $null) -and ($password_never_expires -ne $user_obj.PasswordNeverExpires)) {
|
||||
If (($null -ne $password_never_expires) -and ($password_never_expires -ne $user_obj.PasswordNeverExpires)) {
|
||||
Set-ADUser -Identity $username -PasswordNeverExpires $password_never_expires -WhatIf:$check_mode @extra_args
|
||||
$user_obj = Get-ADUser -Identity $username -Properties * @extra_args
|
||||
$result.changed = $true
|
||||
}
|
||||
If (($password_expired -ne $null) -and ($password_expired -ne $user_obj.PasswordExpired)) {
|
||||
If (($null -ne $password_expired) -and ($password_expired -ne $user_obj.PasswordExpired)) {
|
||||
Set-ADUser -Identity $username -ChangePasswordAtLogon $password_expired -WhatIf:$check_mode @extra_args
|
||||
$user_obj = Get-ADUser -Identity $username -Properties * @extra_args
|
||||
$result.changed = $true
|
||||
}
|
||||
If (($user_cannot_change_password -ne $null) -and ($user_cannot_change_password -ne $user_obj.CannotChangePassword)) {
|
||||
If (($null -ne $user_cannot_change_password) -and ($user_cannot_change_password -ne $user_obj.CannotChangePassword)) {
|
||||
Set-ADUser -Identity $username -CannotChangePassword $user_cannot_change_password -WhatIf:$check_mode @extra_args
|
||||
$user_obj = Get-ADUser -Identity $username -Properties * @extra_args
|
||||
$result.changed = $true
|
||||
}
|
||||
|
||||
# Assign other account settings
|
||||
If (($upn -ne $null) -and ($upn -ne $user_obj.UserPrincipalName)) {
|
||||
If (($null -ne $upn) -and ($upn -ne $user_obj.UserPrincipalName)) {
|
||||
Set-ADUser -Identity $username -UserPrincipalName $upn -WhatIf:$check_mode @extra_args
|
||||
$user_obj = Get-ADUser -Identity $username -Properties * @extra_args
|
||||
$result.changed = $true
|
||||
}
|
||||
If (($description -ne $null) -and ($description -ne $user_obj.Description)) {
|
||||
If (($null -ne $description) -and ($description -ne $user_obj.Description)) {
|
||||
Set-ADUser -Identity $username -description $description -WhatIf:$check_mode @extra_args
|
||||
$user_obj = Get-ADUser -Identity $username -Properties * @extra_args
|
||||
$result.changed = $true
|
||||
|
@ -154,7 +154,7 @@ If ($state -eq 'present') {
|
|||
|
||||
# Set user information
|
||||
Foreach ($key in $user_info.Keys) {
|
||||
If ($user_info[$key] -eq $null) {
|
||||
If ($null -eq $user_info[$key]) {
|
||||
continue
|
||||
}
|
||||
$value = $user_info[$key]
|
||||
|
@ -170,7 +170,7 @@ If ($state -eq 'present') {
|
|||
# Set additional attributes
|
||||
$set_args = $extra_args.Clone()
|
||||
$run_change = $false
|
||||
if ($attributes -ne $null) {
|
||||
if ($null -ne $attributes) {
|
||||
$add_attributes = @{}
|
||||
$replace_attributes = @{}
|
||||
foreach ($attribute in $attributes.GetEnumerator()) {
|
||||
|
@ -208,7 +208,7 @@ If ($state -eq 'present') {
|
|||
|
||||
|
||||
# Configure group assignment
|
||||
If ($groups -ne $null) {
|
||||
If ($null -ne $groups) {
|
||||
$group_list = $groups
|
||||
|
||||
$groups = @()
|
||||
|
|
|
@ -50,7 +50,7 @@ if ($state -eq "present" -and $before_value -ne $value) {
|
|||
}
|
||||
$module.Result.changed = $true
|
||||
|
||||
} elseif ($state -eq "absent" -and $before_value -ne $null) {
|
||||
} elseif ($state -eq "absent" -and $null -ne $before_value) {
|
||||
if (-not $module.CheckMode) {
|
||||
[Environment]::SetEnvironmentVariable($name, $null, $level)
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ if (Test-Path -LiteralPath $path) {
|
|||
|
||||
# If state is not supplied, test the $path to see if it looks like
|
||||
# a file or a folder and set state to file or folder
|
||||
if ($state -eq $null) {
|
||||
if ($null -eq $state) {
|
||||
$basename = Split-Path -Path $path -Leaf
|
||||
if ($basename.length -gt 0) {
|
||||
$state = "file"
|
||||
|
|
|
@ -25,27 +25,27 @@ If ( $ext -notin '.exe', '.dll'){
|
|||
Try {
|
||||
$_version_fields = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($path)
|
||||
$file_version = $_version_fields.FileVersion
|
||||
If ($file_version -eq $null){
|
||||
If ($null -eq $file_version){
|
||||
$file_version = ''
|
||||
}
|
||||
$product_version = $_version_fields.ProductVersion
|
||||
If ($product_version -eq $null){
|
||||
If ($null -eq $product_version){
|
||||
$product_version= ''
|
||||
}
|
||||
$file_major_part = $_version_fields.FileMajorPart
|
||||
If ($file_major_part -eq $null){
|
||||
If ($null -eq $file_major_part){
|
||||
$file_major_part= ''
|
||||
}
|
||||
$file_minor_part = $_version_fields.FileMinorPart
|
||||
If ($file_minor_part -eq $null){
|
||||
If ($null -eq $file_minor_part){
|
||||
$file_minor_part= ''
|
||||
}
|
||||
$file_build_part = $_version_fields.FileBuildPart
|
||||
If ($file_build_part -eq $null){
|
||||
If ($null -eq $file_build_part){
|
||||
$file_build_part = ''
|
||||
}
|
||||
$file_private_part = $_version_fields.FilePrivatePart
|
||||
If ($file_private_part -eq $null){
|
||||
If ($null -eq $file_private_part){
|
||||
$file_private_part = ''
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ Function Get-HotfixMetadataFromName($name) {
|
|||
Function Get-HotfixMetadataFromFile($extract_path) {
|
||||
# MSU contents https://support.microsoft.com/en-us/help/934307/description-of-the-windows-update-standalone-installer-in-windows
|
||||
$metadata_path = Get-ChildItem -Path $extract_path | Where-Object { $_.Extension -eq ".xml" }
|
||||
if ($metadata_path -eq $null) {
|
||||
if ($null -eq $metadata_path) {
|
||||
Fail-Json $result "failed to get metadata xml inside MSU file, cannot get hotfix metadata required for this task"
|
||||
}
|
||||
[xml]$xml = Get-Content -Path $metadata_path.FullName
|
||||
|
@ -102,12 +102,12 @@ Function Get-HotfixMetadataFromFile($extract_path) {
|
|||
}
|
||||
|
||||
$package_properties_path = Get-ChildItem -Path $extract_path | Where-Object { $_.Extension -eq ".txt" }
|
||||
if ($package_properties_path -eq $null) {
|
||||
if ($null -eq $package_properties_path) {
|
||||
$hotfix_kb = "UNKNOWN"
|
||||
} else {
|
||||
$package_ini = Get-Content -Path $package_properties_path.FullName
|
||||
$entry = $package_ini | Where-Object { $_.StartsWith("KB Article Number") }
|
||||
if ($entry -eq $null) {
|
||||
if ($null -eq $entry) {
|
||||
$hotfix_kb = "UNKNOWN"
|
||||
} else {
|
||||
$hotfix_kb = ($entry -split '=')[-1]
|
||||
|
@ -130,7 +130,7 @@ Function Get-HotfixMetadataFromKB($kb) {
|
|||
$packages = Get-WindowsPackage -Online
|
||||
$identifier = $packages | Where-Object { $_.PackageName -like "*$kb*" }
|
||||
|
||||
if ($identifier -eq $null) {
|
||||
if ($null -eq $identifier) {
|
||||
# still haven't found the KB, need to loop through the results and check the description
|
||||
foreach ($package in $packages) {
|
||||
$raw_metadata = Get-HotfixMetadataFromName -name $package.PackageName
|
||||
|
@ -141,7 +141,7 @@ Function Get-HotfixMetadataFromKB($kb) {
|
|||
}
|
||||
|
||||
# if we still haven't found the package then we need to throw an error
|
||||
if ($metadata -eq $null) {
|
||||
if ($null -eq $metadata) {
|
||||
Fail-Json $result "failed to get DISM package from KB, to continue specify hotfix_identifier instead"
|
||||
}
|
||||
} else {
|
||||
|
@ -155,11 +155,11 @@ if ($state -eq "absent") {
|
|||
# uninstall hotfix
|
||||
# this is a pretty poor way of doing this, is there a better way?
|
||||
|
||||
if ($hotfix_identifier -ne $null) {
|
||||
if ($null -ne $hotfix_identifier) {
|
||||
$hotfix_metadata = Get-HotfixMetadataFromName -name $hotfix_identifier
|
||||
} elseif ($hotfix_kb -ne $null) {
|
||||
} elseif ($null -ne $hotfix_kb) {
|
||||
$hotfix_install_info = Get-Hotfix -Id $hotfix_kb -ErrorAction SilentlyContinue
|
||||
if ($hotfix_install_info -ne $null) {
|
||||
if ($null -ne $hotfix_install_info) {
|
||||
$hotfix_metadata = Get-HotfixMetadataFromKB -kb $hotfix_kb
|
||||
} else {
|
||||
$hotfix_metadata = @{state = "NotPresent"}
|
||||
|
@ -185,11 +185,11 @@ if ($state -eq "absent") {
|
|||
}
|
||||
$result.reboot_required = $remove_Result.RestartNeeded
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($source -eq $null) {
|
||||
if ($null -eq $source) {
|
||||
Fail-Json $result "source must be set when state=present"
|
||||
}
|
||||
if (-not (Test-Path -Path $source -PathType Leaf)) {
|
||||
|
@ -202,12 +202,12 @@ if ($state -eq "absent") {
|
|||
$hotfix_metadata = Get-HotfixMetadataFromFile -extract_path $extract_path
|
||||
|
||||
# validate the hotfix matches if the hotfix id has been passed in
|
||||
if ($hotfix_identifier -ne $null) {
|
||||
if ($null -ne $hotfix_identifier) {
|
||||
if ($hotfix_metadata.name -ne $hotfix_identifier) {
|
||||
Fail-Json $result "the hotfix identifier $hotfix_identifier does not match with the source msu identifier $($hotfix_metadata.name), please omit or specify the correct identifier to continue"
|
||||
}
|
||||
}
|
||||
if ($hotfix_kb -ne $null) {
|
||||
if ($null -ne $hotfix_kb) {
|
||||
if ($hotfix_metadata.kb -ne $hotfix_kb) {
|
||||
Fail-Json $result "the hotfix KB $hotfix_kb does not match with the source msu KB $($hotfix_metadata.kb), please omit or specify the correct KB to continue"
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ $physical_path = Get-AnsibleParam -obj $params -name "physical_path" -type "str"
|
|||
$state = Get-AnsibleParam -obj $params -name "state" -type "str" -default "present" -validateset "absent","present"
|
||||
|
||||
# Ensure WebAdministration module is loaded
|
||||
if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $null) {
|
||||
if ($null -eq (Get-Module "WebAdministration" -ErrorAction SilentlyContinue)) {
|
||||
Import-Module WebAdministration
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ $result = @{
|
|||
}
|
||||
|
||||
# Ensure WebAdministration module is loaded
|
||||
if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $null) {
|
||||
if ($null -eq (Get-Module "WebAdministration" -ErrorAction SilentlyContinue)) {
|
||||
Import-Module WebAdministration
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ Function Convert-CollectionToList($collection) {
|
|||
}
|
||||
|
||||
Function Compare-Values($current, $new) {
|
||||
if ($current -eq $null) {
|
||||
if ($null -eq $current) {
|
||||
return $true
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ Function Convert-ToPropertyValue($pool, $attribute_key, $attribute_value) {
|
|||
foreach ($key in $attribute_key_split) {
|
||||
$attribute_meta = $parent.Attributes | Where-Object { $_.Name -eq $key }
|
||||
$parent = $parent.$key
|
||||
if ($attribute_meta -eq $null) {
|
||||
if ($null -eq $attribute_meta) {
|
||||
$attribute_meta = $parent
|
||||
}
|
||||
}
|
||||
|
@ -152,11 +152,11 @@ Function Convert-ToPropertyValue($pool, $attribute_key, $attribute_value) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# Try and cast the variable using the chosen type, revert to the default if it fails
|
||||
Set-Variable -Name casted_value -Value ($value -as ([type] $attribute_meta.TypeName))
|
||||
if ($casted_value -eq $null) {
|
||||
if ($null -eq $casted_value) {
|
||||
$value
|
||||
} else {
|
||||
$casted_value
|
||||
|
@ -167,7 +167,7 @@ Function Convert-ToPropertyValue($pool, $attribute_key, $attribute_value) {
|
|||
}
|
||||
|
||||
# Ensure WebAdministration module is loaded
|
||||
if ((Get-Module -Name "WebAdministration" -ErrorAction SilentlyContinue) -eq $null) {
|
||||
if ($null -eq (Get-Module -Name "WebAdministration" -ErrorAction SilentlyContinue)) {
|
||||
Import-Module WebAdministration
|
||||
$web_admin_dll_path = Join-Path $env:SystemRoot system32\inetsrv\Microsoft.Web.Administration.dll
|
||||
Add-Type -Path $web_admin_dll_path
|
||||
|
|
|
@ -24,7 +24,7 @@ $bind_ssl = Get-AnsibleParam -obj $params -name "ssl" -type "str"
|
|||
# are separated by a pipe and property name/values by colon.
|
||||
# Ex. "foo:1|bar:2"
|
||||
$parameters = Get-AnsibleParam -obj $params -name "parameters" -type "str"
|
||||
if($parameters -ne $null) {
|
||||
if($null -ne $parameters) {
|
||||
$parameters = @($parameters -split '\|' | ForEach {
|
||||
return ,($_ -split "\:", 2);
|
||||
})
|
||||
|
@ -32,7 +32,7 @@ if($parameters -ne $null) {
|
|||
|
||||
|
||||
# Ensure WebAdministration module is loaded
|
||||
if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $null) {
|
||||
if ($null -eq (Get-Module "WebAdministration" -ErrorAction SilentlyContinue)) {
|
||||
Import-Module WebAdministration
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ Try {
|
|||
# This is a bug in the New-WebSite commandlet. Apparently there must be at least one site configured in IIS otherwise New-WebSite crashes.
|
||||
# For more details, see http://stackoverflow.com/questions/3573889/ps-c-new-website-blah-throws-index-was-outside-the-bounds-of-the-array
|
||||
$sites_list = get-childitem -Path IIS:\sites
|
||||
if ($sites_list -eq $null) { $site_parameters.ID = 1 }
|
||||
if ($null -eq $sites_list) { $site_parameters.ID = 1 }
|
||||
|
||||
$site = New-Website @site_parameters -Force
|
||||
$result.changed = $true
|
||||
|
|
|
@ -87,7 +87,7 @@ function Present($path, $regexp, $line, $insertafter, $insertbefore, $create, $b
|
|||
|
||||
# Read the dest file lines using the indicated encoding into a mutable ArrayList.
|
||||
$before = [System.IO.File]::ReadAllLines($cleanpath, $encodingobj)
|
||||
If ($before -eq $null) {
|
||||
If ($null -eq $before) {
|
||||
$lines = New-Object System.Collections.ArrayList;
|
||||
}
|
||||
Else {
|
||||
|
@ -224,7 +224,7 @@ function Absent($path, $regexp, $line, $backup, $validate, $encodingobj, $linese
|
|||
# interchangeable in windows pathnames, but .NET framework internals do not support that.
|
||||
$cleanpath = $path.Replace("/", "\");
|
||||
$before = [System.IO.File]::ReadAllLines($cleanpath, $encodingobj);
|
||||
If ($before -eq $null) {
|
||||
If ($null -eq $before) {
|
||||
$lines = New-Object System.Collections.ArrayList;
|
||||
}
|
||||
Else {
|
||||
|
|
|
@ -553,7 +553,7 @@ try {
|
|||
}
|
||||
|
||||
if ($state -eq "absent") {
|
||||
if ($existing_target -ne $null) {
|
||||
if ($null -ne $existing_target) {
|
||||
if ($null -ne $path -and $existing_target.Path -ne $path) {
|
||||
$module.FailJson("did not delete mapped drive $letter, the target path is pointing to a different location at $( $existing_target.Path )")
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ $chdir = Get-AnsibleParam -obj $params -name "chdir" -type "path"
|
|||
$product_id = Get-AnsibleParam -obj $params -name "product_id" -type "str" -aliases "productid"
|
||||
$state = Get-AnsibleParam -obj $params -name "state" -type "str" -default "present" -validateset "absent","present" -aliases "ensure"
|
||||
$username = Get-AnsibleParam -obj $params -name "username" -type "str" -aliases "user_name"
|
||||
$password = Get-AnsibleParam -obj $params -name "password" -type "str" -failifempty ($username -ne $null) -aliases "user_password"
|
||||
$password = Get-AnsibleParam -obj $params -name "password" -type "str" -failifempty ($null -ne $username) -aliases "user_password"
|
||||
$validate_certs = Get-AnsibleParam -obj $params -name "validate_certs" -type "bool" -default $true
|
||||
$creates_path = Get-AnsibleParam -obj $params -name "creates_path" -type "path"
|
||||
$creates_version = Get-AnsibleParam -obj $params -name "creates_version" -type "str"
|
||||
|
@ -32,7 +32,7 @@ $result = @{
|
|||
reboot_required = $false
|
||||
}
|
||||
|
||||
if ($arguments -ne $null) {
|
||||
if ($null -ne $arguments) {
|
||||
# convert a list to a string and escape the values
|
||||
if ($arguments -is [array]) {
|
||||
$arguments = Argv-ToString -arguments $arguments
|
||||
|
@ -54,7 +54,7 @@ if ([Net.SecurityProtocolType].GetMember("Tls12").Count -gt 0) {
|
|||
[Net.ServicePointManager]::SecurityProtocol = $security_protcols
|
||||
|
||||
$credential = $null
|
||||
if ($username -ne $null) {
|
||||
if ($null -ne $username) {
|
||||
$sec_user_password = ConvertTo-SecureString -String $password -AsPlainText -Force
|
||||
$credential = New-Object -TypeName PSCredential -ArgumentList $username, $sec_user_password
|
||||
}
|
||||
|
@ -69,13 +69,13 @@ foreach ($rc in ($expected_return_code)) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($path -eq $null) {
|
||||
if (-not ($state -eq "absent" -and $product_id -ne $null)) {
|
||||
if ($null -eq $path) {
|
||||
if (-not ($state -eq "absent" -and $null -ne $product_id)) {
|
||||
Fail-Json -obj $result -message "path can only be null when state=absent and product_id is not null"
|
||||
}
|
||||
}
|
||||
|
||||
if ($creates_version -ne $null -and $creates_path -eq $null) {
|
||||
if ($null -ne $creates_version -and $null -eq $creates_path) {
|
||||
Fail-Json -obj $result -Message "creates_path must be set when creates_version is set"
|
||||
}
|
||||
|
||||
|
@ -138,8 +138,8 @@ Function Test-RegistryProperty($path, $name) {
|
|||
# if the property exists and false if the property does not
|
||||
try {
|
||||
$value = (Get-Item -Path $path).GetValue($name)
|
||||
# need to do it this way return ($value -eq $null) does not work
|
||||
if ($value -eq $null) {
|
||||
# need to do it this way return ($null -eq $value) does not work
|
||||
if ($null -eq $value) {
|
||||
return $false
|
||||
} else {
|
||||
return $true
|
||||
|
@ -162,7 +162,7 @@ Function Get-ProgramMetadata($state, $path, $product_id, $credential, $creates_p
|
|||
}
|
||||
|
||||
# set the location type and validate the path
|
||||
if ($path -ne $null) {
|
||||
if ($null -ne $path) {
|
||||
if ($path.EndsWith(".msi", [System.StringComparison]::CurrentCultureIgnoreCase)) {
|
||||
$metadata.msi = $true
|
||||
} else {
|
||||
|
@ -178,7 +178,7 @@ Function Get-ProgramMetadata($state, $path, $product_id, $credential, $creates_p
|
|||
}
|
||||
} elseif ($path.StartsWith("/") -or $path.StartsWith("\\")) {
|
||||
$metadata.location_type = [LocationType]::Unc
|
||||
if ($credential -ne $null) {
|
||||
if ($null -ne $credential) {
|
||||
# Test-Path doesn't support supplying -Credentials, need to create PSDrive before testing
|
||||
$file_path = Split-Path -Path $path
|
||||
$file_name = Split-Path -Path $path -Leaf
|
||||
|
@ -210,24 +210,24 @@ Function Get-ProgramMetadata($state, $path, $product_id, $credential, $creates_p
|
|||
}
|
||||
|
||||
# try and get the product id
|
||||
if ($product_id -ne $null) {
|
||||
if ($null -ne $product_id) {
|
||||
$metadata.product_id = $product_id
|
||||
} else {
|
||||
# we can get the product_id if the path is an msi and is either a local file or unc file with credential delegation
|
||||
if (($metadata.msi -eq $true) -and (($metadata.location_type -eq [LocationType]::Local) -or ($metadata.location_type -eq [LocationType]::Unc -and $credential -eq $null))) {
|
||||
if (($metadata.msi -eq $true) -and (($metadata.location_type -eq [LocationType]::Local) -or ($metadata.location_type -eq [LocationType]::Unc -and $null -eq $credential))) {
|
||||
Add-Type -TypeDefinition $msi_tools
|
||||
try {
|
||||
$metadata.product_id = [Ansible.MsiTools]::GetPackageProperty($path, "ProductCode")
|
||||
} catch {
|
||||
Fail-Json -obj $result -message "failed to get product_id from MSI at $($path): $($_.Exception.Message)"
|
||||
}
|
||||
} elseif ($creates_path -eq $null -and $creates_service -eq $null) {
|
||||
} elseif ($null -eq $creates_path -and $null -eq $creates_service) {
|
||||
# we need to fail without the product id at this point
|
||||
Fail-Json $result "product_id is required when the path is not an MSI or the path is an MSI but not local"
|
||||
}
|
||||
}
|
||||
|
||||
if ($metadata.product_id -ne $null) {
|
||||
if ($null -ne $metadata.product_id) {
|
||||
$uninstall_key = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$($metadata.product_id)"
|
||||
$uninstall_key_wow64 = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$($metadata.product_id)"
|
||||
if (Test-Path -Path $uninstall_key) {
|
||||
|
@ -249,11 +249,11 @@ Function Get-ProgramMetadata($state, $path, $product_id, $credential, $creates_p
|
|||
}
|
||||
|
||||
# use the creates_* to determine if the program is installed
|
||||
if ($creates_path -ne $null) {
|
||||
if ($null -ne $creates_path) {
|
||||
$path_exists = Test-Path -Path $creates_path
|
||||
$metadata.installed = $path_exists
|
||||
|
||||
if ($creates_version -ne $null -and $path_exists -eq $true) {
|
||||
if ($null -ne $creates_version -and $path_exists -eq $true) {
|
||||
if (Test-Path -Path $creates_path -PathType Leaf) {
|
||||
$existing_version = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($creates_path).FileVersion
|
||||
$version_matched = $creates_version -eq $existing_version
|
||||
|
@ -263,15 +263,15 @@ Function Get-ProgramMetadata($state, $path, $product_id, $credential, $creates_p
|
|||
}
|
||||
}
|
||||
}
|
||||
if ($creates_service -ne $null) {
|
||||
if ($null -ne $creates_service) {
|
||||
$existing_service = Get-Service -Name $creates_service -ErrorAction SilentlyContinue
|
||||
$service_exists = $existing_service -ne $null
|
||||
$service_exists = $null -ne $existing_service
|
||||
$metadata.installed = $service_exists
|
||||
}
|
||||
|
||||
|
||||
# finally throw error if path is not valid unless we want to uninstall the package and it already is
|
||||
if ($metadata.path_error -ne $null -and (-not ($state -eq "absent" -and $metadata.installed -eq $false))) {
|
||||
if ($null -ne $metadata.path_error -and (-not ($state -eq "absent" -and $metadata.installed -eq $false))) {
|
||||
Fail-Json -obj $result -message $metadata.path_error
|
||||
}
|
||||
|
||||
|
@ -306,7 +306,7 @@ if ($state -eq "absent") {
|
|||
try {
|
||||
# If path is on a network and we specify credentials or path is a
|
||||
# URL and not an MSI we need to get a temp local copy
|
||||
if ($program_metadata.location_type -eq [LocationType]::Unc -and $credential -ne $null) {
|
||||
if ($program_metadata.location_type -eq [LocationType]::Unc -and $null -ne $credential) {
|
||||
$file_name = Split-Path -Path $path -Leaf
|
||||
$local_path = [System.IO.Path]::GetRandomFileName()
|
||||
Copy-Item -Path "win_package:\$file_name" -Destination $local_path -WhatIf:$check_mode
|
||||
|
@ -334,7 +334,7 @@ if ($state -eq "absent") {
|
|||
$cleanup_artifacts += $log_path
|
||||
}
|
||||
|
||||
if ($program_metadata.product_id -ne $null) {
|
||||
if ($null -ne $program_metadata.product_id) {
|
||||
$id = $program_metadata.product_id
|
||||
} else {
|
||||
$id = $local_path
|
||||
|
@ -350,7 +350,7 @@ if ($state -eq "absent") {
|
|||
$command_args = @{
|
||||
command = Argv-ToString -arguments $uninstall_arguments
|
||||
}
|
||||
if ($arguments -ne $null) {
|
||||
if ($null -ne $arguments) {
|
||||
$command_args['command'] += " $arguments"
|
||||
}
|
||||
if ($chdir) {
|
||||
|
@ -363,7 +363,7 @@ if ($state -eq "absent") {
|
|||
Fail-Json -obj $result -message "failed to run uninstall process ($($command_args['command'])): $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
if (($log_path -ne $null) -and (Test-Path -Path $log_path)) {
|
||||
if (($null -ne $log_path) -and (Test-Path -Path $log_path)) {
|
||||
$log_content = Get-Content -Path $log_path | Out-String
|
||||
} else {
|
||||
$log_content = $null
|
||||
|
@ -373,7 +373,7 @@ if ($state -eq "absent") {
|
|||
if ($valid_return_codes -notcontains $process_result.rc) {
|
||||
$result.stdout = Convert-Encoding -string $process_result.stdout
|
||||
$result.stderr = Convert-Encoding -string $process_result.stderr
|
||||
if ($log_content -ne $null) {
|
||||
if ($null -ne $log_content) {
|
||||
$result.log = $log_content
|
||||
}
|
||||
Fail-Json -obj $result -message "unexpected rc from uninstall $uninstall_exe $($uninstall_arguments): see rc, stdout and stderr for more details"
|
||||
|
@ -403,7 +403,7 @@ if ($state -eq "absent") {
|
|||
try {
|
||||
# If path is on a network and we specify credentials or path is a
|
||||
# URL and not an MSI we need to get a temp local copy
|
||||
if ($program_metadata.location_type -eq [LocationType]::Unc -and $credential -ne $null) {
|
||||
if ($program_metadata.location_type -eq [LocationType]::Unc -and $null -ne $credential) {
|
||||
$file_name = Split-Path -Path $path -Leaf
|
||||
$local_path = [System.IO.Path]::GetRandomFileName()
|
||||
Copy-Item -Path "win_package:\$file_name" -Destination $local_path -WhatIf:$check_mode
|
||||
|
@ -438,7 +438,7 @@ if ($state -eq "absent") {
|
|||
$command_args = @{
|
||||
command = Argv-ToString -arguments $install_arguments
|
||||
}
|
||||
if ($arguments -ne $null) {
|
||||
if ($null -ne $arguments) {
|
||||
$command_args['command'] += " $arguments"
|
||||
}
|
||||
if ($chdir) {
|
||||
|
@ -451,7 +451,7 @@ if ($state -eq "absent") {
|
|||
Fail-Json -obj $result -message "failed to run install process ($($command_args['command'])): $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
if (($log_path -ne $null) -and (Test-Path -Path $log_path)) {
|
||||
if (($null -ne $log_path) -and (Test-Path -Path $log_path)) {
|
||||
$log_content = Get-Content -Path $log_path | Out-String
|
||||
} else {
|
||||
$log_content = $null
|
||||
|
@ -461,7 +461,7 @@ if ($state -eq "absent") {
|
|||
if ($valid_return_codes -notcontains $process_result.rc) {
|
||||
$result.stdout = Convert-Encoding -string $process_result.stdout
|
||||
$result.stderr = Convert-Encoding -string $process_result.stderr
|
||||
if ($log_content -ne $null) {
|
||||
if ($null -ne $log_content) {
|
||||
$result.log = $log_content
|
||||
}
|
||||
Fail-Json -obj $result -message "unexpected rc from install $install_exe $($install_arguments): see rc, stdout and stderr for more details"
|
||||
|
|
|
@ -39,13 +39,13 @@ $result = @{
|
|||
|
||||
if ($removeAll) {
|
||||
$currentPageFiles = Get-WmiObject Win32_PageFileSetting
|
||||
if ($currentPageFiles -ne $null) {
|
||||
if ($null -ne $currentPageFiles) {
|
||||
$currentPageFiles | Remove-WmiObject -WhatIf:$check_mode | Out-Null
|
||||
$result.changed = $true
|
||||
}
|
||||
}
|
||||
|
||||
if ($automatic -ne $null) {
|
||||
if ($null -ne $automatic) {
|
||||
# change autmoatic managed pagefile
|
||||
try {
|
||||
$computerSystem = Get-WmiObject -Class win32_computersystem -EnableAllPrivileges
|
||||
|
@ -67,7 +67,7 @@ if ($automatic -ne $null) {
|
|||
|
||||
if ($state -eq "absent") {
|
||||
# Remove pagefile
|
||||
if ((Get-Pagefile $fullPath) -ne $null)
|
||||
if ($null -ne (Get-Pagefile $fullPath))
|
||||
{
|
||||
try {
|
||||
Remove-Pagefile $fullPath -whatif:$check_mode
|
||||
|
@ -79,7 +79,7 @@ if ($state -eq "absent") {
|
|||
} elseif ($state -eq "present") {
|
||||
# Remove current pagefile
|
||||
if ($override) {
|
||||
if ((Get-Pagefile $fullPath) -ne $null)
|
||||
if ($null -ne (Get-Pagefile $fullPath))
|
||||
{
|
||||
try {
|
||||
Remove-Pagefile $fullPath -whatif:$check_mode
|
||||
|
@ -96,7 +96,7 @@ if ($state -eq "absent") {
|
|||
}
|
||||
|
||||
# Set pagefile
|
||||
if ((Get-Pagefile $fullPath) -eq $null) {
|
||||
if ($null -eq (Get-Pagefile $fullPath)) {
|
||||
try {
|
||||
$pagefile = Set-WmiInstance -Class Win32_PageFileSetting -Arguments @{name = $fullPath; InitialSize = 0; MaximumSize = 0} -WhatIf:$check_mode
|
||||
} catch {
|
||||
|
@ -133,7 +133,7 @@ if ($state -eq "absent") {
|
|||
} elseif ($state -eq "query") {
|
||||
$result.pagefiles = @()
|
||||
|
||||
if ($drive -eq $null) {
|
||||
if ($null -eq $drive) {
|
||||
try {
|
||||
$pagefiles = Get-WmiObject Win32_PageFileSetting
|
||||
} catch {
|
||||
|
|
|
@ -146,7 +146,7 @@ if ($null -ne $order -and $order -lt 1) {
|
|||
}
|
||||
|
||||
# Ensure RemoteDesktopServices module is loaded
|
||||
if ((Get-Module -Name RemoteDesktopServices -ErrorAction SilentlyContinue) -eq $null) {
|
||||
if ($null -eq (Get-Module -Name RemoteDesktopServices -ErrorAction SilentlyContinue)) {
|
||||
Import-Module -Name RemoteDesktopServices
|
||||
}
|
||||
|
||||
|
@ -354,4 +354,4 @@ if ($diff_mode -and $result.changed -eq $true) {
|
|||
}
|
||||
}
|
||||
|
||||
Exit-Json $result
|
||||
Exit-Json $result
|
||||
|
|
|
@ -138,7 +138,7 @@ if ($null -ne $allowed_ports) {
|
|||
}
|
||||
|
||||
# Ensure RemoteDesktopServices module is loaded
|
||||
if ((Get-Module -Name RemoteDesktopServices -ErrorAction SilentlyContinue) -eq $null) {
|
||||
if ($null -eq (Get-Module -Name RemoteDesktopServices -ErrorAction SilentlyContinue)) {
|
||||
Import-Module -Name RemoteDesktopServices
|
||||
}
|
||||
|
||||
|
@ -279,4 +279,4 @@ if ($diff_mode -and $result.changed -eq $true) {
|
|||
}
|
||||
}
|
||||
|
||||
Exit-Json $result
|
||||
Exit-Json $result
|
||||
|
|
|
@ -25,7 +25,7 @@ $result = @{
|
|||
$diff_text = $null
|
||||
|
||||
# Ensure RemoteDesktopServices module is loaded
|
||||
if ((Get-Module -Name RemoteDesktopServices -ErrorAction SilentlyContinue) -eq $null) {
|
||||
if ($null -eq (Get-Module -Name RemoteDesktopServices -ErrorAction SilentlyContinue)) {
|
||||
Import-Module -Name RemoteDesktopServices
|
||||
}
|
||||
|
||||
|
@ -97,4 +97,4 @@ if ($diff_mode -and $result.changed -eq $true) {
|
|||
}
|
||||
}
|
||||
|
||||
Exit-Json $result
|
||||
Exit-Json $result
|
||||
|
|
|
@ -61,7 +61,7 @@ Function Get-ValidGeoIds($cultures) {
|
|||
|
||||
Function Test-RegistryProperty($reg_key, $property) {
|
||||
$type = Get-ItemProperty $reg_key -Name $property -ErrorAction SilentlyContinue
|
||||
if ($type -eq $null) {
|
||||
if ($null -eq $type) {
|
||||
$false
|
||||
} else {
|
||||
$true
|
||||
|
@ -211,32 +211,32 @@ Function Set-SystemLocaleLegacy($unicode_language) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($format -eq $null -and $location -eq $null -and $unicode_language -eq $null) {
|
||||
if ($null -eq $format -and $null -eq $location -and $null -eq $unicode_language) {
|
||||
Fail-Json $result "An argument for 'format', 'location' or 'unicode_language' needs to be supplied"
|
||||
} else {
|
||||
$valid_cultures = [System.Globalization.CultureInfo]::GetCultures('InstalledWin32Cultures')
|
||||
$valid_geoids = Get-ValidGeoIds -cultures $valid_cultures
|
||||
|
||||
if ($location -ne $null) {
|
||||
if ($null -ne $location) {
|
||||
if ($valid_geoids -notcontains $location) {
|
||||
Fail-Json $result "The argument location '$location' does not contain a valid Geo ID"
|
||||
}
|
||||
}
|
||||
|
||||
if ($format -ne $null) {
|
||||
if ($null -ne $format) {
|
||||
if ($valid_cultures.Name -notcontains $format) {
|
||||
Fail-Json $result "The argument format '$format' does not contain a valid Culture Name"
|
||||
}
|
||||
}
|
||||
|
||||
if ($unicode_language -ne $null) {
|
||||
if ($null -ne $unicode_language) {
|
||||
if ($valid_cultures.Name -notcontains $unicode_language) {
|
||||
Fail-Json $result "The argument unicode_language '$unicode_language' does not contain a valid Culture Name"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($location -ne $null) {
|
||||
if ($null -ne $location) {
|
||||
# Get-WinHomeLocation was only added in Server 2012 and above
|
||||
# Use legacy option if older
|
||||
if (Get-Command 'Get-WinHomeLocation' -ErrorAction SilentlyContinue) {
|
||||
|
@ -256,7 +256,7 @@ if ($location -ne $null) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($format -ne $null) {
|
||||
if ($null -ne $format) {
|
||||
$current_format = (Get-Culture).Name
|
||||
if ($current_format -ne $format) {
|
||||
# Set-Culture was only added in Server 2012 and above, use legacy option if older
|
||||
|
@ -271,7 +271,7 @@ if ($format -ne $null) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($unicode_language -ne $null) {
|
||||
if ($null -ne $unicode_language) {
|
||||
# Get/Set-WinSystemLocale was only added in Server 2012 and above, use legacy option if older
|
||||
if (Get-Command 'Get-WinSystemLocale' -ErrorAction SilentlyContinue) {
|
||||
$current_unicode_language = (Get-WinSystemLocale).Name
|
||||
|
|
|
@ -58,7 +58,7 @@ if ($check_mode) {
|
|||
$robocopy_opts += "/l"
|
||||
}
|
||||
|
||||
if ($flags -eq $null) {
|
||||
if ($null -eq $flags) {
|
||||
if ($purge) {
|
||||
$robocopy_opts += "/purge"
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ Function Compare-Properties($property_name, $parent_property, $map, $enum_map=$n
|
|||
foreach ($entry in $map.GetEnumerator()) {
|
||||
$new_value = $entry.Value
|
||||
|
||||
if ($new_value -ne $null) {
|
||||
if ($null -ne $new_value) {
|
||||
$property_name = $entry.Name
|
||||
$existing_value = $parent_property.$property_name
|
||||
if ($existing_value -cne $new_value) {
|
||||
|
@ -161,7 +161,7 @@ Function Compare-Properties($property_name, $parent_property, $map, $enum_map=$n
|
|||
Fail-Json -obj $result -message "failed to set $property_name property '$property_name' to '$new_value': $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
if ($enum_map -ne $null -and $enum_map.ContainsKey($property_name)) {
|
||||
if ($null -ne $enum_map -and $enum_map.ContainsKey($property_name)) {
|
||||
$enum = [type]$enum_map.$property_name
|
||||
$existing_value = [Enum]::ToObject($enum, $existing_value)
|
||||
$new_value = [Enum]::ToObject($enum, $new_value)
|
||||
|
@ -247,7 +247,7 @@ Function Compare-PropertyList {
|
|||
|
||||
# now we have validated the input and have gotten the metadata, let's
|
||||
# get the diff string
|
||||
if ($existing_property -eq $null) {
|
||||
if ($null -eq $existing_property) {
|
||||
# we have more properties than before,just add to the new
|
||||
# properties list
|
||||
$diff_list = [System.Collections.ArrayList]@()
|
||||
|
@ -308,20 +308,20 @@ Function Compare-PropertyList {
|
|||
$sub_com_name = Convert-SnakeToPascalCase -snake $kv.Key
|
||||
$sub_existing_value = $existing_property.$com_name.$sub_com_name
|
||||
|
||||
if ($sub_property_value -ne $null) {
|
||||
if ($null -ne $sub_property_value) {
|
||||
[void]$diff_list.Add("+$com_name.$sub_com_name=$sub_property_value")
|
||||
}
|
||||
|
||||
if ($sub_existing_value -ne $null) {
|
||||
if ($null -ne $sub_existing_value) {
|
||||
[void]$diff_list.Add("-$com_name.$sub_com_name=$sub_existing_value")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($property_value -ne $null) {
|
||||
if ($null -ne $property_value) {
|
||||
[void]$diff_list.Add("+$com_name=$property_value")
|
||||
}
|
||||
|
||||
if ($existing_value -ne $null) {
|
||||
if ($null -ne $existing_value) {
|
||||
[void]$diff_list.Add("-$com_name=$existing_value")
|
||||
}
|
||||
}
|
||||
|
@ -337,12 +337,12 @@ Function Compare-PropertyList {
|
|||
$com_name = Convert-SnakeToPascalCase -snake $property_arg
|
||||
$property_value = $new_property.$property_arg
|
||||
$existing_value = $existing_property.$com_name
|
||||
|
||||
|
||||
if ($property_value -is [Hashtable]) {
|
||||
foreach ($kv in $property_value.GetEnumerator()) {
|
||||
$sub_property_value = $kv.Value
|
||||
|
||||
if ($sub_property_value -ne $null) {
|
||||
|
||||
if ($null -ne $sub_property_value) {
|
||||
$sub_com_name = Convert-SnakeToPascalCase -snake $kv.Key
|
||||
$sub_existing_value = $existing_property.$com_name.$sub_com_name
|
||||
|
||||
|
@ -352,7 +352,7 @@ Function Compare-PropertyList {
|
|||
}
|
||||
}
|
||||
}
|
||||
} elseif ($property_value -ne $null -and $property_value -cne $existing_value) {
|
||||
} elseif ($null -ne $property_value -and $property_value -cne $existing_value) {
|
||||
[void]$diff_list.Add("-$com_name=$existing_value")
|
||||
[void]$diff_list.Add("+$com_name=$property_value")
|
||||
}
|
||||
|
@ -370,14 +370,14 @@ Function Compare-PropertyList {
|
|||
if ($new_value -is [Hashtable]) {
|
||||
$com_name = Convert-SnakeToPascalCase -snake $property_arg
|
||||
$new_object_property = $new_object.$com_name
|
||||
|
||||
|
||||
foreach ($kv in $new_value.GetEnumerator()) {
|
||||
$value = $kv.Value
|
||||
if ($value -ne $null) {
|
||||
if ($null -ne $value) {
|
||||
Set-PropertyForComObject -com_object $new_object_property -name $property_name -arg $kv.Key -value $value
|
||||
}
|
||||
}
|
||||
} elseif ($new_value -ne $null) {
|
||||
} elseif ($null -ne $new_value) {
|
||||
Set-PropertyForComObject -com_object $new_object -name $property_name -arg $property_arg -value $new_value
|
||||
}
|
||||
}
|
||||
|
@ -397,7 +397,7 @@ Function Compare-PropertyList {
|
|||
foreach ($property_arg in $property_args) {
|
||||
$com_name = Convert-SnakeToPascalCase -snake $property_arg
|
||||
$existing_value = $existing_property.$com_name
|
||||
if ($existing_value -ne $null) {
|
||||
if ($null -ne $existing_value) {
|
||||
[void]$diff_list.Add("-$com_name=$existing_value")
|
||||
}
|
||||
}
|
||||
|
@ -417,7 +417,7 @@ Function Compare-Actions($task_definition) {
|
|||
# actions for use in a diff string
|
||||
# ActionCollection - https://msdn.microsoft.com/en-us/library/windows/desktop/aa446804(v=vs.85).aspx
|
||||
# Action - https://msdn.microsoft.com/en-us/library/windows/desktop/aa446803(v=vs.85).aspx
|
||||
if ($actions -eq $null) {
|
||||
if ($null -eq $actions) {
|
||||
return ,[System.Collections.ArrayList]@()
|
||||
}
|
||||
|
||||
|
@ -468,22 +468,22 @@ Function Compare-Principal($task_definition, $task_definition_xml) {
|
|||
# the actual sid/username. Depending on OS version this could be the SID
|
||||
# or it could be the username, we need to handle that accordingly
|
||||
$principal_username_sid = $task_definition_xml.Task.Principals.Principal.UserId
|
||||
if ($principal_username_sid -ne $null -and $principal_username_sid -notmatch "^S-\d-\d+(-\d+){1,14}(-\d+){0,1}$") {
|
||||
if ($null -ne $principal_username_sid -and $principal_username_sid -notmatch "^S-\d-\d+(-\d+){1,14}(-\d+){0,1}$") {
|
||||
$principal_username_sid = Convert-ToSID -account_name $principal_username_sid
|
||||
}
|
||||
$principal_group_sid = $task_definition_xml.Task.Principals.Principal.GroupId
|
||||
if ($principal_group_sid -ne $null -and $principal_group_sid -notmatch "^S-\d-\d+(-\d+){1,14}(-\d+){0,1}$") {
|
||||
if ($null -ne $principal_group_sid -and $principal_group_sid -notmatch "^S-\d-\d+(-\d+){1,14}(-\d+){0,1}$") {
|
||||
$principal_group_sid = Convert-ToSID -account_name $principal_group_sid
|
||||
}
|
||||
|
||||
if ($username_sid -ne $null) {
|
||||
|
||||
if ($null -ne $username_sid) {
|
||||
$new_user_name = Convert-FromSid -sid $username_sid
|
||||
if ($principal_group_sid -ne $null) {
|
||||
if ($null -ne $principal_group_sid) {
|
||||
$existing_account_name = Convert-FromSid -sid $principal_group_sid
|
||||
[void]$changes.Add("-GroupId=$existing_account_name`n+UserId=$new_user_name")
|
||||
$task_principal.UserId = $new_user_name
|
||||
$task_principal.GroupId = $null
|
||||
} elseif ($principal_username_sid -eq $null) {
|
||||
} elseif ($null -eq $principal_username_sid) {
|
||||
[void]$changes.Add("+UserId=$new_user_name")
|
||||
$task_principal.UserId = $new_user_name
|
||||
} elseif ($principal_username_sid -ne $username_sid) {
|
||||
|
@ -492,14 +492,14 @@ Function Compare-Principal($task_definition, $task_definition_xml) {
|
|||
$task_principal.UserId = $new_user_name
|
||||
}
|
||||
}
|
||||
if ($group_sid -ne $null) {
|
||||
if ($null -ne $group_sid) {
|
||||
$new_group_name = Convert-FromSid -sid $group_sid
|
||||
if ($principal_username_sid -ne $null) {
|
||||
if ($null -ne $principal_username_sid) {
|
||||
$existing_account_name = Convert-FromSid -sid $principal_username_sid
|
||||
[void]$changes.Add("-UserId=$existing_account_name`n+GroupId=$new_group_name")
|
||||
$task_principal.UserId = $null
|
||||
$task_principal.GroupId = $new_group_name
|
||||
} elseif ($principal_group_sid -eq $null) {
|
||||
} elseif ($null -eq $principal_group_sid) {
|
||||
[void]$changes.Add("+GroupId=$new_group_name")
|
||||
$task_principal.GroupId = $new_group_name
|
||||
} elseif ($principal_group_sid -ne $group_sid) {
|
||||
|
@ -508,7 +508,7 @@ Function Compare-Principal($task_definition, $task_definition_xml) {
|
|||
$task_principal.GroupId = $new_group_name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ,$changes
|
||||
}
|
||||
|
||||
|
@ -563,7 +563,7 @@ Function Compare-Triggers($task_definition) {
|
|||
# for use in a diff string
|
||||
# TriggerCollection - https://msdn.microsoft.com/en-us/library/windows/desktop/aa383875(v=vs.85).aspx
|
||||
# Trigger - https://msdn.microsoft.com/en-us/library/windows/desktop/aa383868(v=vs.85).aspx
|
||||
if ($triggers -eq $null) {
|
||||
if ($null -eq $triggers) {
|
||||
return ,[System.Collections.ArrayList]@()
|
||||
}
|
||||
|
||||
|
@ -639,7 +639,7 @@ Function Test-TaskExists($task_folder, $name) {
|
|||
$task = $null
|
||||
if ($task_folder) {
|
||||
$raw_tasks = $task_folder.GetTasks(1) # 1 = TASK_ENUM_HIDDEN
|
||||
|
||||
|
||||
for ($i = 1; $i -le $raw_tasks.Count; $i++) {
|
||||
if ($raw_tasks.Item($i).Name -eq $name) {
|
||||
$task = $raw_tasks.Item($i)
|
||||
|
@ -676,24 +676,24 @@ if ($group) {
|
|||
}
|
||||
|
||||
# validate store_password and logon_type
|
||||
if ($logon_type -ne $null) {
|
||||
if ($null -ne $logon_type) {
|
||||
$full_enum_name = "TASK_LOGON_$($logon_type.ToUpper())"
|
||||
$logon_type = [TASK_LOGON_TYPE]::$full_enum_name
|
||||
}
|
||||
|
||||
# now validate the logon_type option with the other parameters
|
||||
if ($username -ne $null -and $group -ne $null) {
|
||||
if ($null -ne $username -and $null -ne $group) {
|
||||
Fail-Json -obj $result -message "username and group can not be set at the same time"
|
||||
}
|
||||
if ($logon_type -ne $null) {
|
||||
if ($logon_type -eq [TASK_LOGON_TYPE]::TASK_LOGON_PASSWORD -and $password -eq $null) {
|
||||
if ($null -ne $logon_type) {
|
||||
if ($logon_type -eq [TASK_LOGON_TYPE]::TASK_LOGON_PASSWORD -and $null -eq $password) {
|
||||
Fail-Json -obj $result -message "password must be set when logon_type=password"
|
||||
}
|
||||
if ($logon_type -eq [TASK_LOGON_TYPE]::TASK_LOGON_S4U -and $password -eq $null) {
|
||||
if ($logon_type -eq [TASK_LOGON_TYPE]::TASK_LOGON_S4U -and $null -eq $password) {
|
||||
Fail-Json -obj $result -message "password must be set when logon_type=s4u"
|
||||
}
|
||||
|
||||
if ($logon_type -eq [TASK_LOGON_TYPE]::TASK_LOGON_GROUP -and $group -eq $null) {
|
||||
if ($logon_type -eq [TASK_LOGON_TYPE]::TASK_LOGON_GROUP -and $null -eq $group) {
|
||||
Fail-Json -obj $result -message "group must be set when logon_type=group"
|
||||
}
|
||||
|
||||
|
@ -704,7 +704,7 @@ if ($logon_type -ne $null) {
|
|||
}
|
||||
|
||||
# convert the run_level to enum value
|
||||
if ($run_level -ne $null) {
|
||||
if ($null -ne $run_level) {
|
||||
if ($run_level -eq "limited") {
|
||||
$run_level = [TASK_RUN_LEVEL]::TASK_RUNLEVEL_LUA
|
||||
} else {
|
||||
|
@ -770,16 +770,16 @@ for ($i = 0; $i -lt $triggers.Count; $i++) {
|
|||
}
|
||||
|
||||
$interval_timespan = $null
|
||||
if ($trigger.repetition.ContainsKey("interval") -and $trigger.repetition.interval -ne $null) {
|
||||
if ($trigger.repetition.ContainsKey("interval") -and $null -ne $trigger.repetition.interval) {
|
||||
$interval_timespan = Test-XmlDurationFormat -key "interval" -value $trigger.repetition.interval
|
||||
}
|
||||
|
||||
$duration_timespan = $null
|
||||
if ($trigger.repetition.ContainsKey("duration") -and $trigger.repetition.duration -ne $null) {
|
||||
if ($trigger.repetition.ContainsKey("duration") -and $null -ne $trigger.repetition.duration) {
|
||||
$duration_timespan = Test-XmlDurationFormat -key "duration" -value $trigger.repetition.duration
|
||||
}
|
||||
|
||||
if ($interval_timespan -ne $null -and $duration_timespan -ne $null -and $interval_timespan -gt $duration_timespan) {
|
||||
if ($null -ne $interval_timespan -and $null -ne $duration_timespan -and $interval_timespan -gt $duration_timespan) {
|
||||
Fail-Json -obj $result -message "trigger repetition option 'interval' value '$($trigger.repetition.interval)' must be less than or equal to 'duration' value '$($trigger.repetition.duration)'"
|
||||
}
|
||||
}
|
||||
|
@ -792,7 +792,7 @@ for ($i = 0; $i -lt $triggers.Count; $i++) {
|
|||
} elseif ($days -isnot [Array]) {
|
||||
$days = @($days)
|
||||
}
|
||||
|
||||
|
||||
$day_value = 0
|
||||
foreach ($day in $days) {
|
||||
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa382057(v=vs.85).aspx
|
||||
|
@ -955,7 +955,7 @@ $task = Test-TaskExists -task_folder $task_folder -name $name
|
|||
$task_path = Join-Path -Path $path -ChildPath $name
|
||||
|
||||
if ($state -eq "absent") {
|
||||
if ($task -ne $null) {
|
||||
if ($null -ne $task) {
|
||||
if (-not $check_mode) {
|
||||
try {
|
||||
$task_folder.DeleteTask($name, 0)
|
||||
|
@ -979,10 +979,10 @@ if ($state -eq "absent") {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if ($task -eq $null) {
|
||||
if ($null -eq $task) {
|
||||
$create_diff_string = "+[Task]`n+$task_path`n`n"
|
||||
# to create a bare minimum task we need 1 action
|
||||
if ($actions -eq $null -or $actions.Count -eq 0) {
|
||||
if ($null -eq $actions -or $actions.Count -eq 0) {
|
||||
Fail-Json -obj $result -message "cannot create a task with no actions, set at least one action with a path to an executable"
|
||||
}
|
||||
|
||||
|
@ -997,11 +997,11 @@ if ($state -eq "absent") {
|
|||
$create_diff_string += "+action[0] = {`n +Type=$([TASK_ACTION_TYPE]::TASK_ACTION_EXEC),`n +Path=$($action.path)`n"
|
||||
$task_action = $task_actions.Create([TASK_ACTION_TYPE]::TASK_ACTION_EXEC)
|
||||
$task_action.Path = $action.path
|
||||
if ($action.arguments -ne $null) {
|
||||
if ($null -ne $action.arguments) {
|
||||
$create_diff_string += " +Arguments=$($action.arguments)`n"
|
||||
$task_action.Arguments = $action.arguments
|
||||
}
|
||||
if ($action.working_directory -ne $null) {
|
||||
if ($null -ne $action.working_directory) {
|
||||
$create_diff_string += " +WorkingDirectory=$($action.working_directory)`n"
|
||||
$task_action.WorkingDirectory = $action.working_directory
|
||||
}
|
||||
|
@ -1019,12 +1019,12 @@ if ($state -eq "absent") {
|
|||
}
|
||||
|
||||
# folder doesn't exist, need to create
|
||||
if ($task_folder -eq $null) {
|
||||
if ($null -eq $task_folder) {
|
||||
$task_folder = $service.GetFolder("\")
|
||||
try {
|
||||
if (-not $check_mode) {
|
||||
$task_folder = $task_folder.CreateFolder($path)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Fail-Json -obj $result -message "failed to create new folder at path '$path': $($_.Exception.Message)"
|
||||
}
|
||||
|
@ -1055,7 +1055,7 @@ if ($state -eq "absent") {
|
|||
$trigger_changes = Compare-Triggers -task_definition $task_definition
|
||||
|
||||
# compile the diffs into one list with headers
|
||||
$task_diff = [System.Collections.ArrayList]@()
|
||||
$task_diff = [System.Collections.ArrayList]@()
|
||||
if ($action_changes.Count -gt 0) {
|
||||
[void]$task_diff.Add("[Actions]")
|
||||
foreach ($action_change in $action_changes) {
|
||||
|
@ -1092,7 +1092,7 @@ if ($state -eq "absent") {
|
|||
[void]$task_diff.Add("`n")
|
||||
}
|
||||
|
||||
if ($password -ne $null -and (($update_password -eq $true) -or ($task_diff.Count -gt 0))) {
|
||||
if ($null -ne $password -and (($update_password -eq $true) -or ($task_diff.Count -gt 0))) {
|
||||
# because we can't compare the passwords we just need to reset it
|
||||
$register_username = $username
|
||||
$register_password = $password
|
||||
|
@ -1103,8 +1103,8 @@ if ($state -eq "absent") {
|
|||
$register_password = $null
|
||||
$register_logon_type = $null
|
||||
}
|
||||
|
||||
if ($task_diff.Count -gt 0 -or $register_password -ne $null) {
|
||||
|
||||
if ($task_diff.Count -gt 0 -or $null -ne $register_password) {
|
||||
if ($check_mode) {
|
||||
# Only validate the task in check mode
|
||||
$task_creation_flags = [TASK_CREATION]::TASK_VALIDATE_ONLY
|
||||
|
@ -1117,12 +1117,12 @@ if ($state -eq "absent") {
|
|||
} catch {
|
||||
Fail-Json -obj $result -message "failed to modify scheduled task: $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
|
||||
if ($diff_mode) {
|
||||
$changed_diff_text = $task_diff -join "`n"
|
||||
if ($result.diff.prepared -ne $null) {
|
||||
if ($null -ne $result.diff.prepared) {
|
||||
$diff_text = "$($result.diff.prepared)`n$changed_diff_text"
|
||||
} else {
|
||||
$diff_text = $changed_diff_text
|
||||
|
|
|
@ -77,7 +77,7 @@ $env:TMP = $original_tmp
|
|||
Function Get-PropertyValue($task_property, $com, $property) {
|
||||
$raw_value = $com.$property
|
||||
|
||||
if ($raw_value -eq $null) {
|
||||
if ($null -eq $raw_value) {
|
||||
return $null
|
||||
} elseif ($raw_value.GetType().Name -eq "__ComObject") {
|
||||
$com_values = @{}
|
||||
|
@ -267,15 +267,15 @@ for ($i = 1; $i -le $folder_tasks.Count; $i++) {
|
|||
$folder_task_names += $task_name
|
||||
$folder_task_count += 1
|
||||
|
||||
if ($name -ne $null -and $task_name -eq $name) {
|
||||
if ($null -ne $name -and $task_name -eq $name) {
|
||||
$task = $folder_tasks.Item($i)
|
||||
}
|
||||
}
|
||||
$result.folder_task_names = $folder_task_names
|
||||
$result.folder_task_count = $folder_task_count
|
||||
|
||||
if ($name -ne $null) {
|
||||
if ($task -ne $null) {
|
||||
if ($null -ne $name) {
|
||||
if ($null -ne $task) {
|
||||
$result.task_exists = $true
|
||||
|
||||
# task state
|
||||
|
|
|
@ -102,7 +102,7 @@ Function ConvertTo-Ini($ini) {
|
|||
$value_key = $value.Name
|
||||
$value_value = $value.Value
|
||||
|
||||
if ($value_value -ne $null) {
|
||||
if ($null -ne $value_value) {
|
||||
$content += "$value_key = $value_value"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ $params = Parse-Args $args -supports_check_mode $true
|
|||
$check_mode = Get-AnsibleParam -obj $params -name '_ansible_check_mode' -type 'bool' -default $false
|
||||
|
||||
$dependencies = Get-AnsibleParam -obj $params -name 'dependencies' -type 'list' -default $null
|
||||
$dependency_action = Get-AnsibleParam -obj $params -name 'dependency_action' -type 'str' -default 'set' -validateset 'add','remove','set'
|
||||
$dependency_action = Get-AnsibleParam -obj $params -name 'dependency_action' -type 'str' -default 'set' -validateset 'add','remove','set'
|
||||
$description = Get-AnsibleParam -obj $params -name 'description' -type 'str'
|
||||
$desktop_interact = Get-AnsibleParam -obj $params -name 'desktop_interact' -type 'bool' -default $false
|
||||
$display_name = Get-AnsibleParam -obj $params -name 'display_name' -type 'str'
|
||||
|
@ -29,7 +29,7 @@ $result = @{
|
|||
}
|
||||
|
||||
# parse the username to SID and back so we get the full username with domain in a way WMI understands
|
||||
if ($username -ne $null) {
|
||||
if ($null -ne $username) {
|
||||
if ($username -eq "LocalSystem") {
|
||||
$username_sid = "S-1-5-18"
|
||||
} else {
|
||||
|
@ -49,13 +49,13 @@ if ($username -ne $null) {
|
|||
$username = Convert-FromSID -sid $username_sid
|
||||
}
|
||||
}
|
||||
if ($password -ne $null -and $username -eq $null) {
|
||||
if ($null -ne $password -and $null -eq $username) {
|
||||
Fail-Json $result "The argument 'username' must be supplied with 'password'"
|
||||
}
|
||||
if ($desktop_interact -eq $true -and (-not ($username -eq "LocalSystem" -or $username -eq $null))) {
|
||||
if ($desktop_interact -eq $true -and (-not ($username -eq "LocalSystem" -or $null -eq $username))) {
|
||||
Fail-Json $result "Can only set 'desktop_interact' to true when 'username' equals 'LocalSystem'"
|
||||
}
|
||||
if ($path -ne $null) {
|
||||
if ($null -ne $path) {
|
||||
$path = [System.Environment]::ExpandEnvironmentVariables($path)
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ Function Get-ServiceInfo($name) {
|
|||
|
||||
# Delayed start_mode is in reality Automatic (Delayed), need to check reg key for type
|
||||
$delayed = Get-DelayedStatus -name $svc.Name
|
||||
$actual_start_mode = $wmi_svc.StartMode.ToString().ToLower()
|
||||
$actual_start_mode = $wmi_svc.StartMode.ToString().ToLower()
|
||||
if ($delayed -and $actual_start_mode -eq 'auto') {
|
||||
$actual_start_mode = 'delayed'
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ Function Get-ServiceInfo($name) {
|
|||
}
|
||||
}
|
||||
$description = $wmi_svc.Description
|
||||
if ($description -eq $null) {
|
||||
if ($null -eq $description) {
|
||||
$description = ""
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ Function Set-ServiceStartMode($svc, $start_mode) {
|
|||
} catch {
|
||||
Fail-Json $result $_.Exception.Message
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ Function Set-ServiceAccount($wmi_svc, $username_sid, $username, $password) {
|
|||
$error_msg = Get-WmiErrorMessage -return_value $result.ReturnValue
|
||||
Fail-Json -obj $result -message "Failed to set service account to $($username): $($return.ReturnValue) - $error_msg"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result.changed = $true
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ Function Set-ServiceDisplayName($svc, $display_name) {
|
|||
} catch {
|
||||
Fail-Json $result $_.Exception.Message
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ Function Set-ServiceDescription($svc, $description) {
|
|||
} catch {
|
||||
Fail-Json $result $_.Exception.Message
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ Function Set-ServicePath($name, $path) {
|
|||
} catch {
|
||||
Fail-Json $result $_.Exception.Message
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
}
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ Function Set-ServiceDependencies($wmi_svc, $dependency_action, $dependencies) {
|
|||
Fail-Json -obj $result -message "Failed to set service dependencies $($dep_string): $($return.ReturnValue) - $error_msg"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
}
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ Function Set-ServiceState($svc, $wmi_svc, $state) {
|
|||
Fail-Json $result $_.Exception.Message
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
}
|
||||
|
||||
|
@ -325,7 +325,7 @@ Function Set-ServiceState($svc, $wmi_svc, $state) {
|
|||
} catch {
|
||||
Fail-Json $result $_.Exception.Message
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
}
|
||||
|
||||
|
@ -335,7 +335,7 @@ Function Set-ServiceState($svc, $wmi_svc, $state) {
|
|||
} catch {
|
||||
Fail-Json $result $_.Exception.Message
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
}
|
||||
|
||||
|
@ -366,7 +366,7 @@ Function Set-ServiceState($svc, $wmi_svc, $state) {
|
|||
Fail-Json -obj $result -message "Failed to delete service $($svc.Name): $($return.ReturnValue) - $error_msg"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result.changed = $true
|
||||
}
|
||||
}
|
||||
|
@ -378,35 +378,35 @@ Function Set-ServiceConfiguration($svc) {
|
|||
Fail-Json $result "Can only set desktop_interact to true when service is run with/or 'username' equals 'LocalSystem'"
|
||||
}
|
||||
|
||||
if ($start_mode -ne $null) {
|
||||
if ($null -ne $start_mode) {
|
||||
Set-ServiceStartMode -svc $svc -start_mode $start_mode
|
||||
}
|
||||
|
||||
if ($username -ne $null) {
|
||||
if ($null -ne $username) {
|
||||
Set-ServiceAccount -wmi_svc $wmi_svc -username_sid $username_sid -username $username -password $password
|
||||
}
|
||||
|
||||
if ($display_name -ne $null) {
|
||||
if ($null -ne $display_name) {
|
||||
Set-ServiceDisplayName -svc $svc -display_name $display_name
|
||||
}
|
||||
|
||||
if ($desktop_interact -ne $null) {
|
||||
if ($null -ne $desktop_interact) {
|
||||
Set-ServiceDesktopInteract -wmi_svc $wmi_svc -desktop_interact $desktop_interact
|
||||
}
|
||||
|
||||
if ($description -ne $null) {
|
||||
if ($null -ne $description) {
|
||||
Set-ServiceDescription -svc $svc -description $description
|
||||
}
|
||||
|
||||
if ($path -ne $null) {
|
||||
if ($null -ne $path) {
|
||||
Set-ServicePath -name $svc.Name -path $path
|
||||
}
|
||||
|
||||
if ($dependencies -ne $null) {
|
||||
if ($null -ne $dependencies) {
|
||||
Set-ServiceDependencies -wmi_svc $wmi_svc -dependency_action $dependency_action -dependencies $dependencies
|
||||
}
|
||||
|
||||
if ($state -ne $null) {
|
||||
if ($null -ne $state) {
|
||||
Set-ServiceState -svc $svc -wmi_svc $wmi_svc -state $state
|
||||
}
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ if ($svc) {
|
|||
$result.exists = $false
|
||||
if ($state -ne 'absent') {
|
||||
# Check if path is defined, if so create the service
|
||||
if ($path -ne $null) {
|
||||
if ($null -ne $path) {
|
||||
try {
|
||||
New-Service -Name $name -BinaryPathname $path -WhatIf:$check_mode
|
||||
} catch {
|
||||
|
@ -433,14 +433,14 @@ if ($svc) {
|
|||
} else {
|
||||
# We will only reach here if the service is installed and the state is not absent
|
||||
# Will check if any of the default actions are set and fail as we cannot action it
|
||||
if ($start_mode -ne $null -or
|
||||
$state -ne $null -or
|
||||
$username -ne $null -or
|
||||
$password -ne $null -or
|
||||
$display_name -ne $null -or
|
||||
$description -ne $null -or
|
||||
if ($null -ne $start_mode -or
|
||||
$null -ne $state -or
|
||||
$null -ne $username -or
|
||||
$null -ne $password -or
|
||||
$null -ne $display_name -or
|
||||
$null -ne $description -or
|
||||
$desktop_interact -ne $false -or
|
||||
$dependencies -ne $null -or
|
||||
$null -ne $dependencies -or
|
||||
$dependency_action -ne 'set') {
|
||||
Fail-Json $result "Service '$name' is not installed, need to set 'path' to create a new service"
|
||||
}
|
||||
|
@ -456,7 +456,7 @@ if ($state -eq 'absent') {
|
|||
changed = $changed
|
||||
exists = $false
|
||||
}
|
||||
} elseif ($svc -ne $null) {
|
||||
} elseif ($null -ne $svc) {
|
||||
Get-ServiceInfo -name $name
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ $result = @{
|
|||
[System.Collections.ArrayList]$indexes = @()
|
||||
|
||||
# Type checking
|
||||
# You would think that "$managers -ne $null" would work, but it doesn't.
|
||||
# You would think that "$null -ne $managers" would work, but it doesn't.
|
||||
# A proper type check is required. If a user provides an empty list then $managers
|
||||
# is still of the correct type. If a user provides no option then $managers is $null.
|
||||
If ($managers -Is [System.Collections.ArrayList] -And $managers.Count -gt 0 -And $managers[0] -IsNot [String]) {
|
||||
|
|
|
@ -40,7 +40,7 @@ $common_functions = {
|
|||
$msg = "$date_str $msg"
|
||||
|
||||
Write-Debug -Message $msg
|
||||
if ($log_path -ne $null -and (-not $check_mode)) {
|
||||
if ($null -ne $log_path -and (-not $check_mode)) {
|
||||
Add-Content -Path $log_path -Value $msg
|
||||
}
|
||||
}
|
||||
|
@ -448,7 +448,7 @@ Function Start-Natively($common_functions, $script) {
|
|||
Function Remove-ScheduledJob($name) {
|
||||
$scheduled_job = Get-ScheduledJob -Name $name -ErrorAction SilentlyContinue
|
||||
|
||||
if ($scheduled_job -ne $null) {
|
||||
if ($null -ne $scheduled_job) {
|
||||
Write-DebugLog -msg "Scheduled Job $name exists, ensuring it is not running..."
|
||||
$scheduler = New-Object -ComObject Schedule.Service
|
||||
Write-DebugLog -msg "Connecting to scheduler service..."
|
||||
|
@ -509,7 +509,7 @@ Function Start-AsScheduledTask($common_functions, $script) {
|
|||
Write-DebugLog -msg "Waiting for job completion..."
|
||||
|
||||
# Wait-Job can fail for a few seconds until the scheduled task starts - poll for it...
|
||||
while ($job -eq $null) {
|
||||
while ($null -eq $job) {
|
||||
Start-Sleep -Milliseconds 100
|
||||
if ($sw.ElapsedMilliseconds -ge 30000) { # tasks scheduled right after boot on 2008R2 can take awhile to start...
|
||||
Fail-Json -msg "Timed out waiting for scheduled task to start"
|
||||
|
@ -523,7 +523,7 @@ Function Start-AsScheduledTask($common_functions, $script) {
|
|||
$sw = [System.Diagnostics.Stopwatch]::StartNew()
|
||||
|
||||
# NB: output from scheduled jobs is delayed after completion (including the sub-objects after the primary Output object is available)
|
||||
while (($job.Output -eq $null -or -not ($job.Output | Get-Member -Name Key -ErrorAction Ignore) -or -not $job.Output.Key.Contains("job_output")) -and $sw.ElapsedMilliseconds -lt 15000) {
|
||||
while (($null -eq $job.Output -or -not ($job.Output | Get-Member -Name Key -ErrorAction Ignore) -or -not $job.Output.Key.Contains("job_output")) -and $sw.ElapsedMilliseconds -lt 15000) {
|
||||
Write-DebugLog -msg "Waiting for job output to populate..."
|
||||
Start-Sleep -Milliseconds 500
|
||||
}
|
||||
|
@ -536,7 +536,7 @@ Function Start-AsScheduledTask($common_functions, $script) {
|
|||
DebugOutput = $job.Debug
|
||||
}
|
||||
|
||||
if ($job.Output -eq $null -or -not $job.Output.Keys.Contains('job_output')) {
|
||||
if ($null -eq $job.Output -or -not $job.Output.Keys.Contains('job_output')) {
|
||||
$ret.Output = @{failed = $true; msg = "job output was lost"}
|
||||
} else {
|
||||
$ret.Output = $job.Output.job_output # sub-object returned, can only be accessed as a property for some reason
|
||||
|
|
|
@ -129,11 +129,11 @@ $account_locked = Get-AnsibleParam -obj $params -name "account_locked" -type "bo
|
|||
$groups = Get-AnsibleParam -obj $params -name "groups"
|
||||
$groups_action = Get-AnsibleParam -obj $params -name "groups_action" -type "str" -default "replace" -validateset "add","remove","replace"
|
||||
|
||||
If ($account_locked -ne $null -and $account_locked) {
|
||||
If ($null -ne $account_locked -and $account_locked) {
|
||||
Fail-Json $result "account_locked must be set to 'no' if provided"
|
||||
}
|
||||
|
||||
If ($groups -ne $null) {
|
||||
If ($null -ne $groups) {
|
||||
If ($groups -is [System.String]) {
|
||||
[string[]]$groups = $groups.Split(",")
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ If ($groups -ne $null) {
|
|||
Fail-Json $result "groups must be a string or array"
|
||||
}
|
||||
$groups = $groups | ForEach { ([string]$_).Trim() } | Where { $_ }
|
||||
If ($groups -eq $null) {
|
||||
If ($null -eq $groups) {
|
||||
$groups = @()
|
||||
}
|
||||
}
|
||||
|
@ -153,13 +153,13 @@ If ($state -eq 'present') {
|
|||
try {
|
||||
If (-not $user_obj) {
|
||||
$user_obj = $adsi.Create("User", $username)
|
||||
If ($password -ne $null) {
|
||||
If ($null -ne $password) {
|
||||
$user_obj.SetPassword($password)
|
||||
}
|
||||
$user_obj.SetInfo()
|
||||
$result.changed = $true
|
||||
}
|
||||
ElseIf (($password -ne $null) -and ($update_password -eq 'always')) {
|
||||
ElseIf (($null -ne $password) -and ($update_password -eq 'always')) {
|
||||
# ValidateCredentials will fail if either of these are true- just force update...
|
||||
If($user_obj.AccountDisabled -or $user_obj.PasswordExpired) {
|
||||
$password_match = $false
|
||||
|
@ -177,19 +177,19 @@ If ($state -eq 'present') {
|
|||
$result.changed = $true
|
||||
}
|
||||
}
|
||||
If (($fullname -ne $null) -and ($fullname -ne $user_obj.FullName[0])) {
|
||||
If (($null -ne $fullname) -and ($fullname -ne $user_obj.FullName[0])) {
|
||||
$user_obj.FullName = $fullname
|
||||
$result.changed = $true
|
||||
}
|
||||
If (($description -ne $null) -and ($description -ne $user_obj.Description[0])) {
|
||||
If (($null -ne $description) -and ($description -ne $user_obj.Description[0])) {
|
||||
$user_obj.Description = $description
|
||||
$result.changed = $true
|
||||
}
|
||||
If (($password_expired -ne $null) -and ($password_expired -ne ($user_obj.PasswordExpired | ConvertTo-Bool))) {
|
||||
If (($null -ne $password_expired) -and ($password_expired -ne ($user_obj.PasswordExpired | ConvertTo-Bool))) {
|
||||
$user_obj.PasswordExpired = If ($password_expired) { 1 } Else { 0 }
|
||||
$result.changed = $true
|
||||
}
|
||||
If (($password_never_expires -ne $null) -and ($password_never_expires -ne (Get-UserFlag $user_obj $ADS_UF_DONT_EXPIRE_PASSWD))) {
|
||||
If (($null -ne $password_never_expires) -and ($password_never_expires -ne (Get-UserFlag $user_obj $ADS_UF_DONT_EXPIRE_PASSWD))) {
|
||||
If ($password_never_expires) {
|
||||
Set-UserFlag $user_obj $ADS_UF_DONT_EXPIRE_PASSWD
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ If ($state -eq 'present') {
|
|||
}
|
||||
$result.changed = $true
|
||||
}
|
||||
If (($user_cannot_change_password -ne $null) -and ($user_cannot_change_password -ne (Get-UserFlag $user_obj $ADS_UF_PASSWD_CANT_CHANGE))) {
|
||||
If (($null -ne $user_cannot_change_password) -and ($user_cannot_change_password -ne (Get-UserFlag $user_obj $ADS_UF_PASSWD_CANT_CHANGE))) {
|
||||
If ($user_cannot_change_password) {
|
||||
Set-UserFlag $user_obj $ADS_UF_PASSWD_CANT_CHANGE
|
||||
}
|
||||
|
@ -207,11 +207,11 @@ If ($state -eq 'present') {
|
|||
}
|
||||
$result.changed = $true
|
||||
}
|
||||
If (($account_disabled -ne $null) -and ($account_disabled -ne $user_obj.AccountDisabled)) {
|
||||
If (($null -ne $account_disabled) -and ($account_disabled -ne $user_obj.AccountDisabled)) {
|
||||
$user_obj.AccountDisabled = $account_disabled
|
||||
$result.changed = $true
|
||||
}
|
||||
If (($account_locked -ne $null) -and ($account_locked -ne $user_obj.IsAccountLocked)) {
|
||||
If (($null -ne $account_locked) -and ($account_locked -ne $user_obj.IsAccountLocked)) {
|
||||
$user_obj.IsAccountLocked = $account_locked
|
||||
$result.changed = $true
|
||||
}
|
||||
|
|
|
@ -27,28 +27,28 @@ $result = @{
|
|||
}
|
||||
|
||||
# validate the input with the various options
|
||||
if ($port -ne $null -and $path -ne $null) {
|
||||
if ($null -ne $port -and $null -ne $path) {
|
||||
Fail-Json $result "port and path parameter can not both be passed to win_wait_for"
|
||||
}
|
||||
if ($exclude_hosts -ne $null -and $state -ne "drained") {
|
||||
if ($null -ne $exclude_hosts -and $state -ne "drained") {
|
||||
Fail-Json $result "exclude_hosts should only be with state=drained"
|
||||
}
|
||||
if ($path -ne $null) {
|
||||
if ($null -ne $path) {
|
||||
if ($state -in @("stopped","drained")) {
|
||||
Fail-Json $result "state=$state should only be used for checking a port in the win_wait_for module"
|
||||
}
|
||||
|
||||
if ($exclude_hosts -ne $null) {
|
||||
if ($null -ne $exclude_hosts) {
|
||||
Fail-Json $result "exclude_hosts should only be used when checking a port and state=drained in the win_wait_for module"
|
||||
}
|
||||
}
|
||||
|
||||
if ($port -ne $null) {
|
||||
if ($search_regex -ne $null) {
|
||||
if ($null -ne $port) {
|
||||
if ($null -ne $search_regex) {
|
||||
Fail-Json $result "search_regex should by used when checking a string in a file in the win_wait_for module"
|
||||
}
|
||||
|
||||
if ($exclude_hosts -ne $null -and $state -ne "drained") {
|
||||
if ($null -ne $exclude_hosts -and $state -ne "drained") {
|
||||
Fail-Json $result "exclude_hosts should be used when state=drained in the win_wait_for module"
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ Function Get-PortConnections($hostname, $port) {
|
|||
$active_connections = $conn_info.GetActiveTcpConnections() | Where-Object { $_.LocalEndPoint.Address -eq $hostname -and $_.LocalEndPoint.Port -eq $port }
|
||||
}
|
||||
|
||||
if ($active_connections -ne $null) {
|
||||
if ($null -ne $active_connections) {
|
||||
foreach ($active_connection in $active_connections) {
|
||||
$connections += $active_connection.RemoteEndPoint.Address
|
||||
}
|
||||
|
@ -97,14 +97,14 @@ Function Get-PortConnections($hostname, $port) {
|
|||
|
||||
$module_start = Get-Date
|
||||
|
||||
if ($delay -ne $null) {
|
||||
if ($null -ne $delay) {
|
||||
Start-Sleep -Seconds $delay
|
||||
}
|
||||
|
||||
$attempts = 0
|
||||
if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
|
||||
if ($null -eq $path -and $null -eq $port -and $state -ne "drained") {
|
||||
Start-Sleep -Seconds $timeout
|
||||
} elseif ($path -ne $null) {
|
||||
} elseif ($null -ne $path) {
|
||||
if ($state -in @("present", "started")) {
|
||||
# check if the file exists or string exists in file
|
||||
$start_time = Get-Date
|
||||
|
@ -112,7 +112,7 @@ if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
|
|||
while (((Get-Date) - $start_time).TotalSeconds -lt $timeout) {
|
||||
$attempts += 1
|
||||
if (Test-AnsiblePath -Path $path) {
|
||||
if ($search_regex -eq $null) {
|
||||
if ($null -eq $search_regex) {
|
||||
$complete = $true
|
||||
break
|
||||
} else {
|
||||
|
@ -129,7 +129,7 @@ if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
|
|||
if ($complete -eq $false) {
|
||||
$result.elapsed = ((Get-Date) - $module_start).TotalSeconds
|
||||
$result.wait_attempts = $attempts
|
||||
if ($search_regex -eq $null) {
|
||||
if ($null -eq $search_regex) {
|
||||
Fail-Json $result "timeout while waiting for file $path to be present"
|
||||
} else {
|
||||
Fail-Json $result "timeout while waiting for string regex $search_regex in file $path to match"
|
||||
|
@ -142,7 +142,7 @@ if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
|
|||
while (((Get-Date) - $start_time).TotalSeconds -lt $timeout) {
|
||||
$attempts += 1
|
||||
if (Test-AnsiblePath -Path $path) {
|
||||
if ($search_regex -ne $null) {
|
||||
if ($null -ne $search_regex) {
|
||||
$file_contents = Get-Content -Path $path -Raw
|
||||
if ($file_contents -notmatch $search_regex) {
|
||||
$complete = $true
|
||||
|
@ -160,14 +160,14 @@ if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
|
|||
if ($complete -eq $false) {
|
||||
$result.elapsed = ((Get-Date) - $module_start).TotalSeconds
|
||||
$result.wait_attempts = $attempts
|
||||
if ($search_regex -eq $null) {
|
||||
if ($null -eq $search_regex) {
|
||||
Fail-Json $result "timeout while waiting for file $path to be absent"
|
||||
} else {
|
||||
Fail-Json $result "timeout while waiting for string regex $search_regex in file $path to not match"
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($port -ne $null) {
|
||||
} elseif ($null -ne $port) {
|
||||
if ($state -in @("started","present")) {
|
||||
# check that the port is online and is listening
|
||||
$start_time = Get-Date
|
||||
|
@ -215,7 +215,7 @@ if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
|
|||
while (((Get-Date) - $start_time).TotalSeconds -lt $timeout) {
|
||||
$attempts += 1
|
||||
$active_connections = Get-PortConnections -hostname $hostname -port $port
|
||||
if ($active_connections -eq $null) {
|
||||
if ($null -eq $active_connections) {
|
||||
$complete = $true
|
||||
break
|
||||
} elseif ($active_connections.Count -eq 0) {
|
||||
|
@ -224,7 +224,7 @@ if ($path -eq $null -and $port -eq $null -and $state -ne "drained") {
|
|||
break
|
||||
} else {
|
||||
# there are listeners, check if we should ignore any hosts
|
||||
if ($exclude_hosts -ne $null) {
|
||||
if ($null -ne $exclude_hosts) {
|
||||
$connection_info = $active_connections
|
||||
foreach ($exclude_host in $exclude_hosts) {
|
||||
try {
|
||||
|
|
|
@ -27,12 +27,12 @@ Function Find-WebPiCmd
|
|||
[CmdletBinding()]
|
||||
param()
|
||||
$p = Find-Command "webpicmd.exe"
|
||||
if ($p -ne $null)
|
||||
if ($null -ne $p)
|
||||
{
|
||||
return $p
|
||||
}
|
||||
$a = Find-Command "c:\programdata\chocolatey\bin\webpicmd.exe"
|
||||
if ($a -ne $null)
|
||||
if ($null -ne $a)
|
||||
{
|
||||
return $a
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ $tests = @(
|
|||
)
|
||||
|
||||
# Add domain tests if the domain name has been set
|
||||
if ($test_domain -ne $null) {
|
||||
if ($null -ne $test_domain) {
|
||||
Import-Module ActiveDirectory
|
||||
$domain_info = Get-ADDomain -Identity $test_domain
|
||||
$domain_sid = $domain_info.DomainSID
|
||||
|
|
|
@ -121,7 +121,6 @@ lib/ansible/modules/windows/win_regmerge.ps1 PSCustomUseLiteralPath
|
|||
lib/ansible/modules/windows/win_robocopy.ps1 PSCustomUseLiteralPath
|
||||
lib/ansible/modules/windows/win_route.ps1 PSAvoidTrailingWhitespace
|
||||
lib/ansible/modules/windows/win_route.ps1 PSAvoidUsingCmdletAliases
|
||||
lib/ansible/modules/windows/win_scheduled_task.ps1 PSAvoidTrailingWhitespace
|
||||
lib/ansible/modules/windows/win_scheduled_task_stat.ps1 PSAvoidTrailingWhitespace
|
||||
lib/ansible/modules/windows/win_scheduled_task_stat.ps1 PSAvoidUsingCmdletAliases
|
||||
lib/ansible/modules/windows/win_scheduled_task_stat.ps1 PSUseDeclaredVarsMoreThanAssignments
|
||||
|
@ -129,7 +128,6 @@ lib/ansible/modules/windows/win_security_policy.ps1 PSAvoidTrailingWhitespace
|
|||
lib/ansible/modules/windows/win_security_policy.ps1 PSCustomUseLiteralPath
|
||||
lib/ansible/modules/windows/win_security_policy.ps1 PSUseApprovedVerbs
|
||||
lib/ansible/modules/windows/win_security_policy.ps1 PSUseDeclaredVarsMoreThanAssignments
|
||||
lib/ansible/modules/windows/win_service.ps1 PSAvoidTrailingWhitespace
|
||||
lib/ansible/modules/windows/win_share.ps1 PSCustomUseLiteralPath
|
||||
lib/ansible/modules/windows/win_shell.ps1 PSAvoidTrailingWhitespace
|
||||
lib/ansible/modules/windows/win_shell.ps1 PSAvoidUsingCmdletAliases
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
@{
|
||||
ExcludeRules=@(
|
||||
'PSPossibleIncorrectComparisonWithNull',
|
||||
'PSUseOutputTypeCorrectly',
|
||||
'PSUseShouldProcessForStateChangingFunctions',
|
||||
# We send strings as plaintext so will always come across the 3 issues
|
||||
|
|
Loading…
Reference in a new issue