Created
July 19, 2016 17:48
-
-
Save jpbruckler/a5abd9017f1c02d88d42fbcb8f43e6d9 to your computer and use it in GitHub Desktop.
Because I'm too lazy to keep downloading EICAR files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function New-EicarFile | |
{ | |
<# | |
.SYNOPSIS | |
Creates an EICAR file. | |
.DESCRIPTION | |
Will generate a file with the EICAR antimalware test string at the given path. | |
.PARAMETER Path | |
The full path of the file to create. | |
.PARAMETER Force | |
If the file exists, Force will attempt to overwrite it. | |
.INPUTS None | |
.OUTPUTS File | |
.LINK http://www.eicar.org/86-0-Intended-use.html | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter( Mandatory, | |
Position = 0)] | |
[string] $Path, | |
[switch] $Force | |
) | |
begin { | |
Write-Verbose 'Initializing integer array.' | |
$IntArray = @( 88,53,79,33,80,37,64,65,80,91,52,92,80,90,88,53,52, | |
40,80,94,41,55,67,67,41,55,125,36,69,73,67,65,82,45, | |
83,84,65,78,68,65,82,68,45,65,78,84,73,86,73,82,85, | |
83,45,84,69,83,84,45,70,73,76,69,33,36,72,43,72,42 | |
) | |
$StringBuilder = New-Object System.Text.StringBuilder | |
} | |
process { | |
foreach ($int in $IntArray) { | |
$char = [char] $int | |
Write-Verbose ('Adding character {0} (int: {1}) to string.' -f $char,$int) | |
$null = $StringBuilder.Append($char) | |
} | |
if (Test-Path $Path -ErrorAction SilentlyContinue) { | |
if ($Force) { | |
Write-Verbose ('Writing string to file: {0}' -f $Path) | |
$StringBuilder.ToString() | Out-File -FilePath $Path -Force | |
} | |
else { | |
Write-Error ('Unable to write file {0} because it already exists. Try another file name, or using the -Force parameter.' -f $Path) | |
} | |
} | |
else { | |
Write-Verbose ('Writing string to file: {0}' -f $Path) | |
$StringBuilder.ToString() | Out-File -FilePath $Path -Force | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment