How to send a file to ICAP server for testing the functionalities using the powershell script?

Check Your Version:

This article applies to all MetaDefender ICAP Server releases deployed on Windows systems.

The script shown below is made to specifically work with text files only (using the .txt format). Using different files formats will result in the script failing.

Create a powershell script with the content below and save it as icap_win.ps1

param (
[string]$icapServer = "127.0.0.1", #ICAP server IP
[int]$icapPort ="1344", # ICAP default port
[string]$icapService = "/OMSScanReq-AV", # ICAP service name
[string]$filePath = "" # Path to the file
)

# Read file content
$fileContent = [System.IO.File]::ReadAllBytes($filePath)
$fileSize = $fileContent.Length
$chunkSize = [Convert]::ToString($fileSize, 16) # Convert size to hexadecimal

# Define ICAP Headers
$icapRequest = "REQMOD icap://$icapServer`:$icapPort$icapService ICAP/1.0`r`n"
$icapRequest += "Host: $icapServer`r`n"
$icapRequest += "User-Agent: PowerShell-ICAP-Client`r`n"
$icapRequest += "Encapsulated: req-hdr=0, req-body=" + ($fileSize + 4) + "`r`n`r`n"

# Define HTTP Encapsulation (Required by ICAP)

Execute the script following the command

.\icap_win.ps1 -icapServer <ICAP Server IP> -icapPort <ICAP Port> -filePath <Path to test file>

Example:

.\icap_win.ps1 -icapServer "127.0.0.1" -icapPort 1344 -filePath "D:\eicar.txt"
Support:

If Further Assistance is required, please proceed to log a support case or chatting with our support engineer.