Private/importCmxMalwarePolicies.ps1
function importCmxMalwarePolicies { [CmdletBinding(SupportsShouldProcess=$True)] param ( [parameter(Mandatory=$True)] [ValidateNotNullOrEmpty()] $DataSet ) writeLogFile -Category "info" -Message "------------------------------ importCmxMalwarePolicies -------------------------------" 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 writeLogFile -Category "info" -Message "policy name: $itemName" if (Get-CMAntimalwarePolicy -Name $itemName) { writeLogFile -Category info -Message "po;icy already exists" } else { try { Import-CMAntimalwarePolicy -Path "$itemPath" -NewName "$itemName" -ErrorAction SilentlyContinue | Out-Null writeLogFile -Category "info" -Message "policy created successfully" } catch { writeLogFile -Category error -Message $_.Exception.Message $result = $False break } } Write-Verbose "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" } # foreach writeLogFile -Category info -Message "function runtime: $(getTimeOffset $time1)" Write-Output $result } |