Clear-EventLogRemote
Windows: Clears all entries from specified event logs
#Requires -Version 5.1
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string[]]$LogName,
[string]$ComputerName = $env:COMPUTERNAME,
[pscredential]$Credential
)
Process
{
try
{
$clearParams = @{
'LogName' = $LogName
'ComputerName' = $ComputerName
'Confirm' = $false
'ErrorAction' = 'Stop'
}
if ($null -ne $Credential)
{
$clearParams.Add('Credential', $Credential)
}
Write-Verbose "Clearing event log(s): $($LogName -join ', ') on '$ComputerName'..."
Clear-EventLog @clearParams
$result = [PSCustomObject]@{
LogNames = $LogName
ComputerName = $ComputerName
Action = "Cleared"
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
Write-Output $result
}
catch
{
throw
}
}Specifies the name of the event log to clear (e.g., "Application", "System").
Specifies the name of the target computer. Defaults to the local computer.
Specifies a PSCredential object for remote connection.