################################################################################## # # This is just a wrapper to run Import-Firewall-Blocklist.ps1 as a scheduled task. # It cannot be used as-is, it is just an example since attendees asked for it. # The URLs to download the IP address ranges might change at any time. # The format of the files downloaded might change at any time. # But it shows how a scheduled job might be set up to create firewall rules. # ################################################################################## # Change present working directory and check it. # This the directory for the scheduled job script. cd c:\progra~1\1-ScheduledTasks\Firewall-Blocklist if ($pwd.path -notlike '*Blocklist') { exit -1 } # Utility function to use a regex to extract desired text. filter extract-text ($RegularExpression) { select-string -inputobject $_ -pattern $regularexpression -allmatches | select-object -expandproperty matches | foreach { if ($_.groups.count -le 1) { if ($_.value){ $_.value } } else { $submatches = select-object -input $_ -expandproperty groups $submatches[1..($submatches.count - 1)] | foreach { if ($_.value){ $_.value } } } } } # Utility function to extract IP address range data, but it must be edited # for each source and whenever that source changes its formatting. function get-cidr ($string) { #Use with the software77.net site or sites with a