<# .Synopsis Creates blacklisted IPs on Checkpoint. .DESCRIPTION Connects to Checkpoint mgmt via WebAPI and creates hosts objects with IPs from CSV file and adds them to specific blacklist group .PARAMETER Path Path to the source CSV file with IPs. .PARAMETER Prefix Prefix for hostname. Default value = "rmt-" .PARAMETER Group Groupname to add new hosts to. Default value = "IPBlacklist" .PARAMETER Comment Description text for new created hosts. Default "Blacklist, HD12345678" .EXAMPLE ./Add-Blacklist.ps1 -Path= "c:\hosts.csv" -Prefix "Blacklist-" -Group "Blacklist_G" #> param ( [string]$Path = "C:\PowerShell\Scripts\Checkpoint\Blacklist\hosts.txt", [string]$Prefix = "rmt-", [string]$Group = "IPBlacklist", [string]$Comment = "Blacklist, HD12345678" ) Clear-Host $ScriptPath = Split-Path -parent $MyInvocation.MyCommand.Path $LogFile = (Get-Item $PSCommandPath ).Basename + ".Log" if ($host.name -eq "ConsoleHost") {Start-Transcript -Path $LogFile} Clear-Host Import-Module pscheckpoint $CPServer = "192.168.56.200" $AdminName = "webapi" $Cred = Get-Credential -UserName $AdminName -Message "Enter password for $AdminName" $CPSession = $null $CPSessions = $null $CPSession = Open-CheckPointSession -ManagementServer $CPServer -Credentials $Cred -SessionName "Powershell, $Comment" -SessionTimeout 300 -ErrorAction Stop -CertificateValidation None -PassThru $CPSessions = Get-CheckPointSessions -ErrorAction SilentlyContinue -Session $CPSession if ($CPSessions) { Write-Host "Server:",$CPServer,"connected..."-ForegroundColor Green Write-Host "CP Sessions:" $CPSessions | Format-Table IPAddress,Name,UserName,State,Application Write-Host "Importing source IPs..." $Hosts = Import-Csv -Path $Path Write-Host "Creating FW objects..." foreach ($Record in $Hosts) { $HostIP = $null $HostName = $null $HostIP=$Record.IPAddress $HostName=$Prefix + $HostIP Write-Host "Host:",$HostName,"(IP:",$HostIP,")","->",$Group New-CheckPointHost -IPv4Address $HostIP -Name $HostName -Groups $Group -SetIfExists -Color Black -Comments $Comment -Session $CPSession } Write-Host "Publishing changes..." Publish-CheckPointSession -Session $CPSession Write-Host "Closing CP session..." Close-CheckPointSession -Session $CPSession  Write-Host "Done." } else {Write-Host "Error connecting to server:",$CPServer -ForegroundColor Red} if ($host.name -eq "ConsoleHost") {Stop-Transcript}