Private/Import-CmxMalwarePolicies.ps1
function Import-CmxMalwarePolicies { [CmdletBinding(SupportsShouldProcess=$True)] param ( [parameter(Mandatory=$True)] [ValidateNotNullOrEmpty()] $DataSet ) Write-Log -Category "info" -Message "------------------------------ Import-CmxMalwarePolicies -------------------------------" Write-Host "Configuring antimalware policies" -ForegroundColor Green $result = $true $Time1 = Get-Date foreach ($item in $DataSet.configuration.cmsite.malwarepolicies.malwarepolicy | Where-Object {$_.use -eq '1'}) { $itemName = $item.name $itemComm = $item.comment $itemPath = $item.path Write-Log -Category "info" -Message "policy name: $itemName" if (Get-CMAntimalwarePolicy -Name $itemName) { Write-Log -Category info -Message "po;icy already exists" } else { try { Import-CMAntimalwarePolicy -Path "$itemPath" -NewName "$itemName" -ErrorAction SilentlyContinue | Out-Null Write-Log -Category "info" -Message "policy created successfully" } catch { Write-Log -Category error -Message $_.Exception.Message $result = $False break } } Write-Verbose "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" } # foreach Write-Log -Category info -Message "function runtime: $(Get-TimeOffset $time1)" Write-Output $result } |