Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download Sysmon.exe from https://live.sysinternals.com
function DownloadSysmon {
[cmdletbinding()]
Param()
$Result = $(Test-Path (Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath sysmon.exe));
if(-not $Result) {
try {
# https://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename%28v=vs.110%29.aspx
$tmpfile = [System.IO.Path]::GetTempFileName()
$null = Invoke-WebRequest -Uri 'https://live.sysinternals.com/Sysmon.exe' `
-OutFile $tmpfile -ErrorAction Stop
Write-Verbose 'Sucessfully downloaded Sysmon.exe'
Unblock-File -Path $tmpfile -ErrorAction Stop
$exefile = Join-Path -Path (Split-Path -Path $tmpfile -Parent) -ChildPath 'a.exe'
if (Test-Path $exefile) {
Remove-Item -Path $exefile -Force -ErrorAction Stop
}
$tmpfile | Rename-Item -NewName 'a.exe' -Force -ErrorAction Stop
} catch {
Write-Verbose "Something went wrong $($_.Exception.Message)"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment