Last active
May 28, 2019 01:29
-
-
Save mastry/37cb6c315d9daf3db76939b3e2785b03 to your computer and use it in GitHub Desktop.
Retrieves the most recent IIS log file from a list of servers. Assumes the logs are in the default location (change first line of PROCESS section if needed).
This file contains 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
[CmdletBinding()] | |
Param( | |
[Parameter(Position=0, ValueFromPipeline = $true, Mandatory = $true)] | |
[string[]] $ComputerName, | |
[switch] $Compress | |
) | |
BEGIN { | |
$targetFileList = @() | |
$tempFolder = [guid]::NewGuid().ToString() | |
$basePath = (pwd).Path | |
$tempFolder = "$($basePath)\$tempFolder" | |
mkdir $tempFolder | |
} | |
PROCESS{ | |
$files = dir "\\$($ComputerName)\C$\inetpub\logs\LogFiles\W3SVC3" | |
$targetFile = ($files | Sort-Object -Property "LastWriteTime" -Descending)[0] | |
$targetFile.CopyTo("$($tempFolder)\$($ComputerName)_$($targetFile.Name)") | |
$targetFileList += $targetFile | |
} | |
END{ | |
if( $Compress.IsPresent ) { | |
Add-Type -AssemblyName "System.IO.Compression.FileSystem" | |
[System.IO.Compression.ZipFile]::CreateFromDirectory("$($tempFolder)","$($tempFolder).zip") | |
del "$($tempFolder)\*.*" | |
rmdir $tempFolder | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment