Skip to content

Commit

Permalink
updated forensic script to have condition based run and include conne…
Browse files Browse the repository at this point in the history
…x,data and monitor logs
  • Loading branch information
Naveen Angali authored and Naveen Angali committed Aug 20, 2024
1 parent bde4f3b commit 8f98fd0
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions Azure-ARM/forensics_log_pull.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
# Strings to look for
$regvars = @("ause-pc-profisee-", "cae-pc-profisee-", "cus-pc-profisee-", "neu-pc-profisee-", "ukw-pc-profisee-", "wcus-pc-profisee-", "wus-pc-profisee-")

# Function to check if the SQL Server starts with any of the specified values
function Check-region {
param (
[string]$SqlServer
)

# Check if the SQL Server starts with any of the values
foreach ($regvar in $regvars) {
if ($SqlServer.StartsWith($regvar)) {
Write-Host "Condition met: Terminating script execution."
exit
}
}

Write-Host "Condition not met: Continuing script execution."
}

# Call the function with the variable
Check-region -SqlServer $env:ProfiseeSqlServer

# Rest of the script
Write-Host "Executing the rest of the script..."

New-Item -Path "C:\Fileshare\" -Name "alllogs" -ItemType "directory" -ErrorAction Ignore
# Pull Product Services, IIS, Event Viewer logs as well as Netstat and TCPConnection logs
$DT = get-date -UFormat "%m-%d-%Y-%H%M%S-UTC-%a"
mkdir "$env:TEMP\all-Logs\$DT\ProfiseeLogs\Config"
$DT = get-date -UFormat "%m-%d-%Y-%H%M%S-UTC-%a"
mkdir "$env:TEMP\all-Logs\$DT\ProfiseeLogs\Config"
mkdir "$env:TEMP\all-Logs\$DT\ProfiseeLogs\Gateway"
mkdir "$env:TEMP\all-Logs\$DT\ProfiseeLogs\Attachments"
mkdir "$env:TEMP\all-Logs\$DT\ProfiseeLogs\Auth"
Expand Down Expand Up @@ -37,7 +64,7 @@ $WebAppName = $env:ProfiseeWebAppName.substring(0, 1).ToUpper() + $env:ProfiseeW

# Compress and copy to fileshare
compress-archive -Path "$env:TEMP\all-Logs\$DT\" -DestinationPath "$env:TEMP\$WebAppName-All-Logs-$DT.zip"
copy "$env:TEMP\$WebAppName-All-Logs-$DT.zip" "C:\fileshare\"
copy "$env:TEMP\$WebAppName-All-Logs-$DT.zip" "C:\fileshare\alllogs"

# Delete older zipped log files more than 30 days
Get-ChildItem -Path C:\Fileshare\* -Include *all-logs-*.zip -Recurse | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} | Remove-Item

0 comments on commit 8f98fd0

Please sign in to comment.