Function Get-WMIEvent($class, $Path="root\cimv2", $query, $Timeout = [timespan]"0.0:0:10",$Credential, $ComputerName) { $scope = $null if ($class -eq $null -and $query -eq $null) { write-host "Please specify either the event class name (-class) or the query" return $null } if ($ComputerName -ne $null) { $Path = "\\" + $Computername + "\" + $Path if ($Credential -ne $null) { [System.Management.Automation.PsCredential]$connection = get-credential $credential [System.Net.NetworkCredential]$cred = $connection.GetNetworkCredential(); $scope = New-Object System.Management.ManagementScope $Path $scope.options.Username = $cred.Username $scope.options.Password = $cred.Password } else { $scope = New-Object System.Management.ManagementScope $Path } } if ($timeout -ne $null) { $options = New-Object System.Management.EventWatcherOptions $options.TimeOut = $Timeout } if ($query -ne $null) { $queryObject = new-object Management.EventQuery $queryObject.QueryString = $query $watcher = new-object Management.ManagementEventWatcher $scope, $queryObject if ($options -ne $null) { $watcher.Options = $Options } return $watcher } if ($class -ne $null) { $query = New-Object System.Management.WQlEventQuery "Select * from $class" $watcher = New-Object System.Management.ManagementEventWatcher $scope, $query if ($options -ne $null) { $watcher.Options = $Options } return $watcher } } Set-Alias gwe Get-WmiEvent