File tree Expand file tree Collapse file tree 7 files changed +32
-35
lines changed Expand file tree Collapse file tree 7 files changed +32
-35
lines changed Original file line number Diff line number Diff line change @@ -82,23 +82,23 @@ function Read-DbaAuditFile {
82
82
}
83
83
}
84
84
85
- $accessible = Test-Path - Path $currentFile
86
- $whoami = whoami
85
+ # $currentFile is only the base filename and must be expanded using a wildcard
86
+ $fileNames = (Get-ChildItem - Path ($currentFile -replace ' \.sqlaudit$' , ' *.sqlaudit' ) | Sort-Object CreationTime).FullName
87
+ $enum = @ ( )
88
+ foreach ($fileName in $fileNames ) {
89
+ $accessible = Test-Path - Path $fileName
90
+ $whoami = whoami
91
+ if (-not $accessible ) {
92
+ Stop-Function - Continue - Message " $fileName cannot be accessed from $ ( $env: COMPUTERNAME ) . Does $whoami have access?"
93
+ }
87
94
88
- if (-not $accessible ) {
89
- if ($file.Status -eq " Stopped" ) { continue }
90
- Stop-Function - Continue - Message " $currentFile cannot be accessed from $ ( $env: COMPUTERNAME ) . Does $whoami have access?"
95
+ $enum += Read-XEvent - FileName $fileName
91
96
}
92
97
93
98
if ($Raw ) {
94
- return (SqlServer. XEvent\Read-SqlXEvent - FileName $currentfile )
99
+ return $enum
95
100
}
96
101
97
- # use the SqlServer.XEvent\Read-SqlXEvent cmdlet from Microsoft
98
- # because the underlying Class uses Tasks
99
- # which is hard to handle in PowerShell
100
-
101
- $enum = SqlServer.XEvent\Read-SqlXEvent - FileName $currentfile
102
102
$newcolumns = ($enum.Fields.Name | Select-Object - Unique)
103
103
104
104
$actions = ($enum.Actions.Name | Select-Object - Unique)
Original file line number Diff line number Diff line change @@ -94,10 +94,6 @@ function Read-DbaXEFile {
94
94
Stop-Function - Message " $file cannot be accessed from $ ( $env: COMPUTERNAME ) ." - Continue
95
95
}
96
96
97
- # use the SqlServer\Read-SqlXEvent cmdlet from Microsoft
98
- # because the underlying Class uses Tasks
99
- # which is hard to handle in PowerShell
100
-
101
97
if ($Raw ) {
102
98
try {
103
99
Read-XEvent - FileName $file
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ function Watch-DbaXESession {
80
80
$sessionname = $xesession.Name
81
81
Write-Message - Level Verbose - Message " Watching $sessionname on $ ( $server.Name ) ."
82
82
83
- if (-not $xesession.IsRunning -and -not $xesession .IsRunning ) {
83
+ if (-not $xesession.IsRunning ) {
84
84
Stop-Function - Message " $ ( $xesession.Name ) is not running on $ ( $server.Name ) " - Continue
85
85
}
86
86
@@ -103,13 +103,10 @@ function Watch-DbaXESession {
103
103
104
104
try {
105
105
if ($raw ) {
106
- return (SqlServer. XEvent\ Read-SqlXEvent - ConnectionString $server.ConnectionContext.ConnectionString - SessionName $sessionname - ErrorAction Stop)
106
+ return (Read-XEvent - ConnectionString $server.ConnectionContext.ConnectionString - SessionName $sessionname - ErrorAction Stop)
107
107
}
108
108
109
- # use the SqlServer.XEvent\Read-SqlXEvent cmdlet from Microsoft
110
- # because the underlying Class uses Tasks
111
- # which is hard to handle in PowerShell
112
- SqlServer.XEvent\Read-SqlXEvent - ConnectionString $server.ConnectionContext.ConnectionString - SessionName $sessionname - ErrorAction Stop | ForEach-Object - Process {
109
+ Read-XEvent - ConnectionString $server.ConnectionContext.ConnectionString - SessionName $sessionname - ErrorAction Stop | ForEach-Object - Process {
113
110
114
111
$hash = [ordered ]@ { }
115
112
Original file line number Diff line number Diff line change @@ -43,12 +43,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
43
43
}
44
44
Context " Verifying command output" {
45
45
It " returns some results" {
46
- $results = Get-DbaInstanceAudit - SqlInstance $TestConfig.instance2 - Audit LoginAudit | Read-DbaAuditFile - Raw - WarningAction SilentlyContinue
47
- [ System.Linq.Enumerable ]::Count( $results ) -gt 1 | Should Be $true
46
+ $results = Get-DbaInstanceAudit - SqlInstance $TestConfig.instance2 - Audit LoginAudit | Read-DbaAuditFile - Raw
47
+ $results | Should -Not - BeNullOrEmpty
48
48
}
49
49
It " returns some results" {
50
50
$results = Get-DbaInstanceAudit - SqlInstance $TestConfig.instance2 - Audit LoginAudit | Read-DbaAuditFile | Select-Object - First 1
51
- $results.server_principal_name | Should -Not - Be $null
51
+ $results.server_principal_name | Should -Not - BeNullOrEmpty
52
52
}
53
53
}
54
54
}
Original file line number Diff line number Diff line change @@ -16,14 +16,13 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
16
16
17
17
Describe " $CommandName Integration Tests" - Tags " IntegrationTests" {
18
18
Context " Verifying command output" {
19
- # THIS WORKS, I SWEAR
20
19
It " returns some results" {
21
- $results = Get-DbaXESession - SqlInstance $TestConfig.instance2 | Read-DbaXEFile - Raw - WarningAction SilentlyContinue
22
- [ System.Linq.Enumerable ]::Count( $results ) -gt 1 | Should Be $true
20
+ $results = Get-DbaXESession - SqlInstance $TestConfig.instance2 | Read-DbaXEFile - Raw
21
+ $results | Should -Not - BeNullOrEmpty
23
22
}
24
23
It " returns some results" {
25
- $results = Get-DbaXESession - SqlInstance $TestConfig.instance2 | Read-DbaXEFile - WarningAction SilentlyContinue
26
- $results.Count -gt 1 | Should Be $true
24
+ $results = Get-DbaXESession - SqlInstance $TestConfig.instance2 | Read-DbaXEFile
25
+ $results | Should -Not - BeNullOrEmpty
27
26
}
28
27
}
29
28
}
Original file line number Diff line number Diff line change @@ -13,12 +13,19 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
13
13
}
14
14
}
15
15
16
- # This command is special and runs infinitely so don't actually try to run it
17
16
Describe " $CommandName Integration Tests" - Tags " IntegrationTests" {
18
17
Context " Command functions as expected" {
19
- It " warns if SQL instance version is not supported" {
20
- $results = Watch-DbaXESession - SqlInstance $TestConfig.instance1 - Session system_health - WarningAction SilentlyContinue - WarningVariable versionwarn
21
- $versionwarn -join ' ' -match " SQL Server version 11 required" | Should Be $true
18
+ BeforeAll {
19
+ Stop-DbaXESession - SqlInstance $TestConfig.instance2 - Session system_health - EnableException - Confirm:$false
20
+ }
21
+ AfterAll {
22
+ Start-DbaXESession - SqlInstance $TestConfig.instance2 - Session system_health - EnableException - Confirm:$false
23
+ }
24
+
25
+ # This command is special and runs infinitely so don't actually try to run it
26
+ It " warns if XE session is not running" {
27
+ $results = Watch-DbaXESession - SqlInstance $TestConfig.instance2 - Session system_health - WarningAction SilentlyContinue - WarningVariable warn
28
+ $warn | Should -Match ' system_health is not running'
22
29
}
23
30
}
24
31
}
Original file line number Diff line number Diff line change @@ -39,8 +39,6 @@ $TestsRunGroups = @{
39
39
# tests that fail because the command does not work
40
40
' Copy-DbaDbCertificate' ,
41
41
' Export-DbaDacPackage' ,
42
- ' Read-DbaAuditFile' ,
43
- ' Read-DbaXEFile' ,
44
42
# takes too long
45
43
' Install-DbaSqlWatch' ,
46
44
' Uninstall-DbaSqlWatch' ,
You can’t perform that action at this time.
0 commit comments