@@ -81,26 +81,28 @@ function Invoke-CIPPStandardMalwareFilterPolicy {
8181 }
8282
8383 # Use custom name if provided, otherwise use default for backward compatibility
84- $PolicyName = if ($Settings.name ) { $Settings.name } else { ' CIPP Default Malware Policy' }
85- $PolicyList = @ ($PolicyName , ' CIPP Default Malware Policy' , ' Default Malware Policy' )
86- $ExistingPolicy = $AllMalwareFilterPolicies | Where-Object - Property Name -In $PolicyList | Select-Object - First 1
87- if ($null -eq $ExistingPolicy.Name ) {
88- # No existing policy - use the configured/default name
89- $PolicyName = if ($Settings.name ) { $Settings.name } else { ' CIPP Default Malware Policy' }
90- } else {
91- # Use existing policy name if found
92- $PolicyName = $ExistingPolicy.Name
84+ $DefaultPolicyName = ' CIPP Default Malware Policy'
85+ $PolicyName = if ($Settings.name ) { $Settings.name } else { $DefaultPolicyName }
86+ # Only match against legacy/default names when no custom name is provided. When a custom
87+ # name is set, deploy it as a new policy instead of reusing an existing default-named one.
88+ if ($PolicyName -eq $DefaultPolicyName ) {
89+ $PolicyList = @ ($PolicyName , ' Default Malware Policy' )
90+ $ExistingPolicy = $AllMalwareFilterPolicies | Where-Object - Property Name -In $PolicyList | Select-Object - First 1
91+ if ($null -ne $ExistingPolicy.Name ) {
92+ # Use existing policy name if found
93+ $PolicyName = $ExistingPolicy.Name
94+ }
9395 }
94- # Derive rule name from policy name, but check for old names for backward compatibility
96+ # Derive rule name from policy name. Only check legacy names when using the default policy name.
9597 $DesiredRuleName = " $PolicyName Rule"
96- $RuleList = @ ( $DesiredRuleName , ' CIPP Default Malware Rule ' , ' CIPP Default Malware Policy ' )
97- $ExistingRule = $AllMalwareFilterRules | Where-Object - Property Name -In $RuleList | Select-Object - First 1
98- if ( $null -eq $ExistingRule .Name ) {
99- # No existing rule - use the derived name
100- $RuleName = $DesiredRuleName
101- } else {
102- # Use existing rule name if found
103- $RuleName = $ExistingRule .Name
98+ $RuleName = $DesiredRuleName
99+ if ( $PolicyName -eq $DefaultPolicyName ) {
100+ $RuleList = @ ( $DesiredRuleName , ' CIPP Default Malware Rule ' , ' CIPP Default Malware Policy ' )
101+ $ExistingRule = $AllMalwareFilterRules | Where-Object - Property Name -In $RuleList | Select-Object - First 1
102+ if ( $null -ne $ExistingRule .Name ) {
103+ # Use existing rule name if found
104+ $RuleName = $ExistingRule .Name
105+ }
104106 }
105107
106108 $CurrentState = $AllMalwareFilterPolicies |
0 commit comments