Functions/Clear-Logs.ps1

function Clear-Logs {
    <#
    .SYNOPSIS
        Clear Windows Logs.
    .DESCRIPTION
        It clears all the logs (Event Viewer Logs) on your current computer. It uses the cmdlet "Get-WinEvent" to realize the cleaning.
        Some logs cannot be cleaned up because they are linked to the system or locked for other reasons.
    .EXAMPLE
        Clear-Logs
    .NOTES
        It must be run as admin to allow to delete logs.
    #>


    [CmdletBinding()]
    Param()

    $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")

    if ($isAdmin -ne $true) {
        Write-Output "Please run this script with admin privileges."
        Break
    }
    else {
        # Clear all the event logs on your computer.
        Write-Output "Clearing logs in progress... Please be patient!"
        Get-WinEvent -ListLog * -Force | Where-Object { Wevtutil.exe Clear-Log $_.LogName } | Out-Null
        Write-Output "Clearing logs done. Thanks for your patience."
    }
}