Created
February 14, 2018 22:42
-
-
Save levi-turner/31853325fda7f249821eceac936c79e0 to your computer and use it in GitHub Desktop.
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
| #-------------------------------------------------------------------------------------------------------------------------------- | |
| # | |
| # Script Name: qlik_sense_log_scrape.ps1 | |
| # Description: get Sense + Windows logs for a given date | |
| # Dependency: N/A | |
| # | |
| # Version Date Author Change Notes | |
| # 0.1 2018-02-14 Levi Turner Initial Version | |
| # | |
| #-------------------------------------------------------------------------------------------------------------------------------- | |
| # Temp Path Sanity check | |
| Set-Location -path C:\ | |
| if (Test-Path C:\temp\) { | |
| Write-Output "Temp Directory Exists" | |
| } else { | |
| mkdir Temp | |
| } | |
| # Create a date folder | |
| $date = Get-Date | |
| $date = $date.GetDateTimeFormats()[6] | |
| Set-Location -Path C:\Temp | |
| if (Test-Path C:\temp\$($date)) { | |
| Write-Output "Temp Directory Exists" | |
| } else { | |
| mkdir $($date) | |
| } | |
| Set-Location -Path C:\temp\$($date) | |
| # Copy Windows Logs | |
| Copy-Item -Path C:\Windows\System32\winevt\Logs\Application.evtx -Destination C:\temp\$($date)\Application.evtx | |
| Copy-Item -Path C:\Windows\System32\winevt\Logs\Application.evtx -Destination C:\temp\$($date)\System.evtx | |
| # Copy Active Logs | |
| # Line 33 will grab the last 2 days, adjust downward as needed | |
| $RemotePath = "C:\ProgramData\Qlik\Sense\Log" | |
| $LocalPath = "C:\temp\$($date)" | |
| $Max_days = "-2" | |
| $Curr_date = get-date | |
| #Checking date and then copying file from RemotePath to LocalPath | |
| Foreach($file in (Get-ChildItem $RemotePath -Recurse -Include *.txt, *.log)) | |
| { | |
| if($file.LastWriteTime -gt ($Curr_date).adddays($Max_days)) | |
| { | |
| Copy-Item -Path $file.fullname -Destination $LocalPath | |
| #Move-Item -Path $file.fullname -Destination $LocalPath | |
| } | |
| ELSE | |
| {} | |
| } | |
| # Doing the same for the Share path | |
| # Adjust RemotePath as needed | |
| $RemotePath = "C:\Share" | |
| $LocalPath = "C:\temp\$($date)" | |
| $Max_days = "-2" | |
| $Curr_date = get-date | |
| Foreach($file in (Get-ChildItem $RemotePath -Recurse -Include *.txt, *.log)) | |
| { | |
| if($file.LastWriteTime -gt ($Curr_date).adddays($Max_days)) | |
| { | |
| Copy-Item -Path $file.fullname -Destination $LocalPath | |
| #Move-Item -Path $file.fullname -Destination $LocalPath | |
| } | |
| ELSE | |
| {} | |
| } | |
| # Zip the folder | |
| $source = "C:\temp\$($date)" | |
| $destination = "C:\temp\$($date).zip" | |
| If(Test-path $destination) {Remove-item $destination} | |
| Add-Type -assembly "system.io.compression.filesystem" | |
| [io.compression.zipfile]::CreateFromDirectory($Source, $destination) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment