EventLog/Get-EventWmiTemporaryEvent.ps1
function Get-EventWmiTemporaryEvent { <# .SYNOPSIS Get WMI Temporary Event Start events (EventId 5860). .DESCRIPTION Get WMI Temporary Event Start events (EventId 5860). from a local or remote host. Events can be filtered by fields. .INPUTS System.IO.FileInfo .OUTPUTS System.Management.Automation.PSCustomObject .NOTES Operation Types https://docs.microsoft.com/en-us/windows/win32/api/wbemcli/nn-wbemcli-iwbemservices Result Codes https://docs.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants?redirectedfrom=MSDN #> [CmdletBinding(DefaultParameterSetName = 'Local')] param ( # Log name for where the events are stored. [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [string] $LogName = 'Microsoft-Windows-WMI-Activity/Operational', # User performing the action. [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [string[]] $User, # Machine that connected to the CMON database. [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [string[]] $ClientMachine, # Process ID of the process that performed the action. [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [string[]] $ProcessId, # Query associated with the temporary subscription. [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [string[]] $Query, # NameSpace against the query is being performed against. [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [string[]] $NameSpace, # Specifies the path to the event log files that this cmdlet get events from. Enter the paths to the log files in a comma-separated list, or use wildcard characters to create file path patterns. Function supports files with the .evtx file name extension. You can include events from different files and file types in the same command. [Parameter(Mandatory=$true, Position=0, ParameterSetName="file", ValueFromPipelineByPropertyName=$true)] [Alias("FullName")] [ValidateNotNullOrEmpty()] [SupportsWildcards()] [string[]] $Path, # 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. # To get events and event logs from remote computers, the firewall port for the event log service must be configured to allow remote access. [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Remote')] [string[]] $ComputerName, # Specifies a user account that has permission to perform this action. # # 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. [Parameter(Mandatory = $false, ParameterSetName = 'Remote')] [Management.Automation.PSCredential] [Management.Automation.CredentialAttribute()] $Credential, # Specifies the maximum number of events that are returned. Enter an integer. The default is to return all the events in the logs or files. [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [int64] $MaxEvents, # Stsrttime from where to pull events. [Parameter(Mandatory = $false)] [datetime] $StartTime, # Stsrttime from where to pull events. [Parameter(Mandatory = $false)] [datetime] $EndTime, # Changes the default logic for matching fields from 'and' to 'or'. [Parameter(Mandatory = $false)] [switch] $ChangeLogic ) begin {} process { Search-EventLogUsertData -EventId 5860 -Provider "Microsoft-Windows-WMI-Activity" -ReturnRecord -SubElement -ParamHash $MyInvocation.BoundParameters | ForEach-Object { [xml]$evtxml = $_.toxml() $ProcInfo = [ordered]@{} $ProcInfo['EventId'] = $evtxml.Event.System.EventID $ProcInfo['Computer'] = $evtxml.Event.System.Computer $ProcInfo['EventRecordID'] = $evtxml.Event.System.EventRecordID $ProcInfo['TimeCreated'] = [datetime]$evtXml.Event.System.TimeCreated.SystemTime $ProcInfo['User'] = $evtxml.Event.UserData.Operation_ClientFailure.User $ProcInfo['ClientMachine'] = $evtxml.Event.UserData.Operation_TemporaryEssStarted.ClientMachine $ProcInfo['Namespace'] = $evtxml.Event.UserData.Operation_TemporaryEssStarted.NamespaceName $ProcInfo['Query'] = $evtxml.Event.UserData.Operation_TemporaryEssStarted.Query $ProcInfo['ProcessId'] = $evtxml.Event.UserData.Operation_TemporaryEssStarted.ProcessId $ProcInfo['PossibleCause'] = $evtxml.Event.UserData.Operation_TemporaryEssStarted.PossibleCause $Obj = New-Object psobject -Property $ProcInfo $Obj } } end {} } |