EventLog/Get-EventVHDImageMount.ps1
function Get-EventVHDImageMount { <# .SYNOPSIS Get Microsoft-Windows-VHDMP-Operational events for when a ISO, VHD, VHDX or CMGS image is mounted on Windows 8 and above systems. .DESCRIPTION Get Microsoft-Windows-VHDMP-Operational events for when a ISO, VHD, VHDX or CMGS image is mounted on Windows 8 and above systems. .EXAMPLE PS C:\> Get-EventVHDImageMount EventId : 12 EventRecordID : 26502 TimeCreated : 2/1/2023 10:09:33 AM Computer : DESKTOP-LH0AJLB Provider : Microsoft-Windows-VHDMP ProcessID : 11560 ThreadID : 17800 UserSID : S-1-5-21-2697533880-3473899400-4136494737-1001 Status : 0 VhdFile : \\?\C:\Users\Carlos Perez\Downloads\support.iso VmId : {00000000-0000-0000-0000-000000000000} VhdType : 3 Version : 1 Flags : 0 AccessMask : 851968 WriteDepth : 0 GetInfoOnly : false ReadOnly : false HandleContext : 0xffffa504b1e885c0 VirtualDisk : 0xffffa504cbf5e040 FileObject : 0xffffa504cc31b9b0 #> [CmdletBinding(DefaultParameterSetName = 'Local')] param ( # Log name for where the events are stored. [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)] [string] $LogName = 'Microsoft-Windows-VHDMP-Operational', # 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, # Type of image to search for, if not specified all mounted images are returned. ISO will return ISO images, VHD will return VHD and VMGS, VHDX will return VHDX and AVHDX. [Parameter(Mandatory=$true)] [ValidateSet("ISO","VHD","VHDX")] [string] $VhdType, # 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 = $true, 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, # Changes the query action from inclusion to exclusion when fields are matched. [Parameter(Mandatory = $false)] [switch] $Suppress ) begin { $Params = $MyInvocation.BoundParameters $vhdtypes = @{ "ISO" = 3 "VHD" = 1 "VHDX" = 2 } if ($Params.Keys -contains "VhdType") { $imageType = $params["VhdType"] $Params.Remove("VhdType") | Out-Null $Params.Add('VhdType', $vhdtypes[$imageType]) | Out-Null } } process { Search-EventLogEventData -EventId 12 -ParamHash $Params -Provider "Microsoft-Windows-VHDMP" -RecordType "VHDMImageMount" -returnrecord | ForEach-Object -Process { [xml]$evtXml = $_.toxml() $evtInfo = [ordered]@{} $evtInfo['EventId'] = $evtXml.Event.System.EventID $evtInfo['EventRecordID'] = $evtXml.Event.System.EventRecordID $evtInfo['TimeCreated'] = [datetime]$evtXml.Event.System.TimeCreated.SystemTime $evtInfo['Computer'] = $evtXml.Event.System.Computer $evtInfo['Provider'] = $evtXml.Event.System.Provider.Name $evtInfo['ProcessID'] = $evtXml.Event.System.Execution.ProcessID $evtInfo['ThreadID'] = $evtXml.Event.System.Execution.ThreadID $evtInfo['UserSID'] = $evtXml.Event.System.Security.UserID $evtxml.Event.EventData.Data | ForEach-Object { $evtInfo[$_.name] = $_.'#text' } New-Object psobject -Property $evtInfo } } end {} } |