FILE: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\Clamscan\clamscan.psm1
--
Function HG-ClamScan {
<#
.SYNOPSIS
This cmdlet will scan the specified directory using ClamAV.
.PARAMETER Path
Accepts a string input. Also, it can be piped in as string or property.
.EXAMPLE
HG-ClamScan D:\Inetpub\vhosts\pleskdemo.com\httpdocs\
#>
[CmdletBinding()]
param([Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[string]$path = $_)
BEGIN {}
PROCESS {
$DefsLocal = 'C:\Scripts\ClamAV\ClamavDefs'
If (!(Test-Path $DefsLocal)){new-item $DefsLocal -ItemType Directory | Out-Null}
Set-Alias CLAM -Value 'C:\Scripts\ClamAV\clamscan.exe'
$url = "http://internal.win.hostgator.com/clamav/filelist.txt"
$filelist = "c:\scripts\clamav\filelist.txt"
$oldfilelist = "c:\scripts\clamav\oldfilelist.txt"
Remove-item $oldfilelist -force -ea SilentlyContinue
Rename-Item $filelist oldfilelist.txt -force -ea SilentlyContinue
Try {
(New-Object System.Net.WebClient).DownloadFile($url, $filelist)
}catch{
Throw "Unable to download $url"
}
$newfiles = Get-Content $filelist | ConvertFrom-Csv
If (Test-Path $oldfilelist){$oldfiles = Get-Content $oldfilelist | ConvertFrom-Csv}
for ($i=0; $i -le $newfiles.Count; $i++){
If (!(Test-Path $DefsLocal\$($newfiles[$i].name)) -or (($oldfiles | ?{$_.name -eq $($newfiles[$i].name)}).LastWriteTime -ne $newfiles[$i].LastWriteTime)){
$url = "http://internal.win.hostgator.com/clamav/$($newfiles[$i].name)"
$output = "$DefsLocal\$($newfiles[$i].name)"
Write-Host "Downloading updated $($newfiles[$i].name)"
Try {
(New-Object System.Net.WebClient).DownloadFile($url, $output)
}catch{
Throw "Unable to download $url"
}
}
}
Write-Host "`nStarting Clam Scan of $Path `n"
$return = CLAM $path -d $DefsLocal -r -i
$return
}
END {}
}
Set-Alias -Name EIG-ClamScan -Value HG-ClamScan
--