-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOPSWAT-ScanFile.ps1
More file actions
75 lines (68 loc) · 3.52 KB
/
Copy pathOPSWAT-ScanFile.ps1
File metadata and controls
75 lines (68 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#Discription: Script to Scan files over OPSWat using Metdefender API and display results of scan
#Auther: MD
function OPSWATScanFile
{
param(
[string]$site,
[string]$FolderPathForScan
)
Try
{
if (Test-path $FolderPathForScan)
{
$FilesPathInFolder=Get-ChildItem -Recurse "$FolderPathForScan" | Where { ! $_.PSIsContainer }
foreach($FileInfo in $FilesPathInFolder)
{
Write-Host $('-' * 50)
write-host "Uploading File: $FileInfo over Metadefender using API for Scan"
$FilePath=$FileInfo.FullName
$FileName=$FileInfo.Name
$uri = "$site/file"
$ProgressPreference = 'SilentlyContinue'
$response = Invoke-RestMethod -Uri $uri -Method Post -InFile $FilePath -UseDefaultCredentials
$response = $response -Replace "@{data_id=","" -Replace "}",""
$resultURI = "$uri/$response"
$resultResponse = Invoke-RestMethod -Uri $resultURI -Method Get -UseDefaultCredentials | ConvertTo-Json | Format-Json
if ($resultResponse -clike '*Processing*')
{
write-host "Processing..."
DO
{
Start-Sleep -s 3
$resultResponse = Invoke-RestMethod -Uri $resultURI -Method Get -UseDefaultCredentials | ConvertTo-Json | Format-Json
} while ($resultResponse -clike '*Processing*')
}
if($FullDetails)
{
write-host $resultResponse
}
Else
{
$resultResponse = $resultResponse | ConvertFrom-Json
if (!$resultResponse.process_info.blocked_reason)
{
write-host " File:" $FileName `n " Data ID:" $resultResponse.data_id `n "Profile:" $resultResponse.process_info.profile `n "Result:" $resultResponse.process_info.result `n "Process time:" $resultResponse.process_info.processing_time -ForegroundColor Green
write-host `n
continue
}
Else
{
write-host " File:" $FileName `n "Data ID:" $resultResponse.data_id `n "Profile:" $resultResponse.process_info.profile `n "Result:" $resultResponse.process_info.result `n "Process time:" $resultResponse.process_info.processing_time -ForegroundColor Red
write-host `n "Blocked Reason:" $resultResponse.process_info.blocked_reason -ForegroundColor Red
}
}
}
}
Else
{
Write-Host "Provide Folder Path DoesNot Exist: $FolderPathForScan" -ForegroundColor Red
}
}
catch
{
$ErrorMessage = $_.Exception.Message
Write-Host "ERROR: $ErrorMessage" -ForegroundColor Red
Break
}
}
OPSWATScanFile -site "https://MDCore.site.com" -FolderPathForScan "C:\FileToScan"