Skip to content

Commit d795f20

Browse files
author
Blake Drumm
authored
Update Get-EventLogs.ps1
Added -Logs switch. We can now select which event logs we want to gather when executing.
1 parent 815ac28 commit d795f20

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

Powershell/Get-EventLogs.ps1

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
Get-EventLogs
44
55
.DESCRIPTION
6-
This Script Collects Event Log data from Remote Servers and the Local Machine if defined. It will collect all of these and finally zip the files up into a easy to transport zip file.
6+
This Script Collects Event Log data from Remote Servers and the Local Machine if defined. It will collect all of these and finally zip the files up into a easy to transport zip file.
77
If you need to collect more logs than just Application, System, and Operations Manager. Please change line 35 [String[]]$Logs.
88
99
.PARAMETER Servers
1010
Add DNS Hostnames you would like to retrieve the Event Logs from like this: Agent1.contoso.com, Agent2.contoso.com
1111
12+
.PARAMETER Logs
13+
Gather specific Event Logs from Remote or Local Machine.
14+
1215
.PARAMETER CaseNumber
1316
A description of the CaseNumber parameter.
1417
1518
.EXAMPLE
16-
PS C:\> .\Get-EventLogs.ps1 -Servers Agent1.contoso.com, Agent2.contoso.com
19+
PS C:\> .\Get-EventLogs.ps1 -Servers Agent1.contoso.com, Agent2.contoso.com -Logs Application, System
1720
1821
.NOTES
1922
Additional information about the file.
@@ -26,13 +29,19 @@ param
2629
[String[]]$Servers,
2730
[Parameter(Mandatory = $false,
2831
Position = 2)]
32+
[String[]]$Logs,
33+
[Parameter(Mandatory = $false,
34+
Position = 3)]
2935
[string]$CaseNumber
3036
)
3137
# --------------------------------------------------------------------
3238
# --------------------------------------------------------------------
3339

3440
#Modify this if you need more logs
35-
[String[]]$Logs = 'Application', 'System', 'Security', 'Operations Manager', 'Microsoft-Windows-PowerShell/Operational'
41+
if ($Logs -eq $null)
42+
{
43+
[String[]]$Logs = 'Application', 'System', 'Security', 'Operations Manager', 'Microsoft-Windows-PowerShell/Operational'
44+
}
3645

3746
$DefinedServers = $null
3847

@@ -82,9 +91,9 @@ function Get-EventLogs
8291
{
8392
Time-Stamp
8493
Write-Host "Output folder not found." -ForegroundColor Gray
85-
Time-Stamp
86-
Write-Host "Creating folder: " -ForegroundColor DarkYellow -NoNewline
87-
Write-Host "$OutputPath" -ForegroundColor DarkCyan
94+
Time-Stamp
95+
Write-Host "Creating folder: " -ForegroundColor DarkYellow -NoNewline
96+
Write-Host "$OutputPath" -ForegroundColor DarkCyan
8897
md $OutputPath | Out-Null
8998
}
9099
if ($servers)
@@ -109,9 +118,9 @@ function Get-EventLogs
109118
{
110119
try
111120
{
112-
if($log -like '*/*')
113-
{$logname = $log.split('/')[0]}
114-
else{$logname = $log}
121+
if ($log -like '*/*')
122+
{ $logname = $log.split('/')[0] }
123+
else { $logname = $log }
115124
Invoke-Command -ComputerName $server {
116125
$fileCheck = test-path "c:\windows\Temp\$using:server`.$using:logname.evtx"
117126
if ($fileCheck -eq $true)
@@ -126,7 +135,7 @@ function Get-EventLogs
126135
{
127136
New-Item -ItemType directory -Path "$OutputPath" -Name "$server" -ErrorAction Stop | Out-Null
128137
New-Item -ItemType directory -Path "$OutputPath\$server" -Name "localemetadata" -ErrorAction Stop | Out-Null
129-
}
138+
}
130139
Move-Item "\\$server\c$\windows\temp\$server.$logname.evtx" "$OutputPath\$server" -force -ErrorAction Stop
131140
#"Get-ChildItem \\$server\c$\windows\temp\localemetadata\"
132141
Get-ChildItem "\\$server\c$\windows\temp\localemetadata\" -ErrorAction Stop |
@@ -143,9 +152,9 @@ function Get-EventLogs
143152
}
144153
else
145154
{
146-
if($log -like '*/*')
147-
{$logname = $log.split('/')[0]}
148-
else{$logname = $log}
155+
if ($log -like '*/*')
156+
{ $logname = $log.split('/')[0] }
157+
else { $logname = $log }
149158
$fileCheck = test-path "c:\windows\Temp\$server.$logname.evtx"
150159
if ($fileCheck -eq $true)
151160
{

0 commit comments

Comments
 (0)