Skip to content

Instantly share code, notes, and snippets.

@yannhowe
Last active January 9, 2020 20:05
Show Gist options
  • Save yannhowe/2e3456bf48cc5988f65539d477687a1c to your computer and use it in GitHub Desktop.
Save yannhowe/2e3456bf48cc5988f65539d477687a1c to your computer and use it in GitHub Desktop.
Powershell to download McAfee and ClamAV Patches
# Had to seperate downloading of each product files instead of providing URL list and finding all links due to laziness to handle relative and absolute linking. Perhaps one day I'll fix it.
$start_time = Get-Date
$download_folder = "D:\Anti-Virus Patches"
# Download URL list
$mcafee_page_url = "http://download.nai.com/products/DatFiles/4.x/NAI/"
$mcafee_file_path = "http://download.nai.com/products/DatFiles/4.x/NAI/"
$clamav_page_url = "https://www.clamav.net/downloads/"
$clamav_file_path = "http://database.clamav.net/"
$trendmicro_page_url = "http://downloadcenter.trendmicro.com/index.php?clk=tab_pattern&clkval=5&regs=NABU&lang_loc=1"
$trendmicro_file_path = "http://www.trendmicro.com/ftp/products/aupattern/ent95_cpr/lpt394.zip"
$files_downloaded = 0
"Starting Download $(Get-Date)" >> $download_folder\download_history.log
# Test for download folder and create if doesn't exist
If (-Not (Test-Path "$download_folder")) {
echo "creating $download_folder " >> $download_folder\download_history.log
New-Item $download_folder -type directory
} Else {
echo "$download_folder already exists" >> $download_folder\download_history.log
}
# DOWNLOAD McAfee STUFF
# Check URL for download links, this is where you put the regex to find specific filenames
#REGEX for xdat, dat.zip
$mcafee_filename_list = Split-Path -Leaf ((Invoke-WebRequest -UseBasicParsing -Uri $mcafee_page_url).Links.Href | Where-Object {$_ -match "(^\d*xdat.exe$|^avvepo\d*dat.zip$)"})
foreach ($file in $mcafee_filename_list) {
If (Test-Path "$download_folder\$file") {
echo "$download_folder\$file already exists" >> $download_folder\download_history.log
} Else {
echo "Downloading $mcafee_file_path$file to $download_folder\$file" >> $download_folder\download_history.log
Invoke-WebRequest -Uri ($mcafee_file_path+$file) -UseBasicParsing -OutFile "$download_folder\$file"
#(New-Object System.Net.WebClient).DownloadFile(($mcafee_file_path+$file),"$download_folder\$file")
#Start-BitsTransfer -Source $mcafee_file_path$file -Destination $download_folder\$file -DisplayName $file -Priority Normal -RetryInterval 600 -RetryTimeout 86400 -Asynchronous
$files_downloaded += 1
}
}
# DOWNLOAD CLAMAV STUFF
# Check URL for download links, this is where you put the regex to find specific filenames
#REGEX for xdat, dat.zip
$clam_av_filename_list = Split-Path -Leaf ((Invoke-WebRequest -UseBasicParsing -Uri $clamav_page_url).Links.Href | Where-Object {$_ -match "([^/]+\.cvd$)"})
foreach ($file in $clam_av_filename_list) {
If (Test-Path "$download_folder\$file") {
echo "$download_folder\$file already exists" >> $download_folder\download_history.log
} Else {
echo "Downloading $clamav_file_path$file to $download_folder\$file" >> $download_folder\download_history.log
Invoke-WebRequest -Uri ($clamav_file_path+$file) -UseBasicParsing -OutFile "$download_folder\$file"
#(New-Object System.Net.WebClient).DownloadFile(($clamav_file_path+$file),"$download_folder\$file")
#Start-BitsTransfer -Source $clamav_file_path$file -Destination $download_folder\$file -DisplayName $file -Priority Normal -RetryInterval 600 -RetryTimeout 86400 -Asynchronous
$files_downloaded += 1
}
}
# DOWNLOAD Trendmicro STUFF
# Check URL for download links, this is where you put the regex to find specific filenames
#REGEX for xdat, dat.zip
$trendmicro_filename_list = Split-Path -Leaf ((Invoke-WebRequest -UseBasicParsing -Uri $trendmicro_page_url).Links.Href | Where-Object {$_ -match "(^lpt\d*.zip$)"})
foreach ($file in $mcafee_filename_list) {
If (Test-Path "$download_folder\$file") {
echo "$download_folder\$file already exists" >> $download_folder\download_history.log
} Else {
echo "Downloading $mcafee_file_path$file to $download_folder\$file" >> $download_folder\download_history.log
Invoke-WebRequest -Uri ($mcafee_file_path+$file) -UseBasicParsing -OutFile "$download_folder\$file"
#(New-Object System.Net.WebClient).DownloadFile(($mcafee_file_path+$file),"$download_folder\$file")
#Start-BitsTransfer -Source $mcafee_file_path$file -Destination $download_folder\$file -DisplayName $file -Priority Normal -RetryInterval 600 -RetryTimeout 86400 -Asynchronous
$files_downloaded += 1
}
}
"$files_downloaded Files Downloaded, Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)" >> $download_folder\download_history.log
@Melvile
Copy link

Melvile commented Jan 9, 2020

Shouldn't the logic to check whether the download folder exists come after the alert that downloads are starting. It will throw an error if the download directory doesn't exist yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment