Skip to content

Commit

Permalink
added try-catch and other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasjordan committed Jun 21, 2023
1 parent e1a4171 commit b99b731
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions public/Read-DbaXEFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function Read-DbaXEFile {
Stop-Function -Message "The session [$pathObject] does not have an associated Target File." -Continue
}

$instance = [dbainstance]$pathObject.ComputerName
$instance = [DbaInstance]$pathObject.ComputerName
if ($instance.IsLocalHost) {
$targetFile = $pathObject.TargetFile
} else {
Expand All @@ -83,22 +83,26 @@ function Read-DbaXEFile {
}

foreach ($file in $files) {
$accessible = Test-Path -Path $file
$whoami = whoami

if (-not $accessible) {
if ($pathObject.Status -eq "Stopped") { continue }
Stop-Function -Continue -Message "$file cannot be accessed from $($env:COMPUTERNAME). Does $whoami have access?"
if (-not (Test-Path -Path $file)) {
Stop-Function -Message "$file cannot be accessed from $($env:COMPUTERNAME)." -Continue
}

# use the SqlServer\Read-SqlXEvent cmdlet from Microsoft
# because the underlying Class uses Tasks
# which is hard to handle in PowerShell

if ($Raw) {
SqlServer\Read-SqlXEvent -FileName $file
try {
SqlServer\Read-SqlXEvent -FileName $file
} catch {
Stop-Function -Message "Failure" -ErrorRecord $_ -Target $file -Continue
}
} else {
$enum = SqlServer\Read-SqlXEvent -FileName $file
try {
$enum = SqlServer\Read-SqlXEvent -FileName $file
} catch {
Stop-Function -Message "Failure" -ErrorRecord $_ -Target $file -Continue
}
$newcolumns = ($enum.Fields.Name | Select-Object -Unique)

$actions = ($enum.Actions.Name | Select-Object -Unique)
Expand Down

0 comments on commit b99b731

Please sign in to comment.