Skip to content

Instantly share code, notes, and snippets.

@mark05e
Last active August 30, 2019 03:38
Show Gist options
  • Save mark05e/73f534fe6ea9989dc347745f28c0f7d7 to your computer and use it in GitHub Desktop.
Save mark05e/73f534fe6ea9989dc347745f28c0f7d7 to your computer and use it in GitHub Desktop.
A crude log collection script in powershell
#ref: https://stackoverflow.com/a/9587943/2854578
$sourceDir = "C:\Users\mark\AppData\"
$targetDir = "E:\temp2\temptest\"
$includefiletype = @("*.log*", "*.log")
$startDateTime = "2019-08-29 8:18:00 PM"
$endDateTime = "2019-08-29 8:20:00 PM"
Get-ChildItem -Path $sourceDir -Include $includefiletype -Recurse |
Where-Object { $_.LastWriteTime -ge $startDateTime -and $_.LastWriteTime -le $endDateTime} |
ForEach {
$targetFile = $targetDir + $_.FullName.Substring($sourceDir.Length);
New-Item -ItemType Directory -Path $targetFile -Force
Copy-item $_.FullName -destination $targetfile -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment