Tag Archives: LogName

Write-EventLog

NAME
    Write-EventLog

SYNOPSIS
    Writes an event to an event log.

SYNTAX
    Write-EventLog [-LogName] <string> [-Source] <string> [-EventId] <int> [-Message] <string> [[-EntryType] {Error | Warning | Information | SuccessAudit | FailureAudit}] [-Category <Int16>] [-ComputerName <string>] [-RawData <Byte[]>] [<CommonParameters>]

DESCRIPTION
    The Write-EventLog cmdlet writes an event to an event log.

    To write an event to an event log, the event log must exist on the computer and the source must be registered for the event log.

    The cmdlets that contain the EventLog noun (the EventLog cmdlets) work only on classic event logs. To get events from logs that use the Windows Event Log technology in Windows Vista and later versions of Windows, use Get-WinEvent.

PARAMETERS
    -Category <Int16>
        Specifies a task category for the event. Enter an integer that is associated with the strings in the category message file for the event log.

        Required?                    false
        Position?                    named
        Default value                1
        Accept pipeline input?     false
        Accept wildcard characters? false

    -ComputerName <string>
        Specifies a remote computer. The default is the local computer.

        Type the NetBIOS name, an Internet Protocol (IP) address, or a fully qualified domain name of a remote computer.

        This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-EventLog even if your computer is not configured to run remote commands.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -EntryType <EventLogEntryType>
        Specifies the entry type of the event. Valid values are Error, Warning, Information, SuccessAudit, and FailureAudit. The default value is Information.

        For a description of the values, see System.Diagnostics.EventLogEntryType in the MSDN (Microsoft Developer Network) library at http://go.microsoft.com/fwlink/?LinkId=143599.

        Required?                    false
        Position?                    4
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -EventId <int>
        Specifies the event identifier. This parameter is required.

        Required?                    true
        Position?                    3
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -LogName <string>
        Specifies the name of the log to which the event is written. Enter the log name (the value of the Log property, not the LogDisplayName). Wildcard characters are not permitted. This parameter is required.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Message <string>
        Specifies the event message. This parameter is required.

        Required?                    true
        Position?                    5
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -RawData <Byte[]>
        Specifies the binary data that is associated with the event, in bytes.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Source <string>
        Specifies the event source, which is typically the name of the application that is writing the event to the log.

        Required?                    true
        Position?                    2
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe input to this cmdlet.

OUTPUTS
    System.Diagnostics.EventLogEntry
        Write-EventLog returns objects that represents the events in the logs.

NOTES

        To use Write-EventLog on Windows Vista and later versions of Windows, start Windows PowerShell with the “Run as administrator” option.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Write-EventLog -LogName Application -Source MyApp -EventId 3001 -EntryType Information -Message “MyApp added a user-requested feature to the display.” -Category 1 -RawData 10,20

    Description
    ———–
    This command writes an event from the MyApp source to the Application event log.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Write-EventLog -ComputerName Server01 -LogName Application -Source MyApp -EventId 3001 -Message “MyApp added a user-requested feature to the display.”

    Description
    ———–
    This command writes an event from the MyApp source to the Application event log on the Server01 remote computer.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135281
    Clear-EventLog
    Get-EventLog
    Limit-EventLog
    New-EventLog
    Remove-EventLog
    Show-EventLog
    Write-EventLog
    Get-WinEvent

Remove-EventLog

NAME
    Remove-EventLog

SYNOPSIS
    Deletes an event log or unregisters an event source.

SYNTAX
    Remove-EventLog [-LogName] <string[]> [[-ComputerName] <string[]>] [-Confirm] [-WhatIf] [<CommonParameters>]

    Remove-EventLog [[-ComputerName] <string[]>] [-Source <string[]>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Remove-EventLog cmdlet deletes an event log file from a local or remote computer and unregisters all of its event sources for the log. You can also use this cmdlet to unregister event sources without deleting any event logs.

    The cmdlets that contain the EventLog noun (the EventLog cmdlets) work only on classic event logs. To get events from logs that use the Windows Event Log technology in Windows Vista and later versions of Windows, use Get-WinEvent.

PARAMETERS
    -ComputerName <string[]>
        Specifies a remote computer. The default is the local computer.

        Type the NetBIOS name, an Internet Protocol (IP) address, or a fully qualified domain name of a remote computer. To specify the local computer, type the computer name, a dot (.), or “localhost”.

        This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Remove-EventLog even if your computer is not configured to run remote commands.

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -LogName <string[]>
        Specifies the event logs. Enter the log name (the value of the Log property; not the LogDisplayName) of one or more event logs , separated by commas. Wildcard characters are not permitted. This parameter is required.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Source <string[]>
        Unregisters the specified event sources. Enter the source names (not the executable name), separated by commas.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe input to this cmdlet.

OUTPUTS
    None
        This cmdlet does not return any output.

NOTES

        To use Remove-EventLog on Windows Vista and later versions of Windows, start Windows PowerShell with the “Run as administrator” option.

        If you remove an event log and then re-create the log, you will not be able to register the same event sources. Applications that used the events sources to write entries to the original log will not be able to write to the new log.

        When you unregister an event source for a particular log, the event source might be prevented from writing entries in other event logs.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Remove-Eventlog -LogName MyLog

    Description
    ———–
    This command deletes the MyLog event log from the local computer and unregisters its event sources.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Remove-Eventlog -LogName MyLog, TestLog -ComputerName Server01, Server02, localhost

    Description
    ———–
    This command deletes the MyLog and TestLog event logs from the local computer (“localhost”) and the Server01 and Server02 remote computers. The command also unregisters the event sources for these logs.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Remove-Eventlog -source MyApp

    Description
    ———–
    This command deletes the MyApp event source from the logs on the local computer. When the command completes, the MyApp program cannot write to any event logs.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Get-Eventlog -list

     Max(K) Retain OverflowAction        Entries Log
     —— —— ————–        ——- —
     15,168     0 OverwriteAsNeeded     22,923 Application
     15,168     0 OverwriteAsNeeded         53 DFS Replication
         512     7 OverwriteOlder             0 Directory Service
     15,168     7 OverwriteOlder             0 Hardware Events
         512     7 OverwriteOlder             0 Internet Explorer
     20,480     0 OverwriteAsNeeded         0 Key Management Service
     30,016     0 OverwriteAsNeeded     50,060 Security
     15,168     0 OverwriteAsNeeded     27,592 System
     15,360     0 OverwriteAsNeeded     18,355 Windows PowerShell
     15,168     7 OverwriteAsNeeded         12 ZapLog

    C:\PS> Remove-Eventlog -LogName ZapLog

    C:\PS> Get-Eventlog -list

     Max(K) Retain OverflowAction        Entries Log
     —— —— ————–        ——- —
     15,168     0 OverwriteAsNeeded     22,923 Application
     15,168     0 OverwriteAsNeeded         53 DFS Replication
         512     7 OverwriteOlder             0 Directory Service
     15,168     7 OverwriteOlder             0 Hardware Events
         512     7 OverwriteOlder             0 Internet Explorer
     20,480     0 OverwriteAsNeeded         0 Key Management Service
     30,016     0 OverwriteAsNeeded     50,060 Security
     15,168     0 OverwriteAsNeeded     27,592 System
     15,360     0 OverwriteAsNeeded     18,355 Windows PowerShell

    Description
    ———–
    These commands show how to list the event logs on a computer and verify that a Remove-EventLog command was successful.

    The first command lists the event logs on the local computer.

    The second command deletes the ZapLog event log.

    The third command lists the event logs again. The ZapLog event log no longer appears in the list.

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-WmiObject win32_nteventlogfile -filter “logfilename=’TestLog'” | foreach {$_.sources}

    MyApp
    TestApp

    C:\PS> Remove-Eventlog -source MyApp

    C:\PS> Get-WmiObject win32_nteventlogfile -filter “logfilename=’TestLog’} | foreach {$_.sources}
    TestApp

    Description
    ———–
    These commands use the Get-WmiObject cmdlet to list the event sources on the local computer. You can these commands to verify the success of a command or to delete an event source.

    The first command gets the event sources of the TestLog event log on the local computer. MyApp is one of the sources.

    The second command uses the Source parameter of Remove-EventLog to delete the MyApp event source.

    The third command is identical to the first. It shows that the MyApp event source was deleted.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135248
    Clear-EventLog
    Get-EventLog
    Limit-EventLog
    New-EventLog
    Remove-EventLog
    Show-EventLog
    Write-EventLog
    Get-WinEvent

Limit-EventLog

NAME
    Limit-EventLog

SYNOPSIS
    Sets the event log properties that limit the size of the event log and the age of its entries.

SYNTAX
    Limit-EventLog [-LogName] <string[]> [-ComputerName <string[]>] [-MaximumSize <Int64>] [-OverflowAction {OverwriteAsNeeded | OverwriteOlder | DoNotOverwrite}] [-RetentionDays <int>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Limit-EventLog cmdlet sets the maximum size of a classic event log, how long each event must be retained, and what happens when the log reaches its maximum size. You can use it to limit the event logs on local or remote computers.

    The cmdlets that contain the EventLog noun (the EventLog cmdlets) work only on classic event logs. To get events from logs that use the Windows Event Log technology in Windows Vista and later versions of Windows, use Get-WinEvent.

PARAMETERS
    -ComputerName <string[]>
        Specifies a remote computer. The default is the local computer.

        Type the NetBIOS name, an Internet Protocol (IP) address, or a fully qualified domain name of a remote computer. To specify the local computer, type the computer name, a dot (.), or “localhost”.

        This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Limit-EventLog even if your computer is not configured to run remote commands.

        Required?                    false
        Position?                    named
        Default value                Local computer
        Accept pipeline input?     false
        Accept wildcard characters? false

    -LogName <string[]>
        Specifies the event logs. Enter the log name (the value of the Log property; not the LogDisplayName) of one or more event logs , separated by commas. Wildcard characters are not permitted. This parameter is required.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -MaximumSize <Int64>
        Specifies the maximum size of the event logs in bytes. Enter a value between 64 kilobytes (KB) and 4 gigabytes (GB). The value must be divisible by 64 KB (65536).

        This parameter specifies the value of the MaximumKilobytes property of the System.Diagnostics.EventLog object that represents a classic event log.

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -OverflowAction <OverflowAction>
        Specifies what happens when the event log reaches its maximum size.

        Valid values are:
        — DoNotOverwrite: Existing entries are retained and new entries are discarded.
        — OverwriteAsNeeded: Each new entry overwrites the oldest entry.
        — OverwriteOlder: New events overwrite events older than the value specified by the MinimumRetentionDays property. If there are no events older than specified by the MinimumRetentionDays property value, new events are discarded.

        This parameter specifies the value of the OverflowAction property of the System.Diagnostics.EventLog object that represents a classic event log.

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -RetentionDays <int>
        Specifies the minimum number of days that an event must remain in the event log.

        This parameter specifies the value of the MinimumRetentionDays property of the System.Diagnostics.EventLog object that represents a classic event log.

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        None

OUTPUTS
    None
        None

NOTES

        To use Limit-EventLog on Windows Vista and later versions of Windows, open Windows PowerShell with the “Run as administrator” option.

        Limit-EventLog changes the properties of the System.Diagnostics.EventLog object that represents a classic event log. To see the current settings of the event log properties, type “Get-Eventlog -list”.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Limit-EventLog -LogName “Windows PowerShell” -MaximumSize 20KB

    Description
    ———–
    This command increases the maximum size of the Windows PowerShell event log on the local computer to 20480 kilobytes (KB) (20 KB).

    ————————– EXAMPLE 2 ————————–

    C:\PS>Limit-EventLog -LogName Security -comp Server01, Server02 -RetentionDays 7

    Description
    ———–
    This command ensures that events in the Security log on the Server01 and Server02 computers are retained for at least 7 days.

    ————————– EXAMPLE 3 ————————–

    C:\PS>$logs = Get-Eventlog -list | foreach {$_.log}

    C:\PS> Limit-EventLog -OverflowAction OverwriteOlder -LogName $logs

    C:\PS> Get-Eventlog -list

    Max(K) Retain OverflowAction     Entries Log
    —— —— ————–     ——- —
    15,168     0 OverwriteOlder     3,412 Application
     512     0 OverwriteOlder         0 DFS Replication
     512     0 OverwriteOlder         17 DxStudio
    10,240     7 OverwriteOlder         0 HardwareEvents
     512     0 OverwriteOlder         0 Internet Explorer
     512     0 OverwriteOlder         0 Key Management Service
    16,384     0 OverwriteOlder         4 ODiag
    16,384     0 OverwriteOlder         389 OSession
                                             Security
    15,168     0 OverwriteOlder     19,360 System
    15,360     0 OverwriteOlder     15,828 Windows PowerShell

    Description
    ———–
    These commands change the overflow action of all event logs on the local computer to “OverwriteOlder”.

    The first command gets the log names of all of the logs on the local computer. The second command sets the overflow action. The third command displays the results.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135227
    Clear-EventLog
    Get-EventLog
    Limit-EventLog
    New-EventLog
    Remove-EventLog
    Show-EventLog
    Write-EventLog
    Get-WinEvent

New-EventLog

NAME
    New-EventLog

SYNOPSIS
    Creates a new event log and a new event source on a local or remote computer.

SYNTAX
    New-EventLog [-LogName] <string> [-Source] <string[]> [[-ComputerName] <string[]>] [-CategoryResourceFile <string>] [-MessageResourceFile <string>] [-ParameterResourceFile <string>] [<CommonParameters>]

DESCRIPTION
    This cmdlet creates a new classic event log on a local or remote computer. It can also register an event source that writes to the new log or to an existing log.

    The cmdlets that contain the EventLog noun (the Event log cmdlets) work only on classic event logs. To get events from logs that use the Windows Event Log technology in Windows Vista and later versions of Windows, use Get-WinEvent.

PARAMETERS
    -CategoryResourceFile <string>
        Specifies the path to the file that contains category strings for the source events. This file is also known as the Category Message File.

        The file must be present on the computer on which the event log is being created. This parameter does not create or move files.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -ComputerName <string[]>
        Creates the new event logs on the specified computers. The default is the local computer.

        Type the NetBIOS name, an Internet Protocol (IP) address, or a fully qualified domain name of a remote computer. To specify the local computer, type the computer name, a dot (.), or “localhost”.

        This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-EventLog even if your computer is not configured to run remote commands.

        Required?                    false
        Position?                    3
        Default value                .
        Accept pipeline input?     false
        Accept wildcard characters? false

    -LogName <string>
        Specifies the name of the event log.

        If the log does not exist, New-EventLog creates the log and uses this value for the Log and LogDisplayName properties of the new event log. If the log exists, New-EventLog registers a new source for the event log.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -MessageResourceFile <string>
        Specifies the path to the file that contains message formatting strings for the source events. This file is also known as the Event Message File.

        The file must be present on the computer on which the event log is being created. This parameter does not create or move files.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -ParameterResourceFile <string>
        Specifies the path to the file that contains strings used for parameter substitutions in event descriptions. This file is also known as the Parameter Message File.

        The file must be present on the computer on which the event log is being created. This parameter does not create or move files.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Source <string[]>
        Specifies the names of the event log sources, such as application programs that write to the event log. This parameter is required.

        Required?                    true
        Position?                    2
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe input to this cmdlet.

OUTPUTS
    System.Diagnostics.EventLogEntry

NOTES

        To use New-EventLog on Windows Vista and later versions of Windows, open Windows PowerShell with the “Run as administrator” option.

        To create an event source in Windows Vista, Windows XP Professional, or Windows Server 2003, you must be a member of the Administrators group on the computer.

        When you create a new event log and a new event source, the system registers the new source for the new log, but the log is not created until the first entry is written to it.

        The operating system stores event logs as files. When you create a new event log, the associated file is stored in the %SystemRoot%\System32\Config directory on the specified computer. The file name is the first eight characters of the Log property with an .evt file name extension.

    ————————– EXAMPLE 1 ————————–

    C:\PS>New-Eventlog -Source TestApp -LogName TestLog -MessageResourceFile C:\Test\TestApp.dll

    Description
    ———–
    This command creates the TestLog event log on the local computer and registers a new source for it.

    ————————– EXAMPLE 2 ————————–

    C:\PS>$file = “C:\Program Files\TestApps\NewTestApp.dll”

    C:\PS> New-Eventlog -ComputerName Server01 -Source NewTestApp -LogName Application -MessageResourceFile $file -CategoryResourceFile $file

    Description
    ———–
    This command adds a new event source, NewTestApp, to the Application log on the Server01 remote computer.

    The command requires that the NewTestApp.dll file is located on the Server01 computer.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135235
    Clear-EventLog
    Get-EventLog
    Limit-EventLog
    New-EventLog
    Remove-EventLog
    Show-EventLog
    Write-EventLog
    Get-WinEvent

Get-WinEvent

NAME
    Get-WinEvent

SYNOPSIS
    Gets events from event logs and event tracing log files on local and remote computers.

SYNTAX
    Get-WinEvent [-LogName] <string[]> [-ComputerName <string>] [-Credential <PSCredential>] [-FilterXPath <string>] [-Force <switch>] [-MaxEvents <int64>] [-Oldest] [<CommonParameters>]

    Get-WinEvent [-Path] <string[]> [-ComputerName <string>] [-Credential <PSCredential>] [-FilterXPath <string>] [-Force <switch>] [-MaxEvents <int64>] [-Oldest] [<CommonParameters>]

    Get-WinEvent [-ProviderName] <string[]> [-ComputerName <string>] [-Credential <PSCredential>] [-FilterXPath <string>] [-Force <switch>] [-MaxEvents <int64>] [-Oldest] [<CommonParameters>]

    Get-WinEvent -FilterHashTable <Hashtable[]> [-ComputerName <string>] [-Credential <PSCredential>] [-Force <switch>] [-MaxEvents <int64>] [-Oldest] [<CommonParameters>]

    Get-WinEvent [-ListLog] <string[]> [-ComputerName <string>] [-Credential <PSCredential>] [<CommonParameters>]

    Get-WinEvent [-ListProvider] <string[]> [-ComputerName <string>] [-Credential <PSCredential>] [<CommonParameters>]

    Get-WinEvent -FilterXml <XmlDocument> [-ComputerName <string>] [-Credential <PSCredential>] [-Force <switch>] [-MaxEvents <int64>] [-Oldest] [<CommonParameters>]

DESCRIPTION
    The Get-WinEvent cmdlet gets events from event logs, including classic logs, such as the System and Application logs, and the event logs that are generated by the new Windows Event Log technology introduced in Windows Vista. It also gets events in log files generated by Event Tracing for Windows (ETW).

    Without parameters, a Get-WinEvent command gets all the events from all the event logs on the computer. To interrupt the command, press CTRL + C.

    Get-WinEvent also lists event logs and event log providers. You can get events from selected logs or from logs generated by selected event providers. And, you can combine events from multiple sources in a single command. Get-WinEvent allows you to filter events by using XPath queries, structured XML queries, and simplified hash-table queries.

    Note: Get-WinEvent requires Windows Vista, Windows Server 2008 R2, or later versions of Windows. And, it requires the Microsoft .NET Framework 3.5 or a later version.

PARAMETERS
    -ComputerName <string>
        Gets events from the event logs on the specified computer. Type the NetBIOS name, an Internet Protocol (IP) address, or the fully qualified domain name of the computer. The default value is the local computer.

        This parameter accepts only one computer name at a time. To find event logs or events on multiple computers, use a ForEach statement. For more information about this parameter, see the examples.

        To get events and event logs from remote computers, the firewall port for the event log service must be configured to allow remote access.

        This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter even if your computer is not configured to run remote commands.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Credential <PSCredential>
        Specifies a user account that has permission to perform this action. The default value is the current user.

        Type a user name, such as User01 or Domain01\User01. Or, enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password. If you type only the parameter name, you will be prompted for both a user name and a password.

        Required?                    false
        Position?                    named
        Default value                Current user
        Accept pipeline input?     false
        Accept wildcard characters? false

    -FilterHashTable <Hashtable[]>
        Uses a query in hash table format to select events from one or more event logs. The query contains a hash table with one or more key-value pairs.

        Hash table queries have the following rules:
        — Keys and values are case-insensitive.
        — Wildcard characters are valid only in the values associated with the LogName and ProviderName keys.
        — Each key can be listed only once in each hash-table.
        — The Path value takes paths to .etl, .evt, and .evtx log files.
        — The LogName, Path, and ProviderName keys can be used in the same query.
        — The UserID key can take a valid security identifier (SID) or a domain account name that can be used to construct a valid System.Security.Principal.NTAccount object.
        — The Data value takes event data in an unnamed field. This is for events in classic event logs.
        — The * key represents a named event data field.
        When Get-WinEvent cannot interpret a key-value pair, it interprets the key as a case-sensitive name for the event data in the event.

        The valid key-value pairs are as follows:
        — LogName=<String[]>
        — ProviderName=<String[]>
        — Path=<String[]>
        — Keywords=<Long[]>
        — ID=<Int32[]>
        — Level=<Int32[]>
        — StartTime=<DateTime>
        — EndTime=<DataTime>
        — UserID=<SID>
        — Data=<String[]>
        — *=<String[]>

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -FilterXml <XmlDocument>
        Uses a structured XML query to select events from one or more event logs.

        To generate a valid XML query, use the Create Custom View and Filter Current Log features in Event Viewer. Use the items in the dialog box to create a query, and then click the XML tab to view the query in XML format. You can copy the XML from the XML tab into the value of the FilterXml parameter. For more information about the Event Viewer features, see Event Viewer Help.

        Typically, you use an XML query to create a complex query that contains several XPath statements. The XML format also allows you to use a “Suppress” XML element that excludes events from the query. For more information about the XML schema for event log queries, see the following topics in the MSDN (Microsoft Developer Network) library.

        — “Query Schema”: http://go.microsoft.com/fwlink/?LinkId=143685

        — “XML Event Queries” in “Event Selection”: http://go.microsoft.com/fwlink/?LinkID=143608

        Required?                    true
        Position?                    named
        Default value                None
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -FilterXPath <string>
        Uses an XPath query to select events from one or more logs.

        For more information about the XPath language, see “Selection Filters” in “Event Selection” and in the “XPath Reference” in the MSDN library.

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Force <switch>
        Gets debug and analytic logs, in addition to other event logs. The Force parameter is required to get a debug or analytic log when the value of the name parameter includes wildcard characters.

        By default, Get-WinEvent excludes these logs unless you specify the full name of a debug or analytic log.

        Required?                    false
        Position?                    named
        Default value                Debugging and analytic logs are not returned in response to queries that use wildcard characters.
        Accept pipeline input?     false
        Accept wildcard characters? false

    -ListLog <string[]>
        Gets the specified event logs. Enter the event log names in a comma-separated list. Wildcards are permitted. To get all the logs, enter a value of *.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? true

    -ListProvider <string[]>
        Gets the specified event log providers. An event log provider is a program or service that writes events to the event log.

        Enter the provider names in a comma-separated list. Wildcards are permitted. To get the providers of all the event logs on the computer, enter a value of *.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? true

    -LogName <string[]>
        Gets events from the specified event logs. Enter the event log names in a comma-separated list. Wildcards are permitted. You can also pipe log names to Get-WinEvent.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? true

    -MaxEvents <int64>
        Specifies the maximum number of events that Get-WinEvent returns. Enter an integer. The default is to return all the events in the logs or files.

        Required?                    false
        Position?                    named
        Default value                All events
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Oldest [<SwitchParameter>]
        Returns the events in oldest-first order. By default, events are returned in newest-first order.

        This parameter is required to get events from .etl and .evt files and from debug and analytic logs. In these files, events are recorded in oldest-first order, and the events can be returned only in oldest-first order.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Path <string[]>
        Gets events from the specified event log files. Enter the paths to the log files in a comma-separated list, or use wildcard characters to create file path patterns.

        Get-WinEvent supports files with the .evt, .evtx, and .etl file name extensions. You can include events from different files and file types in the same command.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? true

    -ProviderName <string[]>
        Gets events written by the specified event log providers. Enter the provider names in a comma-separated list, or use wildcard characters to create provider name patterns.

        An event log provider is a program or service that writes events to the event log. It is not a Windows PowerShell provider.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?     false
        Accept wildcard characters? true

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.String, System.Xml.XmlDocument, System.Collections.Hashtable.
        You can pipe a LogName (string), a FilterXML query, or a FilterHashTable query to Get-WinEvent.

OUTPUTS
    System.Diagnostics.Eventing.Reader.EventLogConfiguration, System.Diagnostics.Eventing.Reader.EventLogRecord, System.Diagnostics.Eventing.Reader.ProviderMetadata
        With the ListLog parameter, Get-WinEvent returns System.Diagnostics.Eventing.Reader.EventLogConfiguration objects. With the ListProvider parameter, Get-WinEvent returns
        System.Diagnostics.Eventing.Reader.ProviderMetadata objects. With all other parameters, Get-WinEvent returns System.Diagnostics.Eventing.Reader.EventLogRecord objects.

NOTES

        Get-WinEvent is designed to replace the Get-EventLog cmdlet on computers running Windows Vista and later versions of Windows. Get-EventLog gets events only in classic event logs. Get-EventLog is retained in Windows PowerShell 2.0 for systems earlier than Windows Vista.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-WinEvent -listlog *

    Description
    ———–
    This command gets all the logs on the local computer.

    Logs are listed in the order that Get-WinEvent gets them. Classic logs are usually retrieved first, followed by the new Windows Eventing logs.

    Because there are typically more than a hundred event logs, this parameter requires a log name or name pattern. To get all the logs, use *.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-WinEvent -listlog Setup | Format-List -property *

        FileSize                     : 69632
        IsLogFull                     : False
        LastAccessTime                 : 2/14/2008 12:55:12 AM
        LastWriteTime                 : 7/9/2008 3:12:05 AM
        OldestRecordNumber             : 1
        RecordCount                    : 3
        LogName                        : Setup
        LogType                        : Operational
        LogIsolation                 : Application
        IsEnabled                     : True
        IsClassicLog                 : False
        SecurityDescriptor             : O:BAG:SYD:(A;;0xf0007;;;SY)(A;
                                         (A;;0x1;;;S-1-5-32-573)
        LogFilePath                    : %SystemRoot%\System32\Winevt\L
        MaximumSizeInBytes             : 1052672
        LogMode                        : Circular
        OwningProviderName             : Microsoft-Windows-Eventlog
        ProviderNames                 : {Microsoft-Windows-WUSA, Micro
        ProviderLevel                 :
        ProviderKeywords             :
        ProviderBufferSize             : 64
        ProviderMinimumNumberOfBuffers : 0
        ProviderMaximumNumberOfBuffers : 64
        ProviderLatency                : 1000
        ProviderControlGuid            :

    Description
    ———–
    These commands get an object that represents the classic System log on the local computer. The object includes useful information about the log, including its size, event log provider, file path, and whether it is enabled.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Get-WinEvent -listlog * -ComputerName Server01| where {$_.recordcount}

    Description
    ———–
    This command gets only event logs on the Server01 computer that contain events. Many logs might be empty.

    The command uses the RecordCount property of the EventLogConfiguration object that Get-WinEvent returns when you use the ListLog parameter.

    ————————– EXAMPLE 4 ————————–

    C:\PS>$s = “Server01”, “Server02”, “Server03”

    C:\PS> foreach ($server in $s)
         {$server; Get-WinEvent -listlog “Windows PowerShell” -ComputerName $server}

    Description
    ———–
    The commands in this example get objects that represent the Windows PowerShell event logs on the Server01, Server02, and Server03 computers. This command uses the Foreach keyword because the ComputerName parameter takes only one value.

    The first command saves the names of the computers in the $s Variable.

    The second command uses a Foreach statement. For each of the computers in the $s Variable, it performs the command in the script block (within the braces). First, the command prints the name of the computer. Then, it runs a Get-WinEvent command to get an object that represents the Windows PowerShell log.

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-WinEvent -listprovider *

    Description
    ———–
    This command gets the event log providers on the local computer and the logs to which they write, if any.

    ————————– EXAMPLE 6 ————————–

    C:\PS>(Get-WinEvent -listlog Application).providernames

    Description
    ———–
    This command gets all of the providers that write to the Application log on the local computer.

    ————————– EXAMPLE 7 ————————–

    C:\PS>>Get-WinEvent -listprovider *policy*

    Description
    ———–
    This command gets the event log providers whose names include the word “policy.”

    ————————– EXAMPLE 8 ————————–

    C:\PS>(Get-WinEvent -listprovider microsoft-windows-grouppolicy).events | Format-Table id, description -auto

    Description
    ———–
    This command lists the event IDs that the Microsoft-Windows-GroupPolicy event provider generates along with the event description.

    It uses the Events property of the object that Get-WinEvent returns when you use the ListProvider parameter, and it uses the ID and Description properties of the object in the Events property.

    ————————– EXAMPLE 9 ————————–

    C:\PS>$events = Get-WinEvent -LogName “Windows PowerShell”

    C:\PS> $events.count
    195

    C:\PS> $events | Group-Object id -noelement | Sort-Object count -desc
    Count Name
    —– —-
     147 600
     22 400
     21 601
        3 403
        2 103

     C:\PS> $events | Group-Object leveldisplayname -noelement
    Count Name
    —– —-
        2 Warning
     193 Information

    Description
    ———–
    This example shows how to use the properties of the event objects that Get-WinEvent returns to learn about the events in an event log.

    The first command uses the Get-WinEvent cmdlet to get all of the events in the Windows PowerShell event log. Then, it saves them in the $events Variable. The log name is enclosed in quotation marks because it contains a space.

    The second command uses the Count property of object collections to find the number of entries in the event log.

    The third command displays the incidence of each event in the log, with the most frequent events first. In this example, event ID 600 is the most frequent event.

    The fourth command groups the items by the value of their LevelDisplayName property to show how many Error, Warning, and Information events are in the log.

    ————————– EXAMPLE 10 ————————–

    C:\PS>Get-WinEvent -LogName *disk*, Microsoft-Windows-Kernel-WHEA

    Description
    ———–
    This command gets the error events whose names include “disk” from all of the event logs on the computer and from the Microsoft-Windows-Kernel-WHEA event log.

    ————————– EXAMPLE 11 ————————–

    C:\PS>Get-WinEvent -path ‘c:\ps-test\Windows PowerShell.evtx’

    Description
    ———–
    This command gets events from a copy of the Windows PowerShell event log file in a test directory. The path is enclosed in quotation marks because the log name includes a space.

    ————————– EXAMPLE 12 ————————–

    C:\PS>Get-WinEvent -path ‘c:\tracing\tracelog.etl’ -MaxEvents 100 -Oldest

    C:\PS> Get-WinEvent -path ‘c:\tracing\tracelog.etl’ -Oldest | Sort-Object -property timecreated -desc | Select-Object -first 100

    Description
    ———–
    These commands get the first 100 events from an Event Tracing for Windows (ETW) event trace log file.

    The first command gets the 100 oldest events in the log. It uses the Get-WinEvent cmdlet to get events from the Tracelog.etl file. It uses the MaxEvents parameter to limit the retrieval to 100 events. Because the events are listed in the order in which they are written to the log (oldest first), the Oldest parameter is required.

    The second command gets the 100 newest events in the log. It uses the Get-WinEvent cmdlet to get all the events from the Tracing.etl file. It passes
    the events to the Sort-Object cmdlet, which sorts them in descending order by the value of the TimeCreated property. Then, it sends the sorted events to the Select-Object cmdlet to select the newest 100 events.

    ————————– EXAMPLE 13 ————————–

    C:\PS>Get-WinEvent -path “c:\tracing\tracelog.etl”, “c:\Logs\Windows PowerShell.evtx” -Oldest | where {$_.id -eq “103”}

    Description
    ———–
    This example shows how to get the events from an event trace log file (.etl) and from a copy of the Windows PowerShell log file (.evtx) that was saved to a test directory.

    You can combine multiple file types in a single command. Because the files contain the same type of .NET Framework object (an EventLogRecord object), you can use the same properties to filter them.

    Note that the command requires the Oldest parameter because it is reading from an .etl file, but the Oldest parameter applies to both of the files.

    ————————– EXAMPLE 14 ————————–

    C:\PS># Use the Where-Object cmdlet
    C:\PS> $yesterday = (Get-Date) – (New-TimeSpan -day 1)
    C:\PS> Get-WinEvent -LogName “Windows PowerShell” | where {$_.timecreated -ge $yesterday}

    # Uses FilterHashTable
    C:\PS> $yesterday = (Get-Date) – (New-TimeSpan -day 1)
    C:\PS> Get-WinEvent -FilterHashTable @{LogName=’Windows PowerShell’; Level=3; StartTime=$yesterday}

    # Use FilterXML
    C:\PS> Get-WinEvent -FilterXML “<QueryList><Query><Select Path=’Windows PowerShell’>*[System[Level=3 and TimeCreated[timediff(@SystemTime) <= 86400000]]]</Select></Query></QueryList>”

    # Use FilterXPath
    C:\PS> Get-WinEvent -LogName “Windows Powershell” -FilterXPath “*[System[Level=3 and TimeCreated[timediff(@SystemTime) <= 86400000]]]”

    Description
    ———–
    This example shows different filtering methods for selecting events from an event log. All of these commands get events that occurred in the last 24 hours from the Windows PowerShell event log.

    The filter methods are more efficient than using the Where-Object cmdlet because the filters are applied while the objects are being retrieved, rather than retrieving all the objects and then filtering them.

    Because dates are difficult to formulate in the XML and XPath formats, to create the XML content for the date, the Filter Current Log feature of Event Viewer is used. For more information about this feature, see Event Viewer Help.

    ————————– EXAMPLE 15 ————————–

    C:\PS>$date = (Get-Date).AddDays(-2)

    C:\PS> $events = Get-WinEvent -FilterHashTable @{ logname = “Microsoft-Windows-Diagnostics-Performance/Operational”; StartTime = $date; ID = 100 }

    Description
    ———–
    This example uses a filter hash table to get events from the performance log.

    The first command uses the Get-Date cmdlet and the AddDays method to get a date that is two days before the current date. It saves the date in the $date Variable.

    The second command uses the Get-WinEvent cmdlet with the FilterHashTable parameter. The keys in the hash table define a filter that selects events from the performance log that occurred within the last two days and that have event ID 100.

    The LogName key specifies the event log, the StartTime key specifies the date, and the ID key specifies the event ID.

    ————————– EXAMPLE 16 ————————–

    C:\PS>$starttime = (Get-Date).adddays(-7)

    C:\PS> $ie-error = Get-WinEvent -FilterHashtable @{logname=”application”; providername=”Application Error”; data=”iexplore.exe”; starttime=$starttime}

    Description
    ———–
    This example uses a filter hash table to find Internet Explorer application errors that occurred within the last week.

    The first command gets the date that is seven days before the current date and stores it in the $starttime Variable.

    The second command uses the Get-WinEvent cmdlet with the FilterHashTable parameter. The keys in the hash table define a filter that selects events from the Application log that were written by the Application Error provider and include the phrase “iexplore.exe”.

    The LogName key specifies the event log. The ProviderName key specifies the event provider, the StartTime key specifies the starting date of the events, and the Data key specifies the text in the event message.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=138336
    Get-EventLog
    Get-Counter
    about_eventlogs

Get-EventLog

NAME
    Get-EventLog

SYNOPSIS
    Gets the events in an event log, or a list of the event logs, on the local or remote computers.

SYNTAX
    Get-EventLog [-AsString] [-ComputerName <string[]>] [-List] [<CommonParameters>]

    Get-EventLog [-LogName] <string> [[-InstanceId] <Int64[]>] [-After <DateTime>] [-AsBaseObject] [-Before <DateTime>] [-ComputerName <string[]>] [-EntryType <string[]>] [-Index <Int32[]>] [-Message <string>] [-Newest <int>] [-Source <string[]>] [-UserName <string[]>] [<CommonParameters>]

DESCRIPTION
    The Get-EventLog cmdlet gets events and event logs on the local and remote computers.

    Use the parameters of Get-EventLog to search for events by using their property values. Get-EventLog gets only the events that match all of the specified property values.

    The cmdlets that contain the EventLog noun (the EventLog cmdlets) work only on classic event logs. To get events from logs that use the Windows Event Log technology in Windows Vista and later versions of Windows, use Get-WinEvent.

PARAMETERS
    -After <DateTime>
        Gets only the events that occur after the specified date and time. Enter a DateTime object, such as the one returned by the Get-Date cmdlet.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -AsBaseObject [<SwitchParameter>]
        Returns a standard System.Diagnostics.EventLogEntry object for each event. Without this parameter, Get-EventLog returns an extended PSObject object with additional EventLogName, Source, and InstanceId properties.

        To see the effect of this parameter, pipe the events to the Get-Member cmdlet and examine the TypeName value in the result.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?     false
        Accept wildcard characters? false

    -AsString [<SwitchParameter>]
        Returns the output as strings, instead of objects.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Before <DateTime>
        Gets only the events that occur before the specified date and time. Enter a DateTime object, such as the one returned by the Get-Date cmdlet.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -ComputerName <string[]>
        Specifies a remote computer. The default is the local computer.

        Type the NetBIOS name, an Internet Protocol (IP) address, or a fully qualified domain name of a remote computer. To specify the local computer, type the computer name, a dot (.), or “localhost”.

        This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-EventLog even if your computer is not configured to run remote commands.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -EntryType <string[]>
        Gets only events with the specified entry type. Valid values are Error, Information, FailureAudit, SuccessAudit, and Warning. The default is all events.

        Required?                    false
        Position?                    named
        Default value                All events
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Index <Int32[]>
        Gets only events with the specified index values.

        Required?                    false
        Position?                    named
        Default value                All events
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InstanceId <Int64[]>
        Gets only events with the specified instance IDs.

        Required?                    false
        Position?                    2
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -List [<SwitchParameter>]
        Gets a list of event logs on the computer.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -LogName <string>
        Specifies the event log. Enter the log name (the value of the Log property; not the LogDisplayName) of one event log. Wildcard characters are not permitted. This parameter is required.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Message <string>
        Gets events that have the specified string in their messages. You can use this property to search for messages that contain certain words or phrases. Wildcards are permitted.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? true

    -Newest <int>
        Specifies the maximum number of events retrieved. Get-EventLog gets the specified number of events, beginning with the newest event in the log.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Source <string[]>
        Gets events that were written to the log by the specified sources. Wildcards are permitted.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? true

    -UserName <string[]>
        Gets only the events that are associated with the specified user names. Enter names or name patterns, such as User01, User*, or Domain01\User*. Wildcards are permitted.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? true

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None.
        You cannot pipe input to this cmdlet.

OUTPUTS
    System.Diagnostics.EventLogEntry. System.Diagnostics.EventLog. System.String
        If the LogName parameter is specified, the output is a collection of EventLogEntry objects (System.Diagnostics.EventLogEntry).

        If only the List parameter is specified, the output is a collection of EventLog objects (System.Diagnostics.EventLog).

        If both the List and AsString parameters are specified, the output is a collection of Strings (System.String).

NOTES

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-Eventlog -list

    Description
    ———–
    This command displays information about the event logs on the computer.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-Eventlog -Newest 5 -LogName application

    Description
    ———–
    This command displays the five most recent entries in the Application event log.

    ————————– EXAMPLE 3 ————————–

    C:\PS>$events = Get-Eventlog -LogName system -Newest 1000

    C:\PS> $events | Group-Object -property source -noelement | Sort-Object -property count -descending

    Count Name
    —– —-
     75 Service Control Manager
     12 Print
        6 UmrdpService
        2 DnsApi
        2 DCOM
        1 Dhcp
        1 TermDD
        1 volsnap

    Description
    ———–
    This example shows how to find all of the sources that are represented in the 1000 most recent entries in the System event log.

    The first command gets the 1,000 most recent entries from the System event log and stores them in the $events Variable.

    The second command uses a pipeline operator (|) to send the events in $events to the Group-Object cmdlet, which groups the entries by the value of the Source property. The command uses a second pipeline operator to send the grouped events to the Sort-Object cmdlet, which sorts them in descending order, so the most frequently appearing source is listed first.

    Source is just property of event log entries. To see all of the properties of an event log entry, pipe the events to the Get-Member cmdlet.

    ————————– EXAMPLE 4 ————————–

    C:\PS>Get-Eventlog -LogName System -EntryType Error

    Description
    ———–
    This command gets only error events from the System event log.

    ————————– EXAMPLE 5 ————————–

    C:\PS>Get-Eventlog -LogName System -InstanceId 3221235481 -Source “DCOM”

    Description
    ———–
    This command gets events from the System log that have an InstanceID of 3221235481 and a Source value of “DCOM.”

    ————————– EXAMPLE 6 ————————–

    C:\PS>Get-Eventlog -LogName “Windows PowerShell” -ComputerName localhost, Server01, Server02

    Description
    ———–
    This command gets the events from the “Windows PowerShell” event log on three computers, Server01, Server02, and the local computer, known as “localhost”.

    ————————– EXAMPLE 7 ————————–

    C:\PS>Get-Eventlog -LogName “Windows PowerShell” -Message “*failed*”

    Description
    ———–
    This command gets all the events in the Windows PowerShell event log that have a message value that includes the word “failed”.

    ————————– EXAMPLE 8 ————————–

    C:\PS>$a = Get-Eventlog -log System -Newest 1

    C:\PS> $a | Format-List -property *

    EventID            : 7036
    MachineName        : Server01
    Data             : {}
    Index             : 10238
    Category         : (0)
    CategoryNumber     : 0
    EntryType         : Information
    Message            : The description for Event ID
    Source             : Service Control Manager
    ReplacementStrings : {WinHTTP Web Proxy Auto-Disco
    InstanceId         : 1073748860
    TimeGenerated     : 4/11/2008 9:56:05 PM
    TimeWritten        : 4/11/2008 9:56:05 PM
    UserName         :
    Site             :
    Container         :

    Description
    ———–
    This example shows how to display all of the property values of an event.

    The first command gets the newest event from the System event log and saves it in the $a Variable.

    The second command uses a pipeline operator (|) to send the event in $a to the Format-List command, which displays all (*) of the event properties.

    ————————– EXAMPLE 9 ————————–

    C:\PS>Get-Eventlog -log application -Source outlook | where {$_.eventID -eq 34}

    Description
    ———–
    This command gets events in the Application event log where the source is Outlook and the event ID is 34. Even though Get-EventLog does not have an EventID parameter, you can use the Where-Object cmdlet to select events based on the value of any event property.

    ————————– EXAMPLE 10 ————————–

    C:\PS>Get-Eventlog -log system -UserName NT* | Group-Object -property username -noelement | Format-Table Count, Name -auto

    Count Name
    —– —-
     6031 NT AUTHORITY\SYSTEM
     42 NT AUTHORITY\LOCAL SERVICE
        4 NT AUTHORITY\NETWORK SERVICE

    Description
    ———–
    This command returns the events in the system log grouped by the value of their UserName property. The Get-EventLog command uses the UserName parameter to get only events in which the user name begins with “NT*”.

    ————————– EXAMPLE 11 ————————–

    C:\PS>$May31 = Get-Date 5/31/08

    C:\PS> $July1 = Get-Date 7/01/08

    C:\PS> Get-Eventlog -log “Windows PowerShell” -EntryType Error -After $may31 -Before $july1

    Description
    ———–
    This command gets all of the errors in the Windows PowerShell event log that occurred in June 2008.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113314
    Get-WinEvent
    Clear-EventLog
    Limit-EventLog
    New-EventLog
    Remove-EventLog
    Show-EventLog
    Write-EventLog
    Get-WinEvent

Clear-EventLog

NAME
    Clear-EventLog

SYNOPSIS
    Deletes all entries from specified event logs on the local or remote computers.

SYNTAX
    Clear-EventLog [-LogName] <string[]> [[-ComputerName] <string[]>] [-Confirm] [-WhatIf] [<CommonParameters>]

DESCRIPTION
    The Clear-EventLog cmdlet deletes all of the entries from the specified event logs on the local computer or on remote computers. To use Clear-EventLog, you must be a member of the Administrators group on the affected computer.

    The cmdlets that contain the EventLog noun (the EventLog cmdlets) work only on classic event logs. To get events from logs that use the Windows Event Log technology in Windows Vista and later versions of Windows, use Get-WinEvent.

PARAMETERS
    -ComputerName <string[]>
        Specifies a remote computer. The default is the local computer.

        Type the NetBIOS name, an Internet Protocol (IP) address, or a fully qualified domain name of a remote computer. To specify the local computer, type the computer name, a dot (.), or “localhost”.

        This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-EventLog even if your computer is not configured to run remote commands.

        Required?                    false
        Position?                    2
        Default value                Local computer
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -LogName <string[]>
        Specifies the event logs. Enter the log name (the value of the Log property; not the LogDisplayName) of one or more event logs, separated by commas. Wildcard characters are not permitted. This parameter is required.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     true (ByPropertyName)
        Accept wildcard characters? false

    -Confirm [<SwitchParameter>]
        Prompts you for confirmation before executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -WhatIf [<SwitchParameter>]
        Describes what would happen if you executed the command without actually executing the command.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    None
        You cannot pipe objects to Clear-EventLog.

OUTPUTS
    None
        This cmdlet does not generate any output.

NOTES

        To use Clear-EventLog on Windows Vista and later versions of Windows, start Windows PowerShell with the “Run as administrator” option.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Clear-EventLog “Windows PowerShell”

    Description
    ———–
    This command deletes the entries from the “Windows PowerShell” event log on the local computer.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Clear-EventLog -LogName ODiag, OSession -ComputerName localhost, Server02

    Description
    ———–
    This command deletes all of the entries in the Microsoft Office Diagnostics (ODiag) and Microsoft Office Sessions (OSession) logs on the local computer and the Server02 remote computer.

    ————————– EXAMPLE 3 ————————–

    C:\PS>Clear-EventLog -log application, system -Confirm

    Description
    ———–
    This command prompts you for confirmation before deleting the entries in the specified event logs.

    ————————– EXAMPLE 4 ————————–

    C:\PS>function clear-all-event-logs ($computerName=”localhost”)
    {
        $logs = Get-Eventlog -ComputerName $computername -list | foreach {$_.Log}
        $logs | foreach {Clear-EventLog -comp $computername -log $_ }
        Get-Eventlog -ComputerName $computername -list
    }

    C:\PS> clear-all-event-logs -comp Server01

     Max(K) Retain OverflowAction        Entries Log
     —— —— ————–        ——- —
     15,168     0 OverwriteAsNeeded         0 Application
     15,168     0 OverwriteAsNeeded         0 DFS Replication
         512     7 OverwriteOlder             0 DxStudio
     20,480     0 OverwriteAsNeeded         0 Hardware Events
         512     7 OverwriteOlder             0 Internet Explorer
     20,480     0 OverwriteAsNeeded         0 Key Management Service
     16,384     0 OverwriteAsNeeded         0 Microsoft Office Diagnostics
     16,384     0 OverwriteAsNeeded         0 Microsoft Office Sessions
     30,016     0 OverwriteAsNeeded         1 Security
     15,168     0 OverwriteAsNeeded         2 System
     15,360     0 OverwriteAsNeeded         0 Windows PowerShell

    Description
    ———–
    This Function clears all event logs on the specified computers and then displays the resulting event log list.

    Notice that a few entries were added to the System and Security logs after the logs were cleared but before they were displayed.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135198
    Get-EventLog
    Limit-EventLog
    New-EventLog
    Remove-EventLog
    Show-EventLog
    Write-EventLog
    Get-WinEvent