Get-EventLogs.ps1
19 Sep 2025Description
Purpose
Retrieves event logs from a specified computer.
Detailed Description
The Get-EventLogs function retrieves event logs from a specified computer. It uses the Get-WinEvent cmdlet to retrieve the logs and returns the log information as a collection of custom objects.
Usage
Example 1
Get-EventLogs -ComputerName "Server01" -LogName "Application"
Retrieves the “Application” event log from the “Server01” computer.
Example 2
Get-EventLogs -ComputerName "Server02"
Retrieves all event logs from the “Server02” computer.
Notes
No additional notes.
Script
<#
.SYNOPSIS
Retrieves event logs from a specified computer.
.DESCRIPTION
The Get-EventLogs function retrieves event logs from a specified computer. It uses the Get-WinEvent cmdlet to retrieve the logs and returns the log information as a collection of custom objects.
.PARAMETER ComputerName
The name of the computer from which to retrieve the event logs.
.PARAMETER LogName
The name of the event log to retrieve. By default, all event logs are retrieved.
.EXAMPLE
Get-EventLogs -ComputerName "Server01" -LogName "Application"
Retrieves the "Application" event log from the "Server01" computer.
.EXAMPLE
Get-EventLogs -ComputerName "Server02"
Retrieves all event logs from the "Server02" computer.
#>
function Get-EventLogs {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$ComputerName,
[Parameter(Mandatory = $false)]
[string]$LogName = '*'
)
try {
$logs = Get-WinEvent -ComputerName $ComputerName -ListLog $LogName -ErrorAction Stop
$logs | ForEach-Object {
[PSCustomObject]@{
LogName = $_.LogName
LogType = $_.LogType
LogIsolation = $_.LogIsolation
IsEnabled = $_.IsEnabled
IsClassicLog = $_.IsClassicLog
LogFilePath = $_.LogFilePath
LogMode = $_.LogMode
MaximumSizeInBytes = $_.MaximumSizeInBytes
RecordCount = $_.RecordCount
OldestRecordNumber = $_.OldestRecordNumber
ProviderNames = $_.ProviderNames
}
}
}
catch {
Write-Output $_.Exception.Message
}
}
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.