Skip to content

Commit

Permalink
more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasjordan committed Jun 21, 2023
1 parent b99b731 commit f6606ea
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions public/Read-DbaXEFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ function Read-DbaXEFile {
.DESCRIPTION
Read XEvents from a *.xel or *.xem file.
Uses the command Read-SqlXEvent from the PowerShell module SqlServer by Microsoft.
The file that the XESession is currently writing to can not be accessed and will be skipped using pipeline input from Get-DbaXESession.
.PARAMETER Path
The path to the *.xem or *.xem file. This is relative to the computer executing the command. UNC paths are supported.
Piping from Get-DbaXESession is also supported.
.PARAMETER Raw
If this switch is enabled, the Microsoft.SqlServer.XEvent.Linq.PublishedEvent enumeration object will be returned.
Expand Down Expand Up @@ -39,7 +45,7 @@ function Read-DbaXEFile {
Returns events from all .xel files in C:\temp\xe.
.EXAMPLE
PS C:\> Get-DbaXESession -SqlInstance sql2014 -Session deadlocks | Read-DbaXEFile
PS C:\> Get-DbaXESession -SqlInstance sql2019 -Session deadlocks | Read-DbaXEFile
Reads remote XEvents by accessing the file over the admin UNC share.
Expand Down Expand Up @@ -76,7 +82,10 @@ function Read-DbaXEFile {
}

$targetFile = $targetFile.Replace('.xel', '*.xel').Replace('.xem', '*.xem')
$files = Get-ChildItem -Path $targetFile | Where-Object Length -gt 0
$files = Get-ChildItem -Path $targetFile | Sort-Object LastWriteTime
if ($pathObject.Status -eq 'Running') {
$files = $files | Select-Object -SkipLast 1
}
Write-Message -Level Verbose -Message "Received $($files.Count) files based on [$targetFile]"
} else {
Stop-Function -Message "The Path [$pathObject] has an unsupported file type of [$($pathObject.GetType().FullName)]."
Expand Down

0 comments on commit f6606ea

Please sign in to comment.