From d2f43f4b4f4039b4219c2a3afea70d9564fbf7f7 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Wed, 18 Sep 2024 21:27:42 +0200 Subject: [PATCH 01/22] v2.1.24 --- dbatools.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbatools.psd1 b/dbatools.psd1 index 3c516bd65d..43f2aa3c8d 100644 --- a/dbatools.psd1 +++ b/dbatools.psd1 @@ -11,7 +11,7 @@ RootModule = 'dbatools.psm1' # Version number of this module. - ModuleVersion = '2.1.23' + ModuleVersion = '2.1.24' # ID used to uniquely identify this module GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789' From 55e603dbdb61e9a065a4329f13f3387ae2f76590 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Wed, 18 Sep 2024 21:41:49 +0200 Subject: [PATCH 02/22] Diagnostic Query Updates --- .../SQLServerDiagnosticQueries_2012.sql | 2 +- .../SQLServerDiagnosticQueries_2014.sql | 2 +- .../SQLServerDiagnosticQueries_2016.sql | 5 ++--- .../SQLServerDiagnosticQueries_2016SP2.sql | 17 +++++++++++++---- .../SQLServerDiagnosticQueries_2017.sql | 6 +++--- .../SQLServerDiagnosticQueries_2019.sql | 10 ++++++---- .../SQLServerDiagnosticQueries_2022.sql | 6 +++--- 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql index c13dc7dc97..cfbd27dff7 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql @@ -1,7 +1,7 @@ -- SQL Server 2012 Diagnostic Information Queries -- Glenn Berry --- Last Modified: June 14, 2024 +-- Last Modified: September 4, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql index 06e5e1b427..90720bcb13 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql @@ -1,7 +1,7 @@ -- SQL Server 2014 Diagnostic Information Queries -- Glenn Berry --- Last Modified: July 9, 2024 +-- Last Modified: September 4, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql index ad40eb2f06..a8180cac8f 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql @@ -1,7 +1,7 @@ -- SQL Server 2016 Diagnostic Information Queries -- Glenn Berry --- Last Modified: July 9, 2024 +-- Last Modified: September 4, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -2004,8 +2004,7 @@ SELECT es.session_id, DB_NAME(es.database_id) AS [Database Name], FROM sys.dm_exec_sessions AS es WITH (NOLOCK) CROSS APPLY sys.dm_exec_input_buffer(es.session_id, NULL) AS ib WHERE es.database_id = DB_ID() -AND es.session_id > 50 -AND es.session_id <> @@SPID OPTION (RECOMPILE); +AND es.is_user_process = 1 OPTION (RECOMPILE); ------ -- Gives you input buffer information from all non-system sessions for the current database diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql index 67082b2531..e2329237f2 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql @@ -1,7 +1,7 @@ -- SQL Server 2016 SP2 Diagnostic Information Queries -- Glenn Berry --- Last Modified: July 9, 2024 +-- Last Modified: September 11, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -85,13 +85,23 @@ SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version In -- 13.0.5865.1 SP2 CU15 + Security Update 1/12/2021 https://support.microsoft.com/en-us/help/4583461/kb4583461-security-update-for-sql-server-2016-sp2-cu15 -- 13.0.5882.1 SP2 CU16 2/11/2021 https://support.microsoft.com/en-us/office/kb5000645-cumulative-update-16-for-sql-server-2016-sp2-a3997fa9-ec49-4df0-bcc3-12dd58b78265 -- 13.0.5888.11 SP2 CU17 3/29/2021 https://support.microsoft.com/en-us/topic/kb5001092-cumulative-update-17-for-sql-server-2016-sp2-5876a4d6-59ac-484a-93dc-4be456cd87d1 + +-- SP3 Builds -- 13.0.6300.2 SP3 RTM 9/15/2021 https://support.microsoft.com/en-us/topic/kb5003279-sql-server-2016-service-pack-3-release-information-46ab9543-5cf9-464d-bd63-796279591c31 -- 13.0.6404.1 SP3 Hotfix 10/28/2021 https://support.microsoft.com/en-us/topic/kb5006943-on-demand-hotfix-update-package-for-sql-server-2016-sp3-94de2975-cd7d-47ed-b003-5d7daf4e2caf -- 13.0.6419.1 SP3 + GDR 6/14/2022 https://support.microsoft.com/en-us/topic/kb5014355-description-of-the-security-update-for-sql-server-2016-sp3-gdr-june-14-2022-bb5097a0-f8f1-4d2c-bfe1-af069ca3cc59 +-- 13.0.6430.49 SP3 + GDR 3/2/2023 https://support.microsoft.com/en-us/topic/kb5021129-description-of-the-security-update-for-sql-server-2016-sp3-gdr-february-14-2023-1a592815-9dc4-434b-9fb2-119339251317 +-- 13.0.6435.1 SP3 + GDR 10/10/2023 https://support.microsoft.com/en-us/topic/kb5029186-description-of-the-security-update-for-sql-server-2016-sp3-gdr-october-10-2023-618b034a-d575-48e0-804a-7b481ba2e600 +-- 13.0.6441.1 SP3 + GDR 7/9/2024 https://support.microsoft.com/en-us/topic/kb5040946-description-of-the-security-update-for-sql-server-2016-sp3-gdr-july-9-2024-e943f6a8-7a97-41b4-804c-c52ca775f5dd +-- 13.0.6445.1 SP3 + GDR 9/10/2024 https://support.microsoft.com/en-us/topic/kb5042207-description-of-the-security-update-for-sql-server-2016-sp3-gdr-september-10-2024-e27a41df-009d-4a50-85e7-dc8f06b9a5a5 + +-- Azure Connect Pack Builds +-- 13.0.7000.253 Azure Connect Pack 5/19/2022 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2016/servicepack3-azureconnect -- 13.0.7016.1 Azure Connect Pack + GDR 6/14/2022 https://support.microsoft.com/en-us/topic/kb5015371-description-of-the-security-update-for-sql-server-2016-sp3-azure-connect-feature-pack-june-14-2022-d809657e-15a9-48fe-bd19-a8864ac5d3a4 -- 13.0.7024.30 Azure Connect Pack + GDR 2/14/2023 https://support.microsoft.com/en-us/topic/kb5021128-description-of-the-security-update-for-sql-server-2016-sp3-azure-connect-feature-pack-february-14-2023-89e54794-460a-41bd-981f-998290e7d46e -- 13.0.7029.3 Azure Connect Pack + GDR 10/10/2023 https://support.microsoft.com/en-us/topic/kb5029187-description-of-the-security-update-for-sql-server-2016-sp3-azure-connect-feature-pack-october-10-2023-e5541468-f243-4000-872c-ac782cfad99f --- 13.0.7037.1 Azure Connect Pack + GDR 7/9/2024 https://support.microsoft.com/en-us/topic/kb5040944-description-of-the-security-update-for-sql-server-2016-sp3-azure-connect-feature-pack-july-9-2024-72b636c9-0619-4c44-b263-f3d7478bcd75 +-- 13.0.7037.1 Azure Connect Pack + GDR 7/9/2024 https://support.microsoft.com/en-us/topic/kb5040944-description-of-the-security-update-for-sql-server-2016-sp3-azure-connect-feature-pack-july-9-2024-72b636c9-0619-4c44-b263-f3d7478bcd75 +-- 13.0.7040.1 Azure Connect Pack + GDR 9/10/2024 https://support.microsoft.com/en-us/topic/kb5042207-description-of-the-security-update-for-sql-server-2016-sp3-gdr-september-10-2024-e27a41df-009d-4a50-85e7-dc8f06b9a5a5 -- How to determine the version, edition and update level of SQL Server and its components -- https://bit.ly/2oAjKgW @@ -2027,8 +2037,7 @@ SELECT es.session_id, DB_NAME(es.database_id) AS [Database Name], FROM sys.dm_exec_sessions AS es WITH (NOLOCK) CROSS APPLY sys.dm_exec_input_buffer(es.session_id, NULL) AS ib WHERE es.database_id = DB_ID() -AND es.session_id > 50 -AND es.session_id <> @@SPID OPTION (RECOMPILE); +AND es.is_user_process = 1 OPTION (RECOMPILE); ------ -- Gives you input buffer information from all non-system sessions for the current database diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2017.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2017.sql index cf5d15bf50..d9bbbd121e 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2017.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2017.sql @@ -1,7 +1,7 @@ -- SQL Server 2017 Diagnostic Information Queries -- Glenn Berry --- Last Modified: July 10, 2024 +-- Last Modified: September 11, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -107,6 +107,7 @@ SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version In -- 14.0.3460.9 CU31 + GDR 2/14/2023 https://support.microsoft.com/en-us/topic/kb5021126-description-of-the-security-update-for-sql-server-2017-cu31-february-14-2023-2867280f-e66f-4598-a2f1-3d301e367683 -- 14.0.3465.1 CU31 + GDR 10/10/2023 https://support.microsoft.com/en-us/topic/kb5029376-description-of-the-security-update-for-sql-server-2017-cu31-october-10-2023-ce23ddf7-b79e-4ba7-ba9d-2679f23a1ad8 -- 14.0.3471.2 CU31 + GDR 7/9/2024 https://support.microsoft.com/en-us/topic/kb5040940-description-of-the-security-update-for-sql-server-2017-cu31-july-9-2024-bff7ab26-e882-4419-aebb-30356125f5c9 +-- 14.0.3475.1 CU31 + GDR 9/10/2024 https://support.microsoft.com/en-us/topic/kb5042215-description-of-the-security-update-for-sql-server-2017-cu31-september-10-2024-55bba26f-548d-466c-9c48-edfb51a53a8a -- How to determine the version, edition and update level of SQL Server and its components -- https://bit.ly/2oAjKgW @@ -2063,8 +2064,7 @@ SELECT es.session_id, DB_NAME(es.database_id) AS [Database Name], FROM sys.dm_exec_sessions AS es WITH (NOLOCK) CROSS APPLY sys.dm_exec_input_buffer(es.session_id, NULL) AS ib WHERE es.database_id = DB_ID() -AND es.session_id > 50 -AND es.session_id <> @@SPID OPTION (RECOMPILE); +AND es.is_user_process = 1 OPTION (RECOMPILE); ------ -- Gives you input buffer information from all non-system sessions for the current database diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql index 0134d8e8de..2fcda6e014 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql @@ -1,7 +1,7 @@ -- SQL Server 2019 Diagnostic Information Queries -- Glenn Berry --- Last Modified: July 9, 2024 +-- Last Modified: September 11, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -102,7 +102,10 @@ SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version In -- 15.0.4360.2 CU25 + GDR 4/9/2024 https://support.microsoft.com/en-us/topic/kb5036335-description-of-the-security-update-for-sql-server-2019-cu25-april-9-2024-eb3571d0-62ee-445e-9681-5715caf9bbc2 -- 15.0.4365.2 CU26 4/11/2024 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2019/cumulativeupdate26 -- 15.0.4375.4 CU27 6/13/2024 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2019/cumulativeupdate27 --- 15.0.8382.1 CU27 + GDR 7/9/2024 https://support.microsoft.com/en-us/topic/kb5040948-description-of-the-security-update-for-sql-server-2019-cu27-july-9-2024-6447dc00-9f1b-484c-9d3d-9e1f1b9f915c +-- 15.0.4382.1 CU27 + GDR 7/9/2024 https://support.microsoft.com/en-us/topic/kb5040948-description-of-the-security-update-for-sql-server-2019-cu27-july-9-2024-6447dc00-9f1b-484c-9d3d-9e1f1b9f915c +-- 15.0.4385.2 CU28 8/1/2024 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2019/cumulativeupdate28 +-- 15.0.4390.2 CU28 + GDR 9/10/2024 https://support.microsoft.com/en-us/topic/kb5042749-description-of-the-security-update-for-sql-server-2019-cu28-september-10-2024-17402ce5-07d3-4e30-9037-9ef997104f34 + -- How to determine the version, edition and update level of SQL Server and its components -- https://bit.ly/2oAjKgW @@ -2173,8 +2176,7 @@ SELECT es.session_id, DB_NAME(es.database_id) AS [Database Name], FROM sys.dm_exec_sessions AS es WITH (NOLOCK) CROSS APPLY sys.dm_exec_input_buffer(es.session_id, NULL) AS ib WHERE es.database_id = DB_ID() -AND es.session_id > 50 -AND es.session_id <> @@SPID OPTION (RECOMPILE); +AND es.is_user_process = 1 OPTION (RECOMPILE); ------ -- Gives you input buffer information from all non-system sessions for the current database diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql index 4fae6f54ec..662389b98b 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql @@ -1,7 +1,7 @@ -- SQL Server 2022 Diagnostic Information Queries -- Glenn Berry --- Last Modified: July 24, 2024 +-- Last Modified: September 11, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -82,6 +82,7 @@ SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version In -- 16.0.4125.3 CU13 5/16/2024 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate13 -- 16.0.4131.2 CU13 + GDR 7/9/2024 https://support.microsoft.com/en-us/topic/kb5040939-description-of-the-security-update-for-sql-server-2022-cu13-july-9-2024-16a61a81-926c-46a5-b6c0-edbca541f2f6 -- 16.0.4135.4 CU14 7/23/2024 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate14 +-- 16.0.4140.3 CU14 + GDR 9/10/2024 https://support.microsoft.com/en-us/topic/kb5042578-description-of-the-security-update-for-sql-server-2022-cu14-september-10-2024-560e6e4c-1f49-4c18-9eb7-054e9fdee3c7 -- What's new in SQL Server 2022 (16.x) -- https://bit.ly/3MJEjR1 @@ -2246,8 +2247,7 @@ SELECT es.session_id, DB_NAME(es.database_id) AS [Database Name], FROM sys.dm_exec_sessions AS es WITH (NOLOCK) CROSS APPLY sys.dm_exec_input_buffer(es.session_id, NULL) AS ib WHERE es.database_id = DB_ID() -AND es.session_id > 50 -AND es.session_id <> @@SPID OPTION (RECOMPILE); +AND es.is_user_process = 1 OPTION (RECOMPILE); ------ -- Gives you input buffer information from all non-system sessions for the current database From 49f7514b4476d51d875168ad6f3e5465fdf20655 Mon Sep 17 00:00:00 2001 From: Mikey Bronowski Date: Tue, 1 Oct 2024 16:14:46 +0100 Subject: [PATCH 03/22] buildref SQL Server 2022 CU15 (#9476) --- bin/dbatools-buildref-index.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/dbatools-buildref-index.json b/bin/dbatools-buildref-index.json index 5b5f873ab5..f543195d59 100644 --- a/bin/dbatools-buildref-index.json +++ b/bin/dbatools-buildref-index.json @@ -1,5 +1,5 @@ { - "LastUpdated": "2024-09-11T00:00:00", + "LastUpdated": "2024-09-26T00:00:00", "Data": [ { "Version": "8.0.47", @@ -4767,6 +4767,11 @@ { "Version": "16.0.4140", "KBList": "5042578" + }, + { + "CU": "CU15", + "Version": "16.0.4145", + "KBList": "5041321" } ] } From 90ec3299e1c9399e237009f943d0867890297ef3 Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Sat, 5 Oct 2024 19:43:39 +0200 Subject: [PATCH 04/22] Update tests to be able to run them outside of AppVeyor (part 3) (#9426) --- tests/Add-DbaDbMirrorMonitor.Tests.ps1 | 3 ++ tests/Copy-DbaAgentJob.Tests.ps1 | 11 +++-- tests/Copy-DbaBackupDevice.Tests.ps1 | 1 + tests/Copy-DbaDatabase.Tests.ps1 | 3 ++ tests/Export-DbaBinaryFile.Tests.ps1 | 2 +- tests/Export-DbaXESessionTemplate.Tests.ps1 | 5 ++- tests/Find-DbaAgentJob.Tests.ps1 | 42 ++++++++++++------- tests/Find-DbaTrigger.Tests.ps1 | 14 ------- tests/Get-DbaBackupInformation.Tests.ps1 | 3 +- tests/Get-DbaDbCompatibility.Tests.ps1 | 5 ++- tests/Get-DbaDump.Tests.ps1 | 1 + tests/Get-DbaLastGoodCheckDb.Tests.ps1 | 2 +- tests/Get-DbaPermission.Tests.ps1 | 3 -- ...-DbaPfDataCollectorCounterSample.Tests.ps1 | 3 -- tests/Install-DbaAgentAdminAlert.Tests.ps1 | 4 +- tests/Invoke-DbaBalanceDataFiles.Tests.ps1 | 6 +-- tests/Invoke-DbaDiagnosticQuery.Tests.ps1 | 4 +- tests/Measure-DbaBackupThroughput.Tests.ps1 | 13 +++--- tests/New-DbaDbMasterKey.Tests.ps1 | 2 +- tests/Restore-DbaDatabase.Tests.ps1 | 7 +++- tests/Set-DbaErrorLogConfig.Tests.ps1 | 4 -- tests/Start-DbaEndpoint.Tests.ps1 | 3 ++ tests/Stop-DbaEndpoint.Tests.ps1 | 3 ++ tests/Sync-DbaLoginPermission.Tests.ps1 | 2 +- tests/Test-DbaLastBackup.Tests.ps1 | 7 ++-- 25 files changed, 81 insertions(+), 72 deletions(-) diff --git a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 index 463827e691..f0b2ad6848 100644 --- a/tests/Add-DbaDbMirrorMonitor.Tests.ps1 +++ b/tests/Add-DbaDbMirrorMonitor.Tests.ps1 @@ -17,6 +17,9 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $null = Remove-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue } + AfterAll { + $null = Remove-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue + } It "adds the mirror monitor" { $results = Add-DbaDbMirrorMonitor -SqlInstance $script:instance2 -WarningAction SilentlyContinue diff --git a/tests/Copy-DbaAgentJob.Tests.ps1 b/tests/Copy-DbaAgentJob.Tests.ps1 index bc231e00c6..aeb6367215 100644 --- a/tests/Copy-DbaAgentJob.Tests.ps1 +++ b/tests/Copy-DbaAgentJob.Tests.ps1 @@ -21,15 +21,16 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $destjobs = Get-DbaAgentJob -SqlInstance $script:instance3 } AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2, $script:instance3 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false + $null = Remove-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_copyjob, dbatoolsci_copyjob_disabled -Confirm:$false } Context "Command copies jobs properly" { $results = Copy-DbaAgentJob -Source $script:instance2 -Destination $script:instance3 -Job dbatoolsci_copyjob It "returns one success" { - $results.Name -eq "dbatoolsci_copyjob" - $results.Status -eq "Successful" + $results.Name | Should -Be "dbatoolsci_copyjob" + $results.Status | Should -Be "Successful" } It "did not copy dbatoolsci_copyjob_disabled" { @@ -38,7 +39,9 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { It "disables jobs when requested" { (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob_disabled).Enabled - $results = Copy-DbaAgentJob -Source $script:instance2 -Destination $script:instance3 -Job dbatoolsci_copyjob_disabled -DisableOnSource -DisableOnDestination + $results = Copy-DbaAgentJob -Source $script:instance2 -Destination $script:instance3 -Job dbatoolsci_copyjob_disabled -DisableOnSource -DisableOnDestination -Force + $results.Name | Should -Be "dbatoolsci_copyjob_disabled" + $results.Status | Should -Be "Successful" (Get-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_copyjob_disabled).Enabled | Should -Be $false (Get-DbaAgentJob -SqlInstance $script:instance3 -Job dbatoolsci_copyjob_disabled).Enabled | Should -Be $false } diff --git a/tests/Copy-DbaBackupDevice.Tests.ps1 b/tests/Copy-DbaBackupDevice.Tests.ps1 index eac4f6ad8a..70d7ba6260 100644 --- a/tests/Copy-DbaBackupDevice.Tests.ps1 +++ b/tests/Copy-DbaBackupDevice.Tests.ps1 @@ -32,6 +32,7 @@ if (-not $env:appveyor) { } catch { # don't care } + Get-ChildItem -Path $backupfilename | Remove-Item } $results = Copy-DbaBackupDevice -Source $script:instance1 -Destination $script:instance2 -WarningVariable warn -WarningAction SilentlyContinue 3> $null diff --git a/tests/Copy-DbaDatabase.Tests.ps1 b/tests/Copy-DbaDatabase.Tests.ps1 index 3a071e937a..a85b00c3e9 100644 --- a/tests/Copy-DbaDatabase.Tests.ps1 +++ b/tests/Copy-DbaDatabase.Tests.ps1 @@ -206,6 +206,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $results[0].DestinationDatabase | Should -Be $newname $files = Get-DbaDbFile -Sqlinstance $script:instance3 -Database $newname ($files.PhysicalName -like "*$newname*").count | Should -Be $files.count + $null = Remove-DbaDatabase -SqlInstance $script:instance3 -Database $newname } It "Should prefix databasename and files" { @@ -214,12 +215,14 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $results[0].DestinationDatabase | Should -Be "$prefix$backuprestoredb" $files = Get-DbaDbFile -Sqlinstance $script:instance3 -Database "$prefix$backuprestoredb" ($files.PhysicalName -like "*$prefix$backuprestoredb*").count | Should -Be $files.count + $null = Remove-DbaDatabase -SqlInstance $script:instance3 -Database "$prefix$backuprestoredb" } $null = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\RestoreTimeClean2016 -useDestinationDefaultDirectories It "Should warn and exit if newname and >1 db specified" { $null = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb, RestoreTimeClean -DetachAttach -Reattach -NewName warn -WarningVariable warnvar 3> $null $warnvar | Should -BeLike "*Cannot use NewName when copying multiple databases" + $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database RestoreTimeClean } } diff --git a/tests/Export-DbaBinaryFile.Tests.ps1 b/tests/Export-DbaBinaryFile.Tests.ps1 index 03ae68877f..0150b54102 100644 --- a/tests/Export-DbaBinaryFile.Tests.ps1 +++ b/tests/Export-DbaBinaryFile.Tests.ps1 @@ -17,7 +17,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeEach { $db = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb $null = $db.Query("CREATE TABLE [dbo].[BunchOFilezz]([FileName123] [nvarchar](50) NULL, [TheFile123] [image] NULL)") - $null = Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFilezz -FilePath $script:appveyorlabrepo\azure\adalsql.msi -Verbose + $null = Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFilezz -FilePath $script:appveyorlabrepo\azure\adalsql.msi $null = Get-ChildItem $script:appveyorlabrepo\certificates | Import-DbaBinaryFile -SqlInstance $script:instance2 -Database tempdb -Table BunchOFilezz } AfterEach { diff --git a/tests/Export-DbaXESessionTemplate.Tests.ps1 b/tests/Export-DbaXESessionTemplate.Tests.ps1 index 27fb416f19..1b1ad8d5f9 100644 --- a/tests/Export-DbaXESessionTemplate.Tests.ps1 +++ b/tests/Export-DbaXESessionTemplate.Tests.ps1 @@ -14,8 +14,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { + BeforeAll { + $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession + } AfterAll { - $null = Get-DbaXESession -SqlInstance $script:instance2 -Session db_ola_health | Remove-DbaXESession + $null = Get-DbaXESession -SqlInstance $script:instance2 -Session 'Profiler TSQL Duration' | Remove-DbaXESession Remove-Item -Path 'C:\windows\temp\Profiler TSQL Duration.xml' -ErrorAction SilentlyContinue } Context "Test Importing Session Template" { diff --git a/tests/Find-DbaAgentJob.Tests.ps1 b/tests/Find-DbaAgentJob.Tests.ps1 index ebc648c06d..2977d35cc7 100644 --- a/tests/Find-DbaAgentJob.Tests.ps1 +++ b/tests/Find-DbaAgentJob.Tests.ps1 @@ -13,20 +13,28 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } } -Describe "$commandname Integration Tests" -Tags "IntegrationTests" { - BeforeAll { - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa' - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $script:instance2 -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -DatabaseUser sa -RetryAttempts 1 -RetryInterval 2 - $null = Start-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' - $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci_job_category' -CategoryType LocalJob - $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob_disabled' -Category 'dbatoolsci_job_category' -Disabled - $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob_disabled' -StepId 1 -StepName 'dbatoolsci Test Step' -Subsystem TransactSql -SubsystemServer $script:instance2 -Command 'SELECT * FROM master.sys.all_columns' -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -DatabaseUser sa -RetryAttempts 1 -RetryInterval 2 - } - AfterAll { - $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false - $null = Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci_job_category' -Confirm:$false - } +Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { + Context "Command finds jobs using all parameters" { + BeforeAll { + #subsystemServer needs the real underlying name, and it doesn't work if targeting something like localhost\namedinstance + # the typical error would be WARNING: [17:19:26][New-DbaAgentJobStep] Something went wrong creating the job step | The specified '@server' is + #invalid (valid values are returned by sp_helpserver). + $srvName = Invoke-DbaQuery -SqlInstance $script:instance2 -Query "select @@servername as sn" -as PSObject + $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa' + $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 + $null = Start-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' + $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -OwnerLogin 'sa' + $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob' -StepId 1 -StepName 'dbatoolsci Failed' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command "RAISERROR (15600,-1,-1, 'dbatools_error');" -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 + $null = New-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci_job_category' -CategoryType LocalJob + $null = New-DbaAgentJob -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob_disabled' -Category 'dbatoolsci_job_category' -Disabled + $null = New-DbaAgentJobStep -SqlInstance $script:instance2 -Job 'dbatoolsci_testjob_disabled' -StepId 1 -StepName 'dbatoolsci Test Step' -Subsystem TransactSql -SubsystemServer $srvName.sn -Command 'SELECT * FROM master.sys.all_columns' -CmdExecSuccessCode 0 -OnSuccessAction QuitWithSuccess -OnFailAction QuitWithFailure -Database master -RetryAttempts 1 -RetryInterval 2 + } + AfterAll { + $null = Remove-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob, dbatoolsci_testjob_disabled -Confirm:$false + $null = Remove-DbaAgentJobCategory -SqlInstance $script:instance2 -Category 'dbatoolsci_job_category' -Confirm:$false + } + $results = Find-DbaAgentJob -SqlInstance $script:instance2 -Job dbatoolsci_testjob It "Should find a specific job" { $results.name | Should Be "dbatoolsci_testjob" @@ -55,9 +63,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It "Should find jobs that have not been scheduled" { $results | Should not be null } - $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsNotScheduled - It "Should find 11 jobs that have no schedule" { - $results.count | Should be 13 + $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsNotScheduled -Job *dbatoolsci* + It "Should find 2 jobs that have no schedule" { + $results.count | Should be 2 } $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsNoEmailNotification It "Should find jobs that have no email notification" { @@ -71,6 +79,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It "Should find jobs that are owned by sa" { $results | Should not be null } + + $results = Find-DbaAgentJob -SqlInstance $script:instance2 -IsFailed -Since '2016-07-01 10:47:00' It "Should find jobs that have been failed since July of 2016" { $results | Should not be null diff --git a/tests/Find-DbaTrigger.Tests.ps1 b/tests/Find-DbaTrigger.Tests.ps1 index a7b1106d45..523f245e77 100644 --- a/tests/Find-DbaTrigger.Tests.ps1 +++ b/tests/Find-DbaTrigger.Tests.ps1 @@ -2,20 +2,6 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" -Describe "$CommandName Unit Tests" -Tag 'UnitTests' { - Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'ExcludeDatabase', 'Pattern', 'TriggerLevel', 'IncludeSystemObjects', 'IncludeSystemDatabases', 'EnableException' - $knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters - It "Should only contain our specific parameters" { - (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0 - } - } -} -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" - Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } diff --git a/tests/Get-DbaBackupInformation.Tests.ps1 b/tests/Get-DbaBackupInformation.Tests.ps1 index 6e1ba343d5..42f271320f 100644 --- a/tests/Get-DbaBackupInformation.Tests.ps1 +++ b/tests/Get-DbaBackupInformation.Tests.ps1 @@ -61,8 +61,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } AfterAll { - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname | Remove-DbaDatabase -Confirm:$false - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname2 | Remove-DbaDatabase -Confirm:$false + $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbname, $dbname2, $dbname3 | Remove-DbaDatabase -Confirm:$false } Context "Get history for all database" { diff --git a/tests/Get-DbaDbCompatibility.Tests.ps1 b/tests/Get-DbaDbCompatibility.Tests.ps1 index 237d02b07b..50e7dcabdc 100644 --- a/tests/Get-DbaDbCompatibility.Tests.ps1 +++ b/tests/Get-DbaDbCompatibility.Tests.ps1 @@ -25,7 +25,10 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Foreach ($row in $results) { It "Should return correct compatibility level for $($row.database)" { - $row.Compatibility | Should Be $compatibilityLevel + # Only test system databases as there might be leftover databases from other tests + if ($row.DatabaseId -le 4) { + $row.Compatibility | Should Be $compatibilityLevel + } $row.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database $row.Database).Id } } diff --git a/tests/Get-DbaDump.Tests.ps1 b/tests/Get-DbaDump.Tests.ps1 index ea8d795bab..bff375274a 100644 --- a/tests/Get-DbaDump.Tests.ps1 +++ b/tests/Get-DbaDump.Tests.ps1 @@ -20,6 +20,7 @@ if (-not $env:appveyor) { BeforeAll { $server = Connect-DbaInstance -SqlInstance $script:instance1 $server.Query("DBCC STACKDUMP") + Start-Sleep -Seconds 5 } $results = Get-DbaDump -SqlInstance $script:instance1 diff --git a/tests/Get-DbaLastGoodCheckDb.Tests.ps1 b/tests/Get-DbaLastGoodCheckDb.Tests.ps1 index 6da4545e62..8464a5913f 100644 --- a/tests/Get-DbaLastGoodCheckDb.Tests.ps1 +++ b/tests/Get-DbaLastGoodCheckDb.Tests.ps1 @@ -22,7 +22,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $db.Query("DBCC CHECKDB") } AfterAll { - $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $dbname -confirm:$false + $null = Remove-DbaDatabase -SqlInstance $script:instance1 -Database $dbname -confirm:$false } Context "Command actually works" { $results = Get-DbaLastGoodCheckDb -SqlInstance $script:instance1 -Database master diff --git a/tests/Get-DbaPermission.Tests.ps1 b/tests/Get-DbaPermission.Tests.ps1 index d3c5f16200..013455502f 100644 --- a/tests/Get-DbaPermission.Tests.ps1 +++ b/tests/Get-DbaPermission.Tests.ps1 @@ -64,9 +64,6 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $null = Invoke-DbaQuery -SqlInstance $server -Database $dbName -Query "GRANT CONTROL ON Schema::$schemaNameForTable2 TO $loginNameUser2" $table2 = New-DbaDbTable -SqlInstance $server -Database $dbName -Name $tableName2 -Schema $schemaNameForTable2 -ColumnMap $tableSpec2 - - # debugging errors seen only in AppVeyor - Write-Host "Get-DbaPermission: Server=$server, dbName=$dbName, loginDBO=$($loginDBO.Name), loginDBOwner=$($loginDBOwner.Name), loginUser1=$($loginUser1.Name), newUserDBOwner=$($newUserDBOwner.Name), newUser1=$($newUser1.Name), table1=$($table1.Name), loginUser2=$($loginUser2.Name), newUser2=$($newUser2.Name), table2=$($table2.Name), table2Schema=$($table2.Schema)" } AfterAll { diff --git a/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 b/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 index 6d82df9077..d3fa5dcda6 100644 --- a/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 +++ b/tests/Get-DbaPfDataCollectorCounterSample.Tests.ps1 @@ -12,9 +12,6 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } } } -$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") -Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan -. "$PSScriptRoot\constants.ps1" Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verifying command works" { diff --git a/tests/Install-DbaAgentAdminAlert.Tests.ps1 b/tests/Install-DbaAgentAdminAlert.Tests.ps1 index 0a4fdce549..d52a7903e4 100644 --- a/tests/Install-DbaAgentAdminAlert.Tests.ps1 +++ b/tests/Install-DbaAgentAdminAlert.Tests.ps1 @@ -15,9 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeEach { - if ($Env:appveyor) { - Get-DbaAgentAlert -SqlInstance $script:instance2, $script:instance3 | Remove-DbaAgentAlert -Confirm:$false - } + Get-DbaAgentAlert -SqlInstance $script:instance2, $script:instance3 | Remove-DbaAgentAlert -Confirm:$false } Context 'Creating a new SQL Server Agent alert' { $parms = @{ diff --git a/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 b/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 index ee7ee89c1c..c34d92548b 100644 --- a/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 +++ b/tests/Invoke-DbaBalanceDataFiles.Tests.ps1 @@ -34,12 +34,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $db = Get-DbaDatabase -SqlInstance $server -Database $dbname # Create the tables - $db.Query("CREATE TABLE table1 (ID1 INT IDENTITY PRIMARY KEY, Name1 varchar(100))") - $db.Query("CREATE TABLE table2 (ID1 INT IDENTITY PRIMARY KEY, Name2 varchar(100))") + $db.Query("CREATE TABLE table1 (ID1 INT IDENTITY PRIMARY KEY, Name1 char(100))") + $db.Query("CREATE TABLE table2 (ID1 INT IDENTITY PRIMARY KEY, Name2 char(100))") # Generate the values $sqlvalues = New-Object System.Collections.ArrayList - 1 .. 1000 | ForEach-Object { $null = $sqlvalues.Add("('some value to test the balance command $_')") } + 1 .. 1000 | ForEach-Object { $null = $sqlvalues.Add("('some value')") } $db.Query("insert into table1 (Name1) Values $($sqlvalues -join ',')") $db.Query("insert into table1 (Name1) Values $($sqlvalues -join ',')") diff --git a/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 b/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 index 2a2f573af4..4ba3d6ad9d 100644 --- a/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 +++ b/tests/Invoke-DbaDiagnosticQuery.Tests.ps1 @@ -62,11 +62,11 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { @($results | Where-Object {$_.Database -eq $Database2}).Count | Should -Be 0 } It "Correctly excludes queries when QueryName and ExcludeQuery parameters are used" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'Version Info', 'Core Counts', 'Server Properties' -ExcludeQuery 'Core Counts' -WhatIf + $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -QueryName 'Version Info', 'Core Counts', 'Server Properties' -ExcludeQuery 'Core Counts' @($results).Count | Should be 2 } It "Correctly excludes queries when only ExcludeQuery parameter is used" { - $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExcludeQuery "Missing Index Warnings", "Buffer Usage" -whatif + $results = Invoke-DbaDiagnosticQuery -SqlInstance $script:instance2 -ExcludeQuery "Missing Index Warnings", "Buffer Usage" @($results).Count | Should -BeGreaterThan 0 @($results | Where-Object Name -eq "Missing Index Warnings").Count | Should be 0 @($results | Where-Object Name -eq "Buffer Usage").Count | Should be 0 diff --git a/tests/Measure-DbaBackupThroughput.Tests.ps1 b/tests/Measure-DbaBackupThroughput.Tests.ps1 index dc3a2a8053..ca4df9fba2 100644 --- a/tests/Measure-DbaBackupThroughput.Tests.ps1 +++ b/tests/Measure-DbaBackupThroughput.Tests.ps1 @@ -16,19 +16,18 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Returns output for single database" { BeforeAll { - $server = Connect-DbaInstance -SqlInstance $script:instance2 $random = Get-Random $db = "dbatoolsci_measurethruput$random" - $server.Query("CREATE DATABASE $db") - $null = Get-DbaDatabase -SqlInstance $server -Database $db | Backup-DbaDatabase + $null = New-DbaDatabase -SqlInstance $script:instance2 -Database $db | Backup-DbaDatabase } AfterAll { - $null = Get-DbaDatabase -SqlInstance $server -Database $db | Remove-DbaDatabase -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database $db } - $results = Measure-DbaBackupThroughput -SqlInstance $server -Database $db - It "Should return just one backup" { - $results.Database.Count -eq 1 | Should Be $true + $results = Measure-DbaBackupThroughput -SqlInstance $script:instance2 -Database $db + It "Should return results" { + $results.Database | Should -Be $db + $results.BackupCount | Should -Be 1 } } } \ No newline at end of file diff --git a/tests/New-DbaDbMasterKey.Tests.ps1 b/tests/New-DbaDbMasterKey.Tests.ps1 index 6a5845960c..f4e3165e0a 100644 --- a/tests/New-DbaDbMasterKey.Tests.ps1 +++ b/tests/New-DbaDbMasterKey.Tests.ps1 @@ -33,6 +33,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $mastercert = New-DbaDbCertificate -SqlInstance $script:instance1 } $db = New-DbaDatabase -SqlInstance $script:instance1 + $db1 = New-DbaDatabase -SqlInstance $script:instance1 } AfterAll { @@ -58,7 +59,6 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.IsEncryptedByServer | Should -Be $true } It "should create master key on a database" { - $db1 = New-DbaDatabase -SqlInstance $script:instance1 $results = New-DbaDbMasterKey -SqlInstance $script:instance1 -Database $db1.Name -SecurePassword $passwd $results.IsEncryptedByServer | Should -Be $true } diff --git a/tests/Restore-DbaDatabase.Tests.ps1 b/tests/Restore-DbaDatabase.Tests.ps1 index 87bbd3c29d..a3efbcb377 100644 --- a/tests/Restore-DbaDatabase.Tests.ps1 +++ b/tests/Restore-DbaDatabase.Tests.ps1 @@ -859,6 +859,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Should backup and restore cleanly" { ($results | Where-Object { $_.RestoreComplete -eq $True }).count | Should Be $Results.count } + $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database StripeTest } Context "Don't try to create/test folders with OutputScriptOnly (Issue 4046)" { @@ -891,7 +892,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } Remove-DbaDbCertificate -SqlInstance $script:instance2 -Database Master -Certificate RestoreTestCert -Confirm:$false Remove-DbaDbMasterKey -SqlInstance $script:instance2 -Database Master -confirm:$false - Remove-DbaDatabase -SqlInstance $script:instance2 -Database EncRestTest -confirm:$false + Remove-DbaDatabase -SqlInstance $script:instance2 -Database EncRestTest, certEncRestTest -confirm:$false } Context "Test restoring with StopAt" { @@ -901,6 +902,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Should have stoped at mark" { $sqlOut.ms | Should -Be 9876 } + $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database StopAt2 } Context "Test restoring with StopAtBefore" { @@ -910,6 +912,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Should have stoped at mark" { $sqlOut.ms | Should -Be 8764 } + $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database StopAt2 } Context "Test restoring with StopAt and StopAfterDate" { @@ -919,6 +922,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Should have stoped at mark" { $sqlOut.ms | Should -Be 29876 } + $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database StopAt2 } Context "Warn if OutputScriptOnly and VerifyOnly specified together #6987" { @@ -926,6 +930,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It "Should return a warning" { $warnvar | Should -BeLike '*The switches OutputScriptOnly and VerifyOnly cannot both be specified at the same time, stopping' } + $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database StopAt2 } if ($env:azurepasswd) { Context "Restores From Azure using SAS" { diff --git a/tests/Set-DbaErrorLogConfig.Tests.ps1 b/tests/Set-DbaErrorLogConfig.Tests.ps1 index 03ff667663..46d668e9fc 100644 --- a/tests/Set-DbaErrorLogConfig.Tests.ps1 +++ b/tests/Set-DbaErrorLogConfig.Tests.ps1 @@ -56,9 +56,5 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $result.LogSize.Kilobyte | Should Be 100 } } - - It "returns a warning for invalid version" { - $warn2 | Should Match 'not supported' - } } } \ No newline at end of file diff --git a/tests/Start-DbaEndpoint.Tests.ps1 b/tests/Start-DbaEndpoint.Tests.ps1 index a96784b052..211352cb8e 100644 --- a/tests/Start-DbaEndpoint.Tests.ps1 +++ b/tests/Start-DbaEndpoint.Tests.ps1 @@ -17,6 +17,9 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' | Stop-DbaEndpoint -Confirm:$false } + AfterAll { + Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' | Start-DbaEndpoint -Confirm:$false + } It "starts the endpoint" { $endpoint = Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' diff --git a/tests/Stop-DbaEndpoint.Tests.ps1 b/tests/Stop-DbaEndpoint.Tests.ps1 index 6b34d60755..38d9fd9089 100644 --- a/tests/Stop-DbaEndpoint.Tests.ps1 +++ b/tests/Stop-DbaEndpoint.Tests.ps1 @@ -17,6 +17,9 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' | Start-DbaEndpoint } + AfterAll { + Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' | Start-DbaEndpoint + } It "stops the endpoint" { $endpoint = Get-DbaEndpoint -SqlInstance $script:instance2 -Endpoint 'TSQL Default TCP' diff --git a/tests/Sync-DbaLoginPermission.Tests.ps1 b/tests/Sync-DbaLoginPermission.Tests.ps1 index 331884e782..3e57eae00c 100644 --- a/tests/Sync-DbaLoginPermission.Tests.ps1 +++ b/tests/Sync-DbaLoginPermission.Tests.ps1 @@ -49,7 +49,7 @@ CREATE LOGIN [$DBUserName] #Creates the user on Invoke-DbaQuery -SqlInstance $script:instance3 -Query $CreateTestLogin $results = Sync-DbaLoginPermission -Source $script:instance2 -Destination $script:instance3 -Login $DBUserName -ExcludeLogin 'NotaLogin' -Warningvariable $warn - $results | Should -be $null + $results.Status | Should -Be 'Successful' $warn | Should -be $null } diff --git a/tests/Test-DbaLastBackup.Tests.ps1 b/tests/Test-DbaLastBackup.Tests.ps1 index 0731328b86..9675e66805 100644 --- a/tests/Test-DbaLastBackup.Tests.ps1 +++ b/tests/Test-DbaLastBackup.Tests.ps1 @@ -15,13 +15,11 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $dbs = $testlastbackup, "dbatoolsci_lildb", "dbatoolsci_testrestore", "dbatoolsci_singlerestore" - $null = Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbs | Remove-DbaDatabase -Confirm:$false - $server = Connect-DbaInstance -SqlInstance $script:instance1 $random = Get-Random $testlastbackup = "dbatoolsci_testlastbackup$random" $dbs = $testlastbackup, "dbatoolsci_lildb", "dbatoolsci_testrestore", "dbatoolsci_singlerestore" + $server = Connect-DbaInstance -SqlInstance $script:instance1 foreach ($db in $dbs) { $server.Query("CREATE DATABASE $db") $server.Query("ALTER DATABASE $db SET RECOVERY FULL WITH NO_WAIT") @@ -32,7 +30,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } AfterAll { # these for sure - Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbs, "bigtestrest", "smalltestrest" | Remove-DbaDatabase -Confirm:$false + $dbs += "bigtestrest", "smalltestrest" + Get-DbaDatabase -SqlInstance $script:instance1 -Database $dbs | Remove-DbaDatabase -Confirm:$false # those just in case test-dbalastbackup didn't cooperate Get-DbaDatabase -SqlInstance $script:instance1 | Where-Object Name -like 'dbatools-testrestore-dbatoolsci_*' | Remove-DbaDatabase -Confirm:$false # see "Restores using a specific path" From bf8423c04caf5856bcb5b071d0434614491d710e Mon Sep 17 00:00:00 2001 From: Adam Koehler Date: Sat, 5 Oct 2024 12:44:33 -0500 Subject: [PATCH 05/22] Test-DBALsnChain - Fix missing log backup (#7515) (#9467) --- private/functions/Test-DbaLsnChain.ps1 | 45 ++++++++++++----------- tests/Test-DbaBackupInformation.Tests.ps1 | 4 +- tests/Test-DbaLsnChain.Tests.ps1 | 6 +-- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/private/functions/Test-DbaLsnChain.ps1 b/private/functions/Test-DbaLsnChain.ps1 index 559931eb0c..e25e6d8ac1 100644 --- a/private/functions/Test-DbaLsnChain.ps1 +++ b/private/functions/Test-DbaLsnChain.ps1 @@ -83,7 +83,7 @@ function Test-DbaLsnChain { } $DiffAnchor = $TestHistory | Where-Object { $_.$TypeName -in ('Database Differential', 'Differential') } #Check for no more than a single Differential backup - if (($DiffAnchor.FirstLSN | Select-Object -unique | Measure-Object).count -gt 1) { + if (($DiffAnchor.FirstLSN | Select-Object -Unique | Measure-Object).count -gt 1) { Write-Message -Level Warning -Message "More than 1 differential backup, not supported" return $false break; @@ -96,27 +96,30 @@ function Test-DbaLsnChain { #Check T-log LSNs form a chain. - $TranLogBackups = $TestHistory | Where-Object { $_.$TypeName -in ('Transaction Log', 'Log') -and $_.DatabaseBackupLSN -eq $FullDBAnchor.CheckPointLSN } | Sort-Object -Property LastLSN, FirstLsn - for ($i = 0; $i -lt ($TranLogBackups.count)) { - Write-Message -Level Debug -Message "looping t logs" - if ($i -eq 0) { - if ($TranLogBackups[$i].FirstLSN -gt $TlogAnchor.LastLSN) { - Write-Message -Level Warning -Message "Break in LSN Chain between $($TlogAnchor.FullName) and $($TranLogBackups[($i)].FullName) " - Write-Message -Level Verbose -Message "Anchor $($TlogAnchor.LastLSN) - FirstLSN $($TranLogBackups[$i].FirstLSN)" - return $false - break - } - } else { - if ($TranLogBackups[($i - 1)].LastLsn -ne $TranLogBackups[($i)].FirstLSN -and ($TranLogBackups[($i)] -ne $TranLogBackups[($i - 1)])) { - Write-Message -Level Warning -Message "Break in transaction log between $($TranLogBackups[($i-1)].FullName) and $($TranLogBackups[($i)].FullName) " - return $false - break - } - } - $i++ + $TranLogBackups = $TestHistory | Where-Object { + $_.$TypeName -in ('Transaction Log', 'Log') -and (($_.DatabaseBackupLSN.ToString() -eq $FullDBAnchor.CheckPointLSN) -or (($_.DatabaseBackupLSN.ToString() -ne $FullDBAnchor.CheckPointLSN) -and ($TranLogBackups[$i].FirstLSN -gt $FullDBAnchor.CheckPointLSN))) + } | Sort-Object -Property LastLSN, FirstLsn + for ($i = 0; $i -lt ($TranLogBackups.count)) { + Write-Message -Level Debug -Message "looping t logs" + if ($i -eq 0) { + if ($TranLogBackups[$i].FirstLSN.ToString() -gt $TlogAnchor.LastLSN) { + Write-Message -Level Warning -Message "Break in LSN Chain between $($TlogAnchor.FullName) and $($TranLogBackups[($i)].FullName) " + Write-Message -Level Verbose -Message "Anchor $($TlogAnchor.LastLSN) - FirstLSN $($TranLogBackups[$i].FirstLSN)" + return $false + break + } + } else { + if ($TranLogBackups[($i - 1)].LastLsn -ne $TranLogBackups[($i)].FirstLSN -and ($TranLogBackups[($i)] -ne $TranLogBackups[($i - 1)])) { + Write-Message -Level Warning -Message "Break in transaction log between $($TranLogBackups[($i-1)].FullName) and $($TranLogBackups[($i)].FullName) " + return $false + break + } } - Write-Message -Level VeryVerbose -Message "Passed LSN Chain checks" - return $true + $i++ + } + Write-Message -Level VeryVerbose -Message "Passed LSN Chain checks" + return $true +} } \ No newline at end of file diff --git a/tests/Test-DbaBackupInformation.Tests.ps1 b/tests/Test-DbaBackupInformation.Tests.ps1 index c491c399d6..93bbe07d5d 100644 --- a/tests/Test-DbaBackupInformation.Tests.ps1 +++ b/tests/Test-DbaBackupInformation.Tests.ps1 @@ -58,7 +58,7 @@ Describe "$commandname Integration Tests" -Tag 'IntegrationTests' { It "Should pass as all systems Green" { $output = $BackupHistory | Test-DbaBackupInformation -SqlInstance NotExist -WarningVariable warnvar -WarningAction SilentlyContinue ($output.Count) -gt 0 | Should be $true - $false -in ($Output.IsVerified) | Should be $False + "False" -in ($Output.IsVerified) | Should be $False ($null -ne $WarnVar) | Should be $True } } @@ -250,4 +250,4 @@ Describe "$commandname Integration Tests" -Tag 'IntegrationTests' { } } } -} \ No newline at end of file +} diff --git a/tests/Test-DbaLsnChain.Tests.ps1 b/tests/Test-DbaLsnChain.Tests.ps1 index 80f5ac6786..cbead55f62 100644 --- a/tests/Test-DbaLsnChain.Tests.ps1 +++ b/tests/Test-DbaLsnChain.Tests.ps1 @@ -5,11 +5,11 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan Describe "$commandname Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} + [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } [object[]]$knownParameters = 'FilteredRestoreFiles', 'Continue', 'EnableException' $knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters It "Should only contain our specific parameters" { - (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0 + (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0 } } } @@ -22,7 +22,7 @@ Describe "$commandname Integration Tests" -Tag 'IntegrationTests' { $filteredFiles = $header | Select-DbaBackupInformation It "Should Return 7" { - $FilteredFiles.count | should be 7 + $FilteredFiles.count | Should be 7 } It "Should return True" { $Output = Test-DbaLsnChain -FilteredRestoreFiles $FilteredFiles -WarningAction SilentlyContinue From 8539ded3ed0a1437f7495f491abf8fc8c510bf1e Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 5 Oct 2024 19:48:47 +0200 Subject: [PATCH 06/22] Update integration-tests-repl.yml --- .github/workflows/integration-tests-repl.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration-tests-repl.yml b/.github/workflows/integration-tests-repl.yml index c9b7b49f17..f4503fbe8d 100644 --- a/.github/workflows/integration-tests-repl.yml +++ b/.github/workflows/integration-tests-repl.yml @@ -51,7 +51,8 @@ jobs: - name: Run replication tests part 1 run: | Import-Module ./dbatools.psd1 -Force - $null = Invoke-Pester ./tests/gh-actions-repl-1.ps1 -Output Detailed -PassThru -Verbose + # Disabled for now, it's suddenly failing + # $null = Invoke-Pester ./tests/gh-actions-repl-1.ps1 -Output Detailed -PassThru -Verbose repl-tests-part2: runs-on: ubuntu-latest From 4d9fc650030f587a9ada8ecb329f352a3c9f52f3 Mon Sep 17 00:00:00 2001 From: Jianjun Pei <52251330+jianjunpei@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:49:56 -0500 Subject: [PATCH 07/22] Get-DbaHelpIndex - Bad joins based on Index Name instead of Index ID when Indexes in same DB named the same #9447 (#9473) --- public/Get-DbaHelpIndex.ps1 | 14 +++++++------- tests/Get-DbaHelpIndex.Tests.ps1 | 31 ++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/public/Get-DbaHelpIndex.ps1 b/public/Get-DbaHelpIndex.ps1 index 86d44d9cb9..865082a690 100644 --- a/public/Get-DbaHelpIndex.ps1 +++ b/public/Get-DbaHelpIndex.ps1 @@ -404,7 +404,7 @@ function Get-DbaHelpIndex { name AS IndexName , STUFF((SELECT N', ' + ColumnName FROM cteIndex ci2 - WHERE ci2.name = ci.name + WHERE ci2.name = ci.name AND ci2.object_id=ci.object_id AND ci2.is_included_column = 0 GROUP BY ci2.index_column_id , ci2.ColumnName @@ -412,9 +412,9 @@ function Get-DbaHelpIndex { FOR XML PATH(N'') , TYPE).value(N'.[1]', N'nvarchar(1000)'), 1, 2, N'') AS KeyColumns , - ISNULL(STUFF((SELECT N', ' + ColumnName + ISNULL(STUFF((SELECT N', ' + ColumnName FROM cteIndex ci3 - WHERE ci3.name = ci.name + WHERE ci3.name = ci.name AND ci3.object_id=ci.object_id AND ci3.is_included_column = 1 GROUP BY ci3.index_column_id , ci3.ColumnName @@ -801,7 +801,7 @@ function Get-DbaHelpIndex { name AS IndexName , STUFF((SELECT N', ' + ColumnName FROM cteIndex ci2 - WHERE ci2.name = ci.name + WHERE ci2.name = ci.name and ci2.object_id=ci.object_id AND ci2.is_included_column = 0 GROUP BY ci2.index_column_id , ci2.ColumnName @@ -809,9 +809,9 @@ function Get-DbaHelpIndex { FOR XML PATH(N'') , TYPE).value(N'.[1]', N'nvarchar(1000)'), 1, 2, N'') AS KeyColumns , - ISNULL(STUFF((SELECT N', ' + ColumnName + ISNULL(STUFF((SELECT N', ' + ColumnName FROM cteIndex ci3 - WHERE ci3.name = ci.name + WHERE ci3.name = ci.name and ci3.object_id=ci.object_id AND ci3.is_included_column = 1 GROUP BY ci3.index_column_id , ci3.ColumnName @@ -1103,4 +1103,4 @@ function Get-DbaHelpIndex { } } } -} \ No newline at end of file +} diff --git a/tests/Get-DbaHelpIndex.Tests.ps1 b/tests/Get-DbaHelpIndex.Tests.ps1 index 7c5df2491a..f642d4954f 100644 --- a/tests/Get-DbaHelpIndex.Tests.ps1 +++ b/tests/Get-DbaHelpIndex.Tests.ps1 @@ -2,13 +2,14 @@ $CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan . "$PSScriptRoot\constants.ps1" +Write-host -Object "${script:instance2}" -ForegroundColor Cyan Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} + [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'ExcludeDatabase', 'InputObject', 'ObjectName', 'IncludeStats', 'IncludeDataTypes', 'Raw', 'IncludeFragmentation', 'EnableException' $knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters It "Should only contain our specific parameters" { - (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0 + (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0 } } } @@ -22,12 +23,16 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $server.Query("Insert into test values ('value1',1),('value2',2)", $dbname) $server.Query("create statistics dbatools_stats on test (col2)", $dbname) $server.Query("select * from test", $dbname) + $server.Query("create table t1(c1 int,c2 int,c3 int,c4 int)", $dbname) + $server.Query("create nonclustered index idx_1 on t1(c1) include(c3)", $dbname) + $server.Query("create table t2(c1 int,c2 int,c3 int,c4 int)", $dbname) + $server.Query("create nonclustered index idx_1 on t2(c1,c2) include(c3,c4)", $dbname) } AfterAll { $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $dbname | Remove-DbaDatabase -Confirm:$false } Context "Command works for indexes" { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname + $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test It 'Results should be returned' { $results | Should Not BeNullOrEmpty } @@ -42,7 +47,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } Context "Command works when including statistics" { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -IncludeStats | Where-Object {$_.Statistics} + $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -IncludeStats | Where-Object { $_.Statistics } It 'Results should be returned' { $results | Should Not BeNullOrEmpty } @@ -51,7 +56,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } Context "Command output includes data types" { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -IncludeDataTypes + $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -IncludeDataTypes It 'Results should be returned' { $results | Should Not BeNullOrEmpty } @@ -60,7 +65,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } Context "Formatting is correct" { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -IncludeFragmentation + $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -IncludeFragmentation It 'Formatted as strings' { $results.IndexReads | Should BeOfType 'String' $results.IndexUpdates | Should BeOfType 'String' @@ -72,7 +77,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } } Context "Formatting is correct for raw" { - $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -raw -IncludeFragmentation + $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname -ObjectName Test -raw -IncludeFragmentation It 'Formatted as Long' { $results.IndexReads | Should BeOfType 'Long' $results.IndexUpdates | Should BeOfType 'Long' @@ -84,4 +89,16 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $results.IndexFragInPercent | Should BeOfType 'Double' } } + Context "Result is correct for tables having the indexes with the same names" { + $results = Get-DbaHelpIndex -SqlInstance $script:instance2 -Database $dbname + It 'Table t1 has correct index key columns and included columns' { + $results.where({ $_.object -eq '[dbo].[t1]' }).KeyColumns | Should -be 'c1' + $results.where({ $_.object -eq '[dbo].[t1]' }).IncludeColumns | Should -be 'c3' + } + It 'Table t2 has correct index key columns and included columns' { + $results.where({ $_.object -eq '[dbo].[t2]' }).KeyColumns | Should -be 'c1, c2' + $results.where({ $_.object -eq '[dbo].[t2]' }).IncludeColumns | Should -be 'c3, c4' + } + + } } \ No newline at end of file From b58de53585c0e47c4707c586648476abb9feb4a7 Mon Sep 17 00:00:00 2001 From: Simone Bizzotto Date: Sat, 5 Oct 2024 19:50:27 +0200 Subject: [PATCH 08/22] Test-DbaDbCompression, returns ? for empty tables (do Compression) (#9474) --- public/Test-DbaDbCompression.ps1 | 56 +++++++++++++++------------ tests/Test-DbaDbCompression.Tests.ps1 | 21 +++++++--- 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/public/Test-DbaDbCompression.ps1 b/public/Test-DbaDbCompression.ps1 index 5bc764d648..19171772d7 100644 --- a/public/Test-DbaDbCompression.ps1 +++ b/public/Test-DbaDbCompression.ps1 @@ -215,7 +215,6 @@ function Test-DbaDbCompression { sys.schemas s ON t.schema_id = s.schema_id WHERE objectproperty(t.object_id, 'IsUserTable') = 1 AND p.data_compression_desc = 'NONE' - AND p.rows > 0 $sqlSchemaWhere $sqlTableWhere GROUP BY @@ -303,14 +302,15 @@ CREATE TABLE ##TestDbaCompression ( ,[Partition] INT ,[IndexID] INT ,[IndexType] VARCHAR(25) + ,[RowCounts] BIGINT ,[PercentScan] SMALLINT ,[PercentUpdate] SMALLINT ,[RowEstimatePercentOriginal] BIGINT ,[PageEstimatePercentOriginal] BIGINT ,[CompressionTypeRecommendation] VARCHAR(7) - ,SizeCurrent BIGINT - ,SizeRequested BIGINT - ,PercentCompression NUMERIC(10, 2) + ,[SizeCurrent] BIGINT + ,[SizeRequested] BIGINT + ,[PercentCompression] NUMERIC(10, 2) ); CREATE TABLE ##tmpEstimateRow ( @@ -343,6 +343,7 @@ INSERT INTO ##TestDbaCompression ( ,[Partition] ,[IndexID] ,[IndexType] + ,[RowCounts] ,[PercentScan] ,[PercentUpdate] ) @@ -353,6 +354,7 @@ INSERT INTO ##TestDbaCompression ( ,p.partition_number AS [Partition] ,x.Index_ID AS [IndexID] ,x.type_desc AS [IndexType] + ,p.rows AS [RowCounts] ,NULL AS [PercentScan] ,NULL AS [PercentUpdate] FROM sys.tables t @@ -362,7 +364,6 @@ INNER JOIN sys.partitions p ON x.object_id = p.object_id AND x.Index_ID = p.Index_ID WHERE OBJECTPROPERTY(t.object_id, 'IsUserTable') = 1 AND p.data_compression_desc = 'NONE' - AND p.rows > 0 $sqlSchemaWhere $sqlTableWhere ORDER BY [TableName] ASC; @@ -516,27 +517,32 @@ AS ( ,[Schema] ,IndexID ,CASE - WHEN [RowEstimatePercentOriginal] >= 100 - AND [PageEstimatePercentOriginal] >= 100 - THEN 'NO_GAIN' - WHEN [PercentUpdate] >= 10 - THEN 'ROW' - WHEN [PercentScan] <= 1 - AND [PercentUpdate] <= 1 - AND [RowEstimatePercentOriginal] < [PageEstimatePercentOriginal] - THEN 'ROW' - WHEN [PercentScan] <= 1 - AND [PercentUpdate] <= 1 - AND [RowEstimatePercentOriginal] > [PageEstimatePercentOriginal] - THEN 'PAGE' - WHEN [PercentScan] >= 60 - AND [PercentUpdate] <= 5 - THEN 'PAGE' - WHEN [PercentScan] <= 35 - AND [PercentUpdate] <= 5 + WHEN [RowCounts] = 0 THEN '?' - ELSE 'ROW' - END + ELSE + CASE + WHEN [RowEstimatePercentOriginal] >= 100 + AND [PageEstimatePercentOriginal] >= 100 + THEN 'NO_GAIN' + WHEN [PercentUpdate] >= 10 + THEN 'ROW' + WHEN [PercentScan] <= 1 + AND [PercentUpdate] <= 1 + AND [RowEstimatePercentOriginal] < [PageEstimatePercentOriginal] + THEN 'ROW' + WHEN [PercentScan] <= 1 + AND [PercentUpdate] <= 1 + AND [RowEstimatePercentOriginal] > [PageEstimatePercentOriginal] + THEN 'PAGE' + WHEN [PercentScan] >= 60 + AND [PercentUpdate] <= 5 + THEN 'PAGE' + WHEN [PercentScan] <= 35 + AND [PercentUpdate] <= 5 + THEN '?' + ELSE 'ROW' + END + END FROM ##TestDbaCompression ) UPDATE ##TestDbaCompression diff --git a/tests/Test-DbaDbCompression.Tests.ps1 b/tests/Test-DbaDbCompression.Tests.ps1 index f747747f91..9533bc9455 100644 --- a/tests/Test-DbaDbCompression.Tests.ps1 +++ b/tests/Test-DbaDbCompression.Tests.ps1 @@ -20,11 +20,12 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $server = Connect-DbaInstance -SqlInstance $script:instance2 $null = $server.Query("Create Database [$dbname]") $null = $server.Query("Create Schema test", $dbname) - $null = $server.Query(" select * into syscols from sys.all_columns - select * into test.sysallparams from sys.all_parameters - create clustered index CL_sysallparams on test.sysallparams (object_id) - create nonclustered index NC_syscols on syscols (precision) include (collation_name) - update test.sysallparams set is_xml_document = 1 where name = '@dbname' + $null = $server.Query(" select * into syscols from sys.all_columns; + select 1 as col into testtable where 1=0; + select * into test.sysallparams from sys.all_parameters; + create clustered index CL_sysallparams on test.sysallparams (object_id); + create nonclustered index NC_syscols on syscols (precision) include (collation_name); + update test.sysallparams set is_xml_document = 1 where name = '@dbname'; ", $dbname) } AfterAll { @@ -38,7 +39,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } $results.foreach{ It "Should suggest ROW, PAGE or NO_GAIN for $($PSitem.TableName) - $($PSitem.IndexType) " { - $PSitem.CompressionTypeRecommendation | Should BeIn ("ROW", "PAGE", "NO_GAIN") + $PSitem.CompressionTypeRecommendation | Should BeIn ("ROW", "PAGE", "NO_GAIN", "?") } It "Should have values for PercentScan and PercentUpdate $($PSitem.TableName) - $($PSitem.IndexType) " { $PSitem.PercentUpdate | Should Not BeNullOrEmpty @@ -81,4 +82,12 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $results.Count | Should Be $resultCount } } + Context "Returns result for empty table (see #9469)" { + $table = 'testtable' + $results = Test-DbaDbCompression -SqlInstance $script:instance2 -Database $dbname -Table $table + It "Should get results for table:$table" { + $results | Should Not Be $null + $results[0].CompressionTypeRecommendation | Should Be '?' + } + } } \ No newline at end of file From 5fa6bbd4368f8ff47b2464432447558f1a232b27 Mon Sep 17 00:00:00 2001 From: Simone Bizzotto Date: Sat, 5 Oct 2024 19:50:56 +0200 Subject: [PATCH 09/22] Get-DbaDbView, add Schema parameter (do DbView) (#9475) --- public/Get-DbaDbView.ps1 | 9 +++++++++ tests/Get-DbaDbView.Tests.ps1 | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/public/Get-DbaDbView.ps1 b/public/Get-DbaDbView.ps1 index 0c00ce2eee..1b32aeaae9 100644 --- a/public/Get-DbaDbView.ps1 +++ b/public/Get-DbaDbView.ps1 @@ -28,6 +28,9 @@ function Get-DbaDbView { .PARAMETER View The view(s) to include - all views are selected if not populated + .PARAMETER Schema + Only return views from the specified schema + .PARAMETER InputObject Enables piping from Get-DbaDatabase @@ -92,6 +95,7 @@ function Get-DbaDbView { [object[]]$ExcludeDatabase, [switch]$ExcludeSystemView, [string[]]$View, + [string[]]$Schema, [Parameter(ValueFromPipeline)] [Microsoft.SqlServer.Management.Smo.Database[]]$InputObject, [switch]$EnableException @@ -167,6 +171,11 @@ function Get-DbaDbView { Write-Message -Message "No views exist in the $db database on $($db.Parent.DomainInstanceName)" -Target $db -Level Verbose continue } + + if ($Schema) { + $views = $views | Where-Object Schema -in $Schema + } + if (Test-Bound -ParameterName ExcludeSystemView) { $views = $views | Where-Object { -not $_.IsSystemObject } } diff --git a/tests/Get-DbaDbView.Tests.ps1 b/tests/Get-DbaDbView.Tests.ps1 index 28fe0ac930..a7e851c416 100644 --- a/tests/Get-DbaDbView.Tests.ps1 +++ b/tests/Get-DbaDbView.Tests.ps1 @@ -6,7 +6,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { It "Should only contain our specific parameters" { [array]$params = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($CommandName, 'Function')).Parameters.Keys - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'ExcludeDatabase', 'ExcludeSystemView', 'View', 'InputObject', 'EnableException' + [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'ExcludeDatabase', 'ExcludeSystemView', 'View', 'Schema', 'InputObject', 'EnableException' Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params | Should -BeNullOrEmpty } } @@ -16,10 +16,15 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $server = Connect-DbaInstance -SqlInstance $script:instance2 $viewName = ("dbatoolsci_{0}" -f $(Get-Random)) + $viewNameWithSchema = ("dbatoolsci_{0}" -f $(Get-Random)) $server.Query("CREATE VIEW $viewName AS (SELECT 1 as col1)", 'tempdb') + $server.Query("CREATE SCHEMA [someschema]", 'tempdb') + $server.Query("CREATE VIEW [someschema].$viewNameWithSchema AS (SELECT 1 as col1)", 'tempdb') } AfterAll { $null = $server.Query("DROP VIEW $viewName", 'tempdb') + $null = $server.Query("DROP VIEW [someschema].$viewNameWithSchema", 'tempdb') + $null = $server.Query("DROP SCHEMA [someschema]", 'tempdb') } Context "Command actually works" { @@ -59,4 +64,12 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { ($results | Where-Object Name -eq $viewName).Name | Should -Be $viewName } } + + Context "Schema parameter (see #9445)" { + It "Should return just one view with schema 'someschema'" { + $results = $script:instance2 | Get-DbaDbView -Database tempdb -Schema 'someschema' + ($results | Where-Object Name -eq $viewNameWithSchema).Name | Should -Be $viewNameWithSchema + ($results | Where-Object Schema -ne 'someschema').Count | Should -Be 0 + } + } } \ No newline at end of file From 6025137a31c5dfc019f23459751497c720d7228f Mon Sep 17 00:00:00 2001 From: Simone Bizzotto Date: Sat, 5 Oct 2024 19:51:28 +0200 Subject: [PATCH 10/22] Import-DbaCsv, map correct types for BulkCopy (#9479) Co-authored-by: Shawn Melton <11204251+wsmelton@users.noreply.github.com> --- public/Import-DbaCsv.ps1 | 200 +++++++++++++++++++++++++++++++--- tests/Import-DbaCsv.Tests.ps1 | 31 +++++- 2 files changed, 215 insertions(+), 16 deletions(-) diff --git a/public/Import-DbaCsv.ps1 b/public/Import-DbaCsv.ps1 index df191514b7..accda838f9 100644 --- a/public/Import-DbaCsv.ps1 +++ b/public/Import-DbaCsv.ps1 @@ -249,7 +249,17 @@ function Import-DbaCsv { >> } PS C:\> Import-DbaCsv -Path c:\temp\supersmall.csv -SqlInstance sql2016 -Database tempdb -ColumnMap $columns - The CSV column 'Text' is inserted into SQL column 'FirstName' and CSV column Number is inserted into the SQL Column 'PhoneNumber'. All other columns are ignored and therefore null or default values. + The CSV field 'Text' is inserted into SQL column 'FirstName' and CSV field Number is inserted into the SQL Column 'PhoneNumber'. All other columns are ignored and therefore null or default values. + + .EXAMPLE + PS C:\> $columns = @{ + >> 0 = 'FirstName' + >> 1 = 'PhoneNumber' + >> } + PS C:\> Import-DbaCsv -Path c:\temp\supersmall.csv -SqlInstance sql2016 -Database tempdb -NoHeaderRow -ColumnMap $columns + + If the CSV has no headers, passing a ColumnMap works when you have as the key the ordinal of the column (0-based). + In this example the first CSV field is inserted into SQL column 'FirstName' and the second CSV field is inserted into the SQL Column 'PhoneNumber'. #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')] param ( @@ -356,7 +366,6 @@ function Import-DbaCsv { $reader.Dispose() } - # Get SQL datatypes by best guess on first data row $sqldatatypes = @(); foreach ($column in $Columns) { @@ -374,11 +383,76 @@ function Import-DbaCsv { } Write-Message -Level Verbose -Message "Successfully created table $schema.$table with the following column definitions:`n $($sqldatatypes -join "`n ")" - # Write-Message -Level Warning -Message "All columns are created using a best guess, and use their maximum datatype." Write-Message -Level Verbose -Message "This is inefficient but allows the script to import without issues." Write-Message -Level Verbose -Message "Consider creating the table first using best practices if the data will be used in production." } + + + + function ConvertTo-DotnetType { + param ( + [string]$DataType + ) + + switch ($DataType) { + 'BigInt' { return [System.Int64] } + 'Binary' { return [System.Byte[]] } + 'VarBinary' { return [System.Byte[]] } + 'Bit' { return [System.Boolean] } + 'Char' { return [System.String] } + 'VarChar' { return [System.String] } + 'NChar' { return [System.String] } + 'NVarChar' { return [System.String] } + 'DateTime' { return [System.DateTime] } + 'SmallDateTime' { return [System.DateTime] } + 'Date' { return [System.DateTime] } + 'Time' { return [System.DateTime] } + 'DateTime2' { return [System.DateTime] } + 'Decimal' { return [System.Decimal] } + 'Money' { return [System.Decimal] } + 'SmallMoney' { return [System.Decimal] } + 'Float' { return [System.Double] } + 'Int' { return [System.Int32] } + 'Real' { return [System.Single] } + 'UniqueIdentifier' { return [System.Guid] } + 'SmallInt' { return [System.Int16] } + 'TinyInt' { return [System.Byte] } + 'Xml' { return [System.String] } + default { throw "Unsupported SMO DataType: $($DataType)" } + } + } + + function Get-TableDefinitionFromInfoSchema { + param ( + [string]$table, + [string]$schema, + $sqlconn + ) + + $query = "SELECT c.COLUMN_NAME, c.DATA_TYPE, c.ORDINAL_POSITION - 1 FROM INFORMATION_SCHEMA.COLUMNS AS c WHERE TABLE_SCHEMA = @schema AND TABLE_NAME = @table;" + $sqlcmd = New-Object Microsoft.Data.SqlClient.SqlCommand($query, $sqlconn, $transaction) + $null = $sqlcmd.Parameters.AddWithValue('schema', $schema) + $null = $sqlcmd.Parameters.AddWithValue('table', $table) + + $result = @() + try { + $reader = $sqlcmd.ExecuteReader() + foreach ($dataRow in $reader) { + $result += [PSCustomObject]@{ + Name = $dataRow[0] + DataType = $dataRow[1] + Index = $dataRow[2] + } + } + $reader.Close() + } catch { + # callers report back the error if $result is empty + } + + return $result + } + Write-Message -Level Verbose -Message "Started at $(Get-Date)" } process { @@ -436,7 +510,7 @@ function Import-DbaCsv { } } - # Use dbo as schema name if not specified in parms, or as first string before a period in filename + # Use dbo as schema name if not specified in params, or as first string before a period in filename if (-not ($PSBoundParameters.Schema)) { if ($UseFileNameForSchema) { if ($filename.IndexOf('.') -eq -1) { @@ -474,9 +548,9 @@ function Import-DbaCsv { } # Ensure Schema exists - $sql = "select count(*) from [$Database].sys.schemas where name='$schema'" + $sql = "select count(*) from sys.schemas where name = @schema" $sqlcmd = New-Object Microsoft.Data.SqlClient.SqlCommand($sql, $sqlconn, $transaction) - + $null = $sqlcmd.Parameters.AddWithValue('schema', $schema) # If Schema doesn't exist create it # Defaulting to dbo. if (($sqlcmd.ExecuteScalar()) -eq 0) { @@ -495,11 +569,21 @@ function Import-DbaCsv { } # Ensure table or view exists - $sql = "select count(*) from [$Database].sys.tables where name = '$table' and schema_id=schema_id('$schema')" + $sql = "select count(*) from sys.tables where name = @table and schema_id = schema_id(@schema)" $sqlcmd = New-Object Microsoft.Data.SqlClient.SqlCommand($sql, $sqlconn, $transaction) + $null = $sqlcmd.Parameters.AddWithValue('schema', $schema) + $null = $sqlcmd.Parameters.AddWithValue('table', $table) - $sql2 = "select count(*) from [$Database].sys.views where name = '$table' and schema_id=schema_id('$schema')" + $sql2 = "select count(*) from sys.views where name = @table and schema_id=schema_id(@schema)" $sqlcmd2 = New-Object Microsoft.Data.SqlClient.SqlCommand($sql2, $sqlconn, $transaction) + $null = $sqlcmd2.Parameters.AddWithValue('schema', $schema) + $null = $sqlcmd2.Parameters.AddWithValue('table', $table) + + # this variable enables the machinery that needs to build a precise mapping from the table definition + # to the type of the columns BulkCopy needs. Lumen has support for it, but since it's a tad bit expensive + # we opt-in only if the table already exists but not when we create the default table (which is basic, and it's all nvarchar(max)s columns) + $shouldMapCorrectTypes = $false + # Create the table if required. Remember, this will occur within a transaction, so if the script fails, the # new table will no longer exist. @@ -516,6 +600,7 @@ function Import-DbaCsv { } } } else { + $shouldMapCorrectTypes = $true Write-Message -Level Verbose -Message "Table exists" } @@ -588,7 +673,8 @@ function Import-DbaCsv { if ($ColumnMap) { foreach ($columnname in $ColumnMap) { - foreach ($key in $columnname.Keys) { + foreach ($key in $columnname.Keys | Sort-Object) { + #sort added in case of column maps done by ordinal $null = $bulkcopy.ColumnMappings.Add($key, $columnname[$key]) } } @@ -599,6 +685,8 @@ function Import-DbaCsv { $null = $bulkcopy.ColumnMappings.Add($columnname, $columnname) } } + + } catch { Stop-Function -Continue -Message "Failure" -ErrorRecord $_ } @@ -637,6 +725,90 @@ function Import-DbaCsv { $NullValue ) + if ($shouldMapCorrectTypes) { + + if ($FirstRowHeader) { + + # we can get default columns, all strings. This "fills" the $reader.Columns list, that we use later + $null = $reader.GetFieldHeaders() + # we get the table definition + # we do not use $server because the connection is active here + $tableDef = Get-TableDefinitionFromInfoSchema -table $table -schema $schema -sqlconn $sqlconn + if ($tableDef.Length -eq 0) { + Stop-Function -Message "Could not fetch table definition for table $table in schema $schema" + } + foreach ($bcMapping in $bulkcopy.ColumnMappings) { + # loop over mappings, we need to be careful and assign the correct type + $colNameFromSql = $bcMapping.DestinationColumn + $colNameFromCsv = $bcMapping.SourceColumn + foreach ($sqlCol in $tableDef) { + if ($sqlCol.Name -eq $colNameFromSql) { + # now we know the column, we need to get the type, let's be extra-obvious here + $colTypeFromSql = $sqlCol.DataType + # and now we translate to C# type + $colTypeCSharp = ConvertTo-DotnetType -DataType $colTypeFromSql + # and now we assign the type to the LumenCsv column + foreach ($csvCol in $reader.Columns) { + if ($csvCol.Name -eq $colNameFromCsv) { + $csvCol.Type = $colTypeCSharp + Write-Message -Level Verbose -Message "Mapped $colNameFromCsv --> $colNameFromSql ($colTypeCSharp --> $colTypeFromSql)" + break + } + } + break + } + } + } + } else { + # we need to resort to ordinals + # start by getting the table definition + $tableDef = Get-TableDefinitionFromInfoSchema -table $table -schema $schema -sqlconn $sqlconn + if ($tableDef.Length -eq 0) { + Stop-Function -Message "Could not fetch table definition for table $table in schema $schema" + } + if ($bulkcopy.ColumnMappings.Count -eq 0) { + # if we land here, we aren't (probably ? ) forcing any mappings, but we kinda need them for later + foreach ($dataRow in $tableDef) { + $null = $bulkcopy.ColumnMappings.Add($dataRow.Index, $dataRow.Index) + } + } + # ok we got the mappings sorted + + # we must build Lumen's columns by hand here, we can't use GetFieldHeaders() + $reader.Columns = New-Object System.Collections.Generic.List[LumenWorks.Framework.IO.Csv.Column] + + foreach ($bcMapping in $bulkcopy.ColumnMappings) { + # loop over mappings, we need to be careful and assign the correct type, and we're in the "natural" order of the CSV fields + $colNameFromSql = $bcMapping.DestinationOrdinal + $colNameFromCsv = $bcMapping.SourceOrdinal + $newcol = New-Object LumenWorks.Framework.IO.Csv.Column + $newcol.Name = "c$(Get-Random)" # need to assign a name, it's required for Lumen even if we're mapping just by ordinal + foreach ($sqlCol in $tableDef) { + if ($bcMapping.DestinationOrdinal -eq -1) { + # we can map by name + $colNameFromSql = $bcMapping.DestinationColumn + $sqlColComparison = $sqlCol.Name + } else { + # we fallback to mapping by index + $colNameFromSql = $bcMapping.DestinationOrdinal + $sqlColComparison = $sqlCol.Index + } + if ($sqlColComparison -eq $colNameFromSql) { + $colTypeFromSql = $sqlCol.DataType + # and now we translate to C# type + $colTypeCSharp = ConvertTo-DotnetType -DataType $colTypeFromSql + # assign it to the column + $newcol.Type = $colTypeCSharp + # and adding to the column collection + $null = $reader.Columns.Add($newcol) + Write-Message -Level Verbose -Message "Mapped $colNameFromSql --> $colNameFromCsv ($colTypeCSharp --> $colTypeFromSql)" + break + } + } + } + } + } + if ($PSBoundParameters.MaxQuotedFieldLength) { $reader.MaxQuotedFieldLength = $MaxQuotedFieldLength } @@ -663,8 +835,7 @@ function Import-DbaCsv { $bulkCopy.Add_SqlRowsCopied( { $script:totalRowsCopied += (Get-AdjustedTotalRowsCopied -ReportedRowsCopied $args[1].RowsCopied -PreviousRowsCopied $script:prevRowsCopied).NewRowCountAdded - $tstamp = $(Get-Date -Format 'yyyyMMddHHmmss') - Write-Message -Level Verbose -Message "[$tstamp] The bulk copy library reported RowsCopied = $($args[1].RowsCopied). The previous RowsCopied = $($script:prevRowsCopied). The adjusted total rows copied = $($script:totalRowsCopied)" + Write-Message -Level Verbose -FunctionName "Import-DbaCsv" -Message " Total rows copied = $($script:totalRowsCopied)" # progress is written by the ProgressStream callback # save the previous count of rows copied to be used on the next event notification $script:prevRowsCopied = $args[1].RowsCopied @@ -675,7 +846,6 @@ function Import-DbaCsv { $completed = $true } catch { $completed = $false - Stop-Function -Continue -Message "Failure" -ErrorRecord $_ } finally { try { @@ -751,9 +921,9 @@ function Import-DbaCsv { end { # Close everything just in case & ignore errors try { - $null = $sqlconn.close(); $null = $sqlconn.Dispose(); - $null = $bulkCopy.close(); $bulkcopy.dispose(); - $null = $reader.close(); $null = $reader.dispose() + $null = $sqlconn.Close(); $null = $sqlconn.Dispose(); + $null = $bulkCopy.Close(); $bulkcopy.Dispose(); + $null = $reader.Close(); $null = $reader.Dispose() } catch { #here to avoid an empty catch $null = 1 diff --git a/tests/Import-DbaCsv.Tests.ps1 b/tests/Import-DbaCsv.Tests.ps1 index 9153582f09..16795b9b03 100644 --- a/tests/Import-DbaCsv.Tests.ps1 +++ b/tests/Import-DbaCsv.Tests.ps1 @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { AfterAll { - Invoke-DbaQuery -SqlInstance $script:instance1, $script:instance2 -Database tempdb -Query "drop table SuperSmall" + Invoke-DbaQuery -SqlInstance $script:instance1, $script:instance2 -Database tempdb -Query "drop table SuperSmall; drop table CommaSeparatedWithHeader" } $path = "$script:appveyorlabrepo\csv\SuperSmall.csv" @@ -95,6 +95,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $result.RowsCopied | Should -Be 1 $result.Database | Should -Be tempdb $result.Table | Should -Be CommaSeparatedWithHeader + Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE NoHeaderRow' } It "works with NoHeaderRow" { @@ -110,5 +111,33 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $result.RowsCopied | Should -Be 3 $data[0].c1 | Should -Be 'firstcol' } + + It "works with tables which have non-varchar types (date)" { + # See #9433 + $server = Connect-DbaInstance $script:instance1 -Database tempdb + Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE WithTypes ([date] DATE, col1 VARCHAR(50), col2 VARCHAR(50))' + $result = Import-DbaCsv -Path $CommaSeparatedWithHeader -SqlInstance $server -Database tempdb -Table 'WithTypes' + Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE WithTypes' + + $result | Should -Not -BeNullOrEmpty + $result.RowsCopied | Should -Be 1 + } + + It "works with tables which have non-varchar types (guid, bit)" { + # See #9433 + $filePath = '.\foo.csv' + $server = Connect-DbaInstance $script:instance1 -Database tempdb + Invoke-DbaQuery -SqlInstance $server -Query 'CREATE TABLE WithGuidsAndBits (one_guid UNIQUEIDENTIFIER, one_bit BIT)' + $row = [pscustomobject]@{ + one_guid = (New-Guid).Guid + one_bit = 1 + } + $row | Export-Csv -Path $filePath -NoTypeInformation + $result = Import-DbaCsv -Path $filePath -SqlInstance $server -Database tempdb -Table 'WithGuidsAndBits' + Invoke-DbaQuery -SqlInstance $server -Query 'DROP TABLE WithGuidsAndBits' + + $result.RowsCopied | Should -Be 1 + Remove-Item $filePath + } } } \ No newline at end of file From c2153258c3868a326e1d18d4dcc97ba8e44989ba Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Sat, 5 Oct 2024 19:58:01 +0200 Subject: [PATCH 11/22] v2.1.25 --- bin/dbatools-index.json | Bin 8893264 -> 8895224 bytes .../SQLServerDiagnosticQueries_2019.sql | 2 +- .../SQLServerDiagnosticQueries_2022.sql | 5 +++-- dbatools.psd1 | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/dbatools-index.json b/bin/dbatools-index.json index df1c5240e96276e77e8cb8f5a2d59aef29f91a12..9c8e053d410b236b1dfa49a4eb914d16038328d6 100644 GIT binary patch delta 907 zcmZwDJ4};N6bJBI_^jolls*I%0c#N`rD{>ssvlUWJVXTrS}XD@w#Z9B5D`T!a4JjFqoJ){BCkjPVV{Nv-)jX`t@^K3XzK9 zD4rzRMrztl8cHCU5=l!*q@!fglYxw6q8*e%skD=J(QZnkJ(Nxvlu3KZO#8?}S+t+B zDTi{&N_lT=k}I0)m3SkV*~(uEZK=_B208k*$r#fcjZz%DriPx!A}*UPf%Rp1rMTA* z@JyEFRd~6|2Kiuz18@)yfddNQFdTtGI10z$I5^=1oP<-c~M|hxS>h5s2uE{Rq9j){AnWI#MTAH!l5FMh5HvOb6A;EX4x^Rr1JWlV(0Q^wT^pY ziYB8&_{AWm_KH579Z2Cvil7)k)y^f!NVqgzB5~~xk1^3KhS4@4y2T)`Y)C2m*4QHR znp~vg&%QP_uTQuo!{!_2t+oJu)hqlwR?}_bh`}N8YP%vEtimAG~Qp8D?88r-5zc=5*Ht#FMeT)~lf#me@VS}mJDIOYF$W&gXfVs<_2nu#u@G=^6f z6)1vYI1Mf+fl_e887PBtsDMg13srCq&cg+$h8nmCm!KBvpdLKnh0EZBE6@N}VKYM$ zG(!utf*;!88U!E+?Qk7BpcA^F8+zad^g!%Y}~LAV7&a2tl<4vfHExCf(fA0EI% U2*DUUf^i^t3{PUKi{X&^4|WTG&j0`b delta 561 zcmWm8$xagi0LS5}jv%WAt+HEML>+fF5sTo0O0j@Nu&5OQ*$Wg9tO{E7k4=mR6A5!8 zO+1qr(_~)3BTvB_kZ|PZ;k$qPdt2tt?v|O9ONVq=rj95}**dBm$pzHqmw$N5|ye<<*HDns&rajRm&&8YIH`mI;(R!pRvq#C%zs|WN!{u$84|P%5{DO zt$!}t-O#sar~SSSJ6>s-sdUJ~1zf}>T*eh##WmES9t~(j6Rx8fH_(EcPC68b4B0i& zRGIDG4t&oWHRg?&v24s5bI$MWK#t4y{tcJdKRYAlubl~P{_(s>B{BiD;uhM_j@!6{ zySRrA+{XhvL??pi!Xt#xjUM#kF~aD>6ZB&MPZ7Z&p5ZzEAEJ1PA-uvcMlg!k7{fRw zFo`KlV+JwIVh;0&V*!g;!W%4O1#gkSJG{pStYQrx@d-(M#ut2ru#Rs|B9lsH9RN}P B`w0L5 diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql index 2fcda6e014..bba5a92302 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql @@ -1,7 +1,7 @@ -- SQL Server 2019 Diagnostic Information Queries -- Glenn Berry --- Last Modified: September 11, 2024 +-- Last Modified: October 2, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql index 662389b98b..298e8bdda6 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql @@ -1,7 +1,7 @@ -- SQL Server 2022 Diagnostic Information Queries -- Glenn Berry --- Last Modified: September 11, 2024 +-- Last Modified: October 3, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -83,6 +83,7 @@ SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version In -- 16.0.4131.2 CU13 + GDR 7/9/2024 https://support.microsoft.com/en-us/topic/kb5040939-description-of-the-security-update-for-sql-server-2022-cu13-july-9-2024-16a61a81-926c-46a5-b6c0-edbca541f2f6 -- 16.0.4135.4 CU14 7/23/2024 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate14 -- 16.0.4140.3 CU14 + GDR 9/10/2024 https://support.microsoft.com/en-us/topic/kb5042578-description-of-the-security-update-for-sql-server-2022-cu14-september-10-2024-560e6e4c-1f49-4c18-9eb7-054e9fdee3c7 +-- 16.0.4145.4 CU15 9/25/2024 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate15 -- What's new in SQL Server 2022 (16.x) -- https://bit.ly/3MJEjR1 @@ -2199,7 +2200,7 @@ ORDER BY total_worker_time DESC OPTION (RECOMPILE); -- Determine which scalar UDFs are in-lineable (Query 84) (Inlineable UDFs) -SELECT OBJECT_NAME(m.object_id) AS [Function Name], is_inlineable, inline_type, +SELECT OBJECT_NAME(m.object_id) AS [Function Name], m.is_inlineable, m.inline_type, efs.total_worker_time FROM sys.sql_modules AS m WITH (NOLOCK) LEFT OUTER JOIN sys.dm_exec_function_stats AS efs WITH (NOLOCK) diff --git a/dbatools.psd1 b/dbatools.psd1 index 43f2aa3c8d..a07325b46d 100644 --- a/dbatools.psd1 +++ b/dbatools.psd1 @@ -11,7 +11,7 @@ RootModule = 'dbatools.psm1' # Version number of this module. - ModuleVersion = '2.1.24' + ModuleVersion = '2.1.25' # ID used to uniquely identify this module GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789' From 5c9345462a976bd0d0224c67bde434ce4fe25b27 Mon Sep 17 00:00:00 2001 From: Mikey Bronowski Date: Wed, 9 Oct 2024 22:16:53 +0100 Subject: [PATCH 12/22] Update dbatools-buildref-index.json --- bin/dbatools-buildref-index.json | 34 +++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/bin/dbatools-buildref-index.json b/bin/dbatools-buildref-index.json index f543195d59..ec844a73a4 100644 --- a/bin/dbatools-buildref-index.json +++ b/bin/dbatools-buildref-index.json @@ -1,5 +1,5 @@ { - "LastUpdated": "2024-09-26T00:00:00", + "LastUpdated": "2024-10-08T00:00:00", "Data": [ { "Version": "8.0.47", @@ -4123,6 +4123,10 @@ "Version": "13.0.6445", "KBList": "5042207" }, + { + "Version": "13.0.6450", + "KBList": "5046063" + }, { "Version": "13.0.7000", "KBList": "5014242" @@ -4147,6 +4151,10 @@ "Version": "13.0.7040", "KBList": "5042209" }, + { + "Version": "13.0.7045", + "KBList": "5046062" + }, { "Version": "14.0.1", "Name": "2017" @@ -4216,6 +4224,10 @@ "Version": "14.0.2060", "KBList": "5042217" }, + { + "Version": "14.0.2065", + "KBList": "5046058" + }, { "CU": "CU1", "Version": "14.0.3006", @@ -4415,6 +4427,10 @@ "Version": "14.0.3475", "KBList": "5042215" }, + { + "Version": "14.0.3480", + "KBList": "5046061" + }, { "Version": "15.0.1000", "Name": "2019" @@ -4468,6 +4484,10 @@ "Version": "15.0.2120", "KBList": "5042214" }, + { + "Version": "15.0.2125", + "KBList": "5046056" + }, { "CU": "CU1", "Version": "15.0.4003", @@ -4637,6 +4657,10 @@ "Version": "15.0.4390", "KBList": "5042749" }, + { + "Version": "15.0.4395", + "KBList": "5046060" + }, { "Version": "16.0.100", "Name": "2022" @@ -4678,6 +4702,10 @@ "Version": "16.0.1125", "KBList": "5042211" }, + { + "Version": "16.0.1130", + "KBList": "5046057" + }, { "CU": "CU1", "Version": "16.0.4003", @@ -4772,6 +4800,10 @@ "CU": "CU15", "Version": "16.0.4145", "KBList": "5041321" + }, + { + "Version": "16.0.4150", + "KBList": "5046059" } ] } From b1962cc6888f32000175d1ae8209feaa45e23868 Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Mon, 14 Oct 2024 09:46:18 +0200 Subject: [PATCH 13/22] Copy-DbaResourceGovernor: Fix copy of classifier function (#9492) awesome, ty both! --- public/Copy-DbaResourceGovernor.ps1 | 6 ++++-- tests/Copy-DbaResourceGovernor.Tests.ps1 | 3 ++- tests/pester.groups.ps1 | 2 -- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/public/Copy-DbaResourceGovernor.ps1 b/public/Copy-DbaResourceGovernor.ps1 index f2320de53f..1be77bd3be 100644 --- a/public/Copy-DbaResourceGovernor.ps1 +++ b/public/Copy-DbaResourceGovernor.ps1 @@ -153,7 +153,8 @@ function Copy-DbaResourceGovernor { } Write-Message -Level Verbose -Message "Creating function." - $destServer.Query($sourceClassifierFunction.Script()) + $script = $sourceClassifierFunction.Script() | Where-Object { $_ -notmatch '^SET QUOTED_IDENTIFIER' -and $_ -notmatch '^SET ANSI_NULLS' } + $destServer.Query($script) $sql = "ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = $fullyQualifiedFunctionName);" Write-Message -Level Debug -Message $sql @@ -191,7 +192,8 @@ function Copy-DbaResourceGovernor { $destClassifierFunction.Drop() Write-Message -Level Verbose -Message "Re-creating the Resource Governor classifier function." - $destServer.Query($sourceClassifierFunction.Script()) + $script = $sourceClassifierFunction.Script() | Where-Object { $_ -notmatch '^SET QUOTED_IDENTIFIER' -and $_ -notmatch '^SET ANSI_NULLS' } + $destServer.Query($script) $sql = "ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = $fullyQualifiedFunctionName);" Write-Message -Level Debug -Message $sql diff --git a/tests/Copy-DbaResourceGovernor.Tests.ps1 b/tests/Copy-DbaResourceGovernor.Tests.ps1 index ca90b128e3..3cce240275 100644 --- a/tests/Copy-DbaResourceGovernor.Tests.ps1 +++ b/tests/Copy-DbaResourceGovernor.Tests.ps1 @@ -56,7 +56,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2 -Query $sql } AfterAll { - Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaProcess -SqlInstance $script:instance2, $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2, $script:instance3 -Query "ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = NULL); ALTER RESOURCE GOVERNOR RECONFIGURE" Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2, $script:instance3 -Query "DROP FUNCTION [dbo].[dbatoolsci_fnRG];ALTER RESOURCE GOVERNOR RECONFIGURE" Invoke-DbaQuery -WarningAction SilentlyContinue -SqlInstance $script:instance2, $script:instance3 -Query "DROP WORKLOAD GROUP [dbatoolsci_prodprocessing];ALTER RESOURCE GOVERNOR RECONFIGURE" @@ -68,6 +68,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { Context "Command works" { It "copies the resource governor successfully" { $results = Copy-DbaResourceGovernor -Source $script:instance2 -Destination $script:instance3 -Force -WarningAction SilentlyContinue + $results.Status | Select-Object -Unique | Should -Be 'Successful' $results.Status.Count | Should -BeGreaterThan 3 $results.Name | Should -Contain 'dbatoolsci_prod' } diff --git a/tests/pester.groups.ps1 b/tests/pester.groups.ps1 index 8599d1f9f8..e2c7ead4af 100644 --- a/tests/pester.groups.ps1 +++ b/tests/pester.groups.ps1 @@ -29,8 +29,6 @@ $TestsRunGroups = @{ # Non-useful info from newly started sql servers 'Get-DbaCpuRingBuffer', 'Get-DbaLatchStatistic', - # times out - 'Copy-DbaResourceGovernor', # fails on newer version of SMO 'Get-DbaUserPermission', 'Invoke-DbaBalanceDataFiles', From 9333fe567f33bb52c32865746461457e312c5bb6 Mon Sep 17 00:00:00 2001 From: Mikey Bronowski Date: Mon, 14 Oct 2024 08:46:48 +0100 Subject: [PATCH 14/22] Fix typos in DbaDbDbcc commands (#9494) --- public/Invoke-DbaDbDbccCheckConstraint.ps1 | 4 ++-- public/Invoke-DbaDbDbccCleanTable.ps1 | 4 ++-- public/Invoke-DbaDbDbccUpdateUsage.ps1 | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/public/Invoke-DbaDbDbccCheckConstraint.ps1 b/public/Invoke-DbaDbDbccCheckConstraint.ps1 index 872d50e608..3b2a61b0ac 100644 --- a/public/Invoke-DbaDbDbccCheckConstraint.ps1 +++ b/public/Invoke-DbaDbDbccCheckConstraint.ps1 @@ -94,7 +94,7 @@ function Invoke-DbaDbDbccCheckConstraint { .EXAMPLE PS C:\> 'Sql1','Sql2/sqlexpress' | Invoke-DbaDbDbccCheckConstraint -WhatIf - Displays what will happen if command DBCC CHECKCONSTRAINTS is called against all databses on Sql1 and Sql2/sqlexpress + Displays what will happen if command DBCC CHECKCONSTRAINTS is called against all databases on Sql1 and Sql2/sqlexpress. #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')] @@ -214,4 +214,4 @@ function Invoke-DbaDbDbccCheckConstraint { } } } -} \ No newline at end of file +} diff --git a/public/Invoke-DbaDbDbccCleanTable.ps1 b/public/Invoke-DbaDbDbccCleanTable.ps1 index dd7e38e3ea..58bfad532b 100644 --- a/public/Invoke-DbaDbDbccCleanTable.ps1 +++ b/public/Invoke-DbaDbDbccCleanTable.ps1 @@ -75,7 +75,7 @@ function Invoke-DbaDbDbccCleanTable { .EXAMPLE PS C:\> 'Sql1','Sql2/sqlexpress' | Invoke-DbaDbDbccCleanTable -Object 'dbo.SomeTable' -BatchSize 5000 - Runs the command DBCC CLEANTABLE('DatabaseName', 'dbo.SomeTable', 5000) against all databses on Sql1 and Sql2/sqlexpress + Runs the command DBCC CLEANTABLE('DatabaseName', 'dbo.SomeTable', 5000) against all databases on Sql1 and Sql2/sqlexpress. #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] @@ -162,4 +162,4 @@ function Invoke-DbaDbDbccCleanTable { } } } -} \ No newline at end of file +} diff --git a/public/Invoke-DbaDbDbccUpdateUsage.ps1 b/public/Invoke-DbaDbDbccUpdateUsage.ps1 index 3dce1de1fa..cf395cc005 100644 --- a/public/Invoke-DbaDbDbccUpdateUsage.ps1 +++ b/public/Invoke-DbaDbDbccUpdateUsage.ps1 @@ -90,7 +90,7 @@ function Invoke-DbaDbDbccUpdateUsage { .EXAMPLE PS C:\> 'Sql1','Sql2/sqlexpress' | Invoke-DbaDbDbccUpdateUsage -WhatIf - Displays what will happen if command DBCC UPDATEUSAGE is called against all databses on Sql1 and Sql2/sqlexpress + Displays what will happen if command DBCC UPDATEUSAGE is called against all databases on Sql1 and Sql2/sqlexpress. #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] @@ -196,4 +196,4 @@ function Invoke-DbaDbDbccUpdateUsage { } } } -} \ No newline at end of file +} From b32f70015575b456403334afecce98ea0731bcc9 Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Mon, 14 Oct 2024 10:05:22 +0200 Subject: [PATCH 15/22] Fix test for Get-DbaDump (#9499) --- tests/Get-DbaDump.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Get-DbaDump.Tests.ps1 b/tests/Get-DbaDump.Tests.ps1 index bff375274a..1889d37378 100644 --- a/tests/Get-DbaDump.Tests.ps1 +++ b/tests/Get-DbaDump.Tests.ps1 @@ -20,7 +20,7 @@ if (-not $env:appveyor) { BeforeAll { $server = Connect-DbaInstance -SqlInstance $script:instance1 $server.Query("DBCC STACKDUMP") - Start-Sleep -Seconds 5 + $server.Query("DBCC STACKDUMP") } $results = Get-DbaDump -SqlInstance $script:instance1 From 6e313001a74bd770d2c471e6dc8342acf9bc29f0 Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Mon, 14 Oct 2024 10:05:54 +0200 Subject: [PATCH 16/22] Refactor AgHadr tests (#9498) --- tests/Disable-DbaAgHadr.Tests.ps1 | 4 +++- tests/Enable-DbaAgHadr.Tests.ps1 | 10 +--------- tests/Get-DbaAgHadr.Tests.ps1 | 8 +++++--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/Disable-DbaAgHadr.Tests.ps1 b/tests/Disable-DbaAgHadr.Tests.ps1 index 24e295de82..4c7792042f 100644 --- a/tests/Disable-DbaAgHadr.Tests.ps1 +++ b/tests/Disable-DbaAgHadr.Tests.ps1 @@ -13,8 +13,10 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { } } +# $script:instance3 is used for Availability Group tests and needs Hadr service setting enabled + Describe "$commandname Integration Tests" -Tag "IntegrationTests" { - BeforeAll { + AfterAll { Enable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -Force } diff --git a/tests/Enable-DbaAgHadr.Tests.ps1 b/tests/Enable-DbaAgHadr.Tests.ps1 index e2ae156520..aa6e266d56 100644 --- a/tests/Enable-DbaAgHadr.Tests.ps1 +++ b/tests/Enable-DbaAgHadr.Tests.ps1 @@ -15,15 +15,7 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $current = Get-DbaAgHadr -SqlInstance $script:instance3 # for appveyor $script:instance2 - if ($current.IsHadrEnabled) { - Disable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -WarningAction SilentlyContinue -Force - } - } - AfterAll { - if (-not $current.IsHadrEnabled) { - Disable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -WarningAction SilentlyContinue -Force - } + Disable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -Force } $results = Enable-DbaAgHadr -SqlInstance $script:instance3 -Confirm:$false -Force diff --git a/tests/Get-DbaAgHadr.Tests.ps1 b/tests/Get-DbaAgHadr.Tests.ps1 index 209e7ca934..d946621db5 100644 --- a/tests/Get-DbaAgHadr.Tests.ps1 +++ b/tests/Get-DbaAgHadr.Tests.ps1 @@ -13,11 +13,13 @@ Describe "$CommandName Unit Tests" -Tag "UnitTests" { } } +# $script:instance3 is used for Availability Group tests and needs Hadr service setting enabled + Describe "$CommandName Integration Test" -Tag "IntegrationTests" { - $results = Get-DbaAgHadr -SqlInstance $script:instance2 + $results = Get-DbaAgHadr -SqlInstance $script:instance3 Context "Validate output" { It "returns the correct properties" { - $results.IsHadrEnabled | Should -Not -Be $null + $results.IsHadrEnabled | Should -Be $true } } -} \ No newline at end of file +} #$script:instance2 for appveyor \ No newline at end of file From e9bef9904b0727808002e3799451bc65033e0e74 Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Mon, 14 Oct 2024 10:07:07 +0200 Subject: [PATCH 17/22] Fix tests for Availability Groups (#9500) --- tests/Add-DbaAgListener.Tests.ps1 | 4 ++-- tests/Add-DbaAgReplica.Tests.ps1 | 14 +++++++++----- tests/Get-DbaAgListener.Tests.ps1 | 8 ++++---- tests/Get-DbaAgReplica.Tests.ps1 | 8 ++++---- tests/New-DbaAvailabilityGroup.Tests.ps1 | 18 +++++------------- tests/Remove-DbaAgListener.Tests.ps1 | 2 +- tests/Set-DbaAgReplica.Tests.ps1 | 15 ++++++++------- tests/pester.groups.ps1 | 2 -- 8 files changed, 33 insertions(+), 38 deletions(-) diff --git a/tests/Add-DbaAgListener.Tests.ps1 b/tests/Add-DbaAgListener.Tests.ps1 index 76ae123c9c..1483f1519c 100644 --- a/tests/Add-DbaAgListener.Tests.ps1 +++ b/tests/Add-DbaAgListener.Tests.ps1 @@ -27,8 +27,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } Context "creates a listener" { It "returns results with proper data" { - $results = $ag | Add-DbaAgListener -Name $listenerName -IPAddress 127.0.20.1 -Confirm:$false - $results.PortNumber | Should -Be 1433 + $results = $ag | Add-DbaAgListener -Name $listenerName -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false + $results.PortNumber | Should -Be 14330 } } } #$script:instance2 for appveyor \ No newline at end of file diff --git a/tests/Add-DbaAgReplica.Tests.ps1 b/tests/Add-DbaAgReplica.Tests.ps1 index 2ce374c4da..5a8c75c922 100644 --- a/tests/Add-DbaAgReplica.Tests.ps1 +++ b/tests/Add-DbaAgReplica.Tests.ps1 @@ -13,14 +13,19 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' { } } Describe "$commandname Integration Tests" -Tag "IntegrationTests" { + BeforeAll { + $agname = "dbatoolsci_agroup" + $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $replicaName = $ag.PrimaryReplica + } AfterAll { - Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false } Context "gets ag replicas" { # the only way to test, really, is to call New-DbaAvailabilityGroup which calls Add-DbaAgReplica $agname = "dbatoolsci_add_replicagroup" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert - + $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $replicaName = $ag.PrimaryReplica It "returns results with proper data" { $results = Get-DbaAgReplica -SqlInstance $script:instance3 @@ -30,8 +35,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $results.FailoverMode | Should -Contain 'Manual' } It "returns just one result" { - $server = Connect-DbaInstance -SqlInstance $script:instance3 - $results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $server.DomainInstanceName -AvailabilityGroup $agname + $results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $replicaName -AvailabilityGroup $agname $results.AvailabilityGroup | Should -Be $agname $results.Role | Should -Be 'Primary' $results.AvailabilityMode | Should -Be 'SynchronousCommit' diff --git a/tests/Get-DbaAgListener.Tests.ps1 b/tests/Get-DbaAgListener.Tests.ps1 index 011351caab..25573e372e 100644 --- a/tests/Get-DbaAgListener.Tests.ps1 +++ b/tests/Get-DbaAgListener.Tests.ps1 @@ -16,16 +16,16 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_ag_listener" - $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert | - Add-DbaAgListener -IPAddress 127.0.20.1 -Confirm:$false + $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $ag | Add-DbaAgListener -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false } Context "gets ags" { It "returns results with proper data" { $results = Get-DbaAgListener -SqlInstance $script:instance3 - $results.PortNumber | Should -Contain 1433 + $results.PortNumber | Should -Contain 14330 } } } #$script:instance2 for appveyor \ No newline at end of file diff --git a/tests/Get-DbaAgReplica.Tests.ps1 b/tests/Get-DbaAgReplica.Tests.ps1 index 86e2f780f4..92b9a5bb56 100644 --- a/tests/Get-DbaAgReplica.Tests.ps1 +++ b/tests/Get-DbaAgReplica.Tests.ps1 @@ -16,10 +16,11 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_agroup" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $replicaName = $ag.PrimaryReplica } AfterAll { - Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false + $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false } Context "gets ag replicas" { It "returns results with proper data" { @@ -29,8 +30,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $results.AvailabilityMode | Should -Contain 'SynchronousCommit' } It "returns just one result" { - $server = Connect-DbaInstance -SqlInstance $script:instance3 - $results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $server.DomainInstanceName -AvailabilityGroup $agname + $results = Get-DbaAgReplica -SqlInstance $script:instance3 -Replica $replicaName -AvailabilityGroup $agname $results.AvailabilityGroup | Should -Be $agname $results.Role | Should -Be 'Primary' $results.AvailabilityMode | Should -Be 'SynchronousCommit' diff --git a/tests/New-DbaAvailabilityGroup.Tests.ps1 b/tests/New-DbaAvailabilityGroup.Tests.ps1 index 7f218a624c..60a378e8b7 100644 --- a/tests/New-DbaAvailabilityGroup.Tests.ps1 +++ b/tests/New-DbaAvailabilityGroup.Tests.ps1 @@ -15,24 +15,16 @@ Describe "$commandname Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $computername = ($script:instance3).Split("\")[0] $null = Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue - $server = Connect-DbaInstance -SqlInstance $script:instance3 $dbname = "dbatoolsci_addag_agroupdb" - $server.Query("create database $dbname") $agname = "dbatoolsci_addag_agroup" - $password = 'MyV3ry$ecur3P@ssw0rd' - $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $null = New-DbaDbMasterKey -SqlInstance $script:instance3 -Database master -WarningAction SilentlyContinue -ErrorAction Ignore -EnableException:$false -SecurePassword $securePassword -Confirm:$false - $null = New-DbaDbCertificate -SqlInstance $script:instance3 -Database master -Name dbatoolsci_AGCert -Subject 'AG Certificate' -ErrorAction Ignore - $null = New-DbaEndpoint -SqlInstance $script:instance3 -Type DatabaseMirroring -Name dbatoolsci_AGEndpoint -Certificate dbatoolsci_AGCert | Start-DbaEndpoint - $backup = Get-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase + $null = New-DbaDatabase -SqlInstance $script:instance3 -Database $dbname | Backup-DbaDatabase + } + AfterEach { + $result = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false } AfterAll { - $null = Remove-DbaAvailabilityGroup -SqlInstance $server -AvailabilityGroup $agname -Confirm:$false - $null = Remove-DbaEndpoint -SqlInstance $server -Endpoint dbatoolsci_AGEndpoint -Confirm:$false - $null = Get-DbaDbCertificate -SqlInstance $server -Certificate dbatoolsci_AGCert | Remove-DbaDbCertificate -Confirm:$false - $null = Remove-DbaDatabase -SqlInstance $server -Database $dbname -Confirm:$false + $null = Remove-DbaDatabase -SqlInstance $script:instance3 -Database $dbname -Confirm:$false } Context "adds an ag" { It "returns an ag with a db named" { diff --git a/tests/Remove-DbaAgListener.Tests.ps1 b/tests/Remove-DbaAgListener.Tests.ps1 index 5d766f77e1..5811f5c158 100644 --- a/tests/Remove-DbaAgListener.Tests.ps1 +++ b/tests/Remove-DbaAgListener.Tests.ps1 @@ -17,7 +17,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_ag_removelistener" $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert - $aglistener = $ag | Add-DbaAgListener -IPAddress 127.0.20.1 -Confirm:$false + $aglistener = $ag | Add-DbaAgListener -IPAddress 127.0.20.1 -Port 14330 -Confirm:$false } AfterAll { $null = Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false diff --git a/tests/Set-DbaAgReplica.Tests.ps1 b/tests/Set-DbaAgReplica.Tests.ps1 index c8821a13b5..37e2461fe1 100644 --- a/tests/Set-DbaAgReplica.Tests.ps1 +++ b/tests/Set-DbaAgReplica.Tests.ps1 @@ -5,7 +5,7 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} - [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Replica', 'AvailabilityMode', 'FailoverMode', 'BackupPriority', 'ConnectionModeInPrimaryRole', 'ConnectionModeInSecondaryRole', 'SeedingMode', 'EndpointUrl', 'ReadonlyRoutingConnectionUrl', 'InputObject', 'EnableException', 'ReadOnlyRoutingList' + [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'AvailabilityGroup', 'Replica', 'AvailabilityMode', 'FailoverMode', 'BackupPriority', 'ConnectionModeInPrimaryRole', 'ConnectionModeInSecondaryRole', 'SeedingMode', 'SessionTimeout', 'EndpointUrl', 'ReadonlyRoutingConnectionUrl', 'ReadOnlyRoutingList', 'InputObject', 'EnableException' $knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters It "Should only contain our specific parameters" { (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0 @@ -16,24 +16,25 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { $agname = "dbatoolsci_arepgroup" - $null = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Confirm:$false -Certificate dbatoolsci_AGCert + $ag = New-DbaAvailabilityGroup -Primary $script:instance3 -Name $agname -ClusterType None -FailoverMode Manual -Certificate dbatoolsci_AGCert -Confirm:$false + $replicaName = $ag.PrimaryReplica } AfterAll { Remove-DbaAvailabilityGroup -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false } Context "sets ag properties" { It "returns modified results" { - $results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false -BackupPriority 5000 + $results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Replica $replicaName -BackupPriority 100 -Confirm:$false $results.AvailabilityGroup | Should -Be $agname - $results.BackupPriority | Should -Be 5000 + $results.BackupPriority | Should -Be 100 } It "returns modified results" { - $results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Confirm:$false -BackupPriority 1000 + $results = Set-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname -Replica $replicaName -SeedingMode Automatic -Confirm:$false $results.AvailabilityGroup | Should -Be $agname - $results.BackupPriority | Should -Be 1000 + $results.SeedingMode | Should -Be Automatic } It "attempts to add a ReadOnlyRoutingList" { - $null = Get-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname | Select-Object -First 1 | Set-DbaAgReplica -ReadOnlyRoutingList nondockersql -WarningVariable warn + $null = Get-DbaAgReplica -SqlInstance $script:instance3 -AvailabilityGroup $agname | Select-Object -First 1 | Set-DbaAgReplica -ReadOnlyRoutingList nondockersql -WarningAction SilentlyContinue -WarningVariable warn -Confirm:$false $warn | Should -match "does not exist. Only availability" } } diff --git a/tests/pester.groups.ps1 b/tests/pester.groups.ps1 index e2c7ead4af..c3b47b2f6a 100644 --- a/tests/pester.groups.ps1 +++ b/tests/pester.groups.ps1 @@ -39,7 +39,6 @@ $TestsRunGroups = @{ 'Invoke-DbaDbMirroring', # previous tests that were failing on older versions too 'Remove-DbaAvailabilityGroup', - 'Set-DbaAgReplica', 'Read-DbaAuditFile', 'Sync-DbaLoginPermission', 'Read-DbaXEFile', @@ -58,7 +57,6 @@ $TestsRunGroups = @{ 'Test-DbaManagementObject', 'Export-DbaDacPackage', 'New-DbaDbTransfer', - 'Remove-DbaAgDatabase', 'Get-DbaDbSynonym', 'Get-DbaDbVirtualLogFile', 'Get-DbaFile', From 689268dec5176b3068aea8403480c8c5b2b7955e Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Mon, 14 Oct 2024 10:08:33 +0200 Subject: [PATCH 18/22] Enable test for Invoke-DbaDbMirroring (#9503) --- tests/Invoke-DbaDbMirroring.Tests.ps1 | 9 ++++++++- tests/pester.groups.ps1 | 3 --- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/Invoke-DbaDbMirroring.Tests.ps1 b/tests/Invoke-DbaDbMirroring.Tests.ps1 index 23e5379c5b..3b15acac08 100644 --- a/tests/Invoke-DbaDbMirroring.Tests.ps1 +++ b/tests/Invoke-DbaDbMirroring.Tests.ps1 @@ -23,13 +23,20 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { Remove-DbaDatabase -SqlInstance $script:instance2 -Database $db1 -Confirm:$false $null = Get-DbaDatabase -SqlInstance $script:instance2 -Database $db1 | Remove-DbaDatabase -Confirm:$false $null = $server.Query("CREATE DATABASE $db1") + + Get-DbaEndpoint -SqlInstance $script:instance2 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $script:instance2 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5022 -Owner sa + Get-DbaEndpoint -SqlInstance $script:instance3 -Type DatabaseMirroring | Remove-DbaEndpoint -Confirm:$false + New-DbaEndpoint -SqlInstance $script:instance3 -Name dbatoolsci_MirroringEndpoint -Type DatabaseMirroring -Port 5023 -Owner sa } AfterAll { + $null = Remove-DbaDbMirror -SqlInstance $script:instance2, $script:instance3 -Database $db1 -Confirm:$false $null = Remove-DbaDatabase -Confirm:$false -SqlInstance $script:instance2, $script:instance3 -Database $db1 -ErrorAction SilentlyContinue } It "returns success" { - $results = Invoke-DbaDbMirroring -Primary $script:instance2 -Mirror $script:instance3 -Database $db1 -Confirm:$false -Force -SharedPath C:\temp + $results = Invoke-DbaDbMirroring -Primary $script:instance2 -Mirror $script:instance3 -Database $db1 -Confirm:$false -Force -SharedPath C:\temp -WarningVariable warn + $warn | Should -BeNullOrEmpty $results.Status | Should -Be 'Success' } } \ No newline at end of file diff --git a/tests/pester.groups.ps1 b/tests/pester.groups.ps1 index c3b47b2f6a..db2fa34755 100644 --- a/tests/pester.groups.ps1 +++ b/tests/pester.groups.ps1 @@ -34,9 +34,6 @@ $TestsRunGroups = @{ 'Invoke-DbaBalanceDataFiles', 'Invoke-DbaWhoisActive', # Works locally aganint a SQL Server 2022 instance without problems. 'Install-DbaDarlingData', - # impossible to do within one server - # "the partner server name must be distinct" - 'Invoke-DbaDbMirroring', # previous tests that were failing on older versions too 'Remove-DbaAvailabilityGroup', 'Read-DbaAuditFile', From 52243511113ec30133273d0a394f69e226939586 Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Mon, 14 Oct 2024 10:09:23 +0200 Subject: [PATCH 19/22] Refactor tests to use variable server instead of instance for SMO server objects (part 1) (#9501) --- tests/Add-DbaExtendedProperty.Tests.ps1 | 6 ++-- tests/Copy-DbaCredential.Tests.ps1 | 38 +++++++++++----------- tests/Copy-DbaDbAssembly.Tests.ps1 | 20 ++++++------ tests/Copy-DbaDbQueryStoreOption.Tests.ps1 | 28 ++++++++-------- tests/Get-DbaDbSchema.Tests.ps1 | 38 +++++++++++----------- tests/Get-DbaExtendedProperty.Tests.ps1 | 10 +++--- tests/Get-DbaLinkedServerLogin.Tests.ps1 | 30 ++++++++--------- tests/Get-DbaServerRoleMember.Tests.ps1 | 28 ++++++++-------- tests/New-DbaAgentOperator.Tests.ps1 | 18 +++++----- tests/New-DbaDbSchema.Tests.ps1 | 24 +++++++------- tests/Remove-DbaDbSchema.Tests.ps1 | 26 +++++++-------- tests/Set-DbaDbSchema.Tests.ps1 | 24 +++++++------- tests/Watch-DbaDbLogin.Tests.ps1 | 6 ++-- 13 files changed, 148 insertions(+), 148 deletions(-) diff --git a/tests/Add-DbaExtendedProperty.Tests.ps1 b/tests/Add-DbaExtendedProperty.Tests.ps1 index 4173ff080b..251328389c 100644 --- a/tests/Add-DbaExtendedProperty.Tests.ps1 +++ b/tests/Add-DbaExtendedProperty.Tests.ps1 @@ -16,10 +16,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Get-DbaProcess -SqlInstance $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $null = Get-DbaProcess -SqlInstance $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" - $db = New-DbaDatabase -SqlInstance $instance2 -Name $newDbName + $db = New-DbaDatabase -SqlInstance $server2 -Name $newDbName } AfterAll { diff --git a/tests/Copy-DbaCredential.Tests.ps1 b/tests/Copy-DbaCredential.Tests.ps1 index 4cdaaa52a0..326f47ccf1 100644 --- a/tests/Copy-DbaCredential.Tests.ps1 +++ b/tests/Copy-DbaCredential.Tests.ps1 @@ -20,8 +20,8 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $plaintext = "BigOlPassword!" $password = ConvertTo-SecureString $plaintext -AsPlainText -Force - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server3 = Connect-DbaInstance -SqlInstance $script:instance3 # Add user foreach ($login in $logins) { @@ -58,14 +58,14 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { #> # check to see if a crypto provider is present on the instances - $instance2CryptoProviders = $instance2.Query("SELECT name FROM sys.cryptographic_providers WHERE is_enabled = 1 ORDER BY name") - $instance3CryptoProviders = $instance3.Query("SELECT name FROM sys.cryptographic_providers WHERE is_enabled = 1 ORDER BY name") + $instance2CryptoProviders = $server2.Query("SELECT name FROM sys.cryptographic_providers WHERE is_enabled = 1 ORDER BY name") + $instance3CryptoProviders = $server3.Query("SELECT name FROM sys.cryptographic_providers WHERE is_enabled = 1 ORDER BY name") $cryptoProvider = ($instance2CryptoProviders | Where-Object { $_.name -eq $instance3CryptoProviders.name } | Select-Object -First 1).name } AfterAll { - (Get-DbaCredential -SqlInstance $instance2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma, dbatoolsci_thor_crypto -ErrorAction Stop -WarningAction SilentlyContinue).Drop() - (Get-DbaCredential -SqlInstance $instance3 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma, dbatoolsci_thor_crypto -ErrorAction Stop -WarningAction SilentlyContinue).Drop() + (Get-DbaCredential -SqlInstance $server2 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma, dbatoolsci_thor_crypto -ErrorAction Stop -WarningAction SilentlyContinue).Drop() + (Get-DbaCredential -SqlInstance $server3 -Identity dbatoolsci_thor, dbatoolsci_thorsmomma, dbatoolsci_thor_crypto -ErrorAction Stop -WarningAction SilentlyContinue).Drop() foreach ($login in $logins) { $null = Invoke-Command2 -ScriptBlock { net user $args /delete *>&1 } -ArgumentList $login -ComputerName $script:instance2 @@ -75,16 +75,16 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Create new credential" { It "Should create new credentials with the proper properties" { - $results = New-DbaCredential -SqlInstance $instance2 -Name dbatoolsci_thorcred -Identity dbatoolsci_thor -Password $password + $results = New-DbaCredential -SqlInstance $server2 -Name dbatoolsci_thorcred -Identity dbatoolsci_thor -Password $password $results.Name | Should Be "dbatoolsci_thorcred" $results.Identity | Should Be "dbatoolsci_thor" - $results = New-DbaCredential -SqlInstance $instance2 -Identity dbatoolsci_thorsmomma -Password $password + $results = New-DbaCredential -SqlInstance $server2 -Identity dbatoolsci_thorsmomma -Password $password $results.Name | Should Be "dbatoolsci_thorsmomma" $results.Identity | Should Be "dbatoolsci_thorsmomma" if ($cryptoProvider) { - $results = New-DbaCredential -SqlInstance $instance2 -Identity dbatoolsci_thor_crypto -Password $password -MappedClassType CryptographicProvider -ProviderName $cryptoProvider + $results = New-DbaCredential -SqlInstance $server2 -Identity dbatoolsci_thor_crypto -Password $password -MappedClassType CryptographicProvider -ProviderName $cryptoProvider $results.Name | Should Be "dbatoolsci_thor_crypto" $results.Identity | Should Be "dbatoolsci_thor_crypto" $results.ProviderName | Should -Be $cryptoProvider @@ -94,13 +94,13 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Copy Credential with the same properties." { It "Should copy successfully" { - $results = Copy-DbaCredential -Source $instance2 -Destination $instance3 -Name dbatoolsci_thorcred + $results = Copy-DbaCredential -Source $server2 -Destination $server3 -Name dbatoolsci_thorcred $results.Status | Should Be "Successful" } It "Should retain its same properties" { - $Credential1 = Get-DbaCredential -SqlInstance $instance2 -Name dbatoolsci_thor -ErrorAction SilentlyContinue -WarningAction SilentlyContinue - $Credential2 = Get-DbaCredential -SqlInstance $instance3 -Name dbatoolsci_thor -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + $Credential1 = Get-DbaCredential -SqlInstance $server2 -Name dbatoolsci_thor -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + $Credential2 = Get-DbaCredential -SqlInstance $server3 -Name dbatoolsci_thor -ErrorAction SilentlyContinue -WarningAction SilentlyContinue # Compare its value $Credential1.Name | Should Be $Credential2.Name @@ -110,7 +110,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "No overwrite" { It "does not overwrite without force" { - $results = Copy-DbaCredential -Source $instance2 -Destination $instance3 -Name dbatoolsci_thorcred + $results = Copy-DbaCredential -Source $server2 -Destination $server3 -Name dbatoolsci_thorcred $results.Status | Should Be "Skipping" } } @@ -118,18 +118,18 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { # See https://github.com/dataplat/dbatools/issues/7896 and comments above in BeforeAll Context "Crypto provider cred" { It -Skip:(-not $cryptoProvider) "ensure copied credential is using the same crypto provider" { - $results = Copy-DbaCredential -Source $instance2 -Destination $instance3 -Name dbatoolsci_thor_crypto + $results = Copy-DbaCredential -Source $server2 -Destination $server3 -Name dbatoolsci_thor_crypto $results.Status | Should Be Successful - $results = Get-DbaCredential -SqlInstance $instance3 -Name dbatoolsci_thor_crypto + $results = Get-DbaCredential -SqlInstance $server3 -Name dbatoolsci_thor_crypto $results.Name | Should -Be dbatoolsci_thor_crypto $results.ProviderName | Should -Be $cryptoProvider } It -Skip:(-not $cryptoProvider) "check warning message if crypto provider is not configured/enabled on destination" { - Remove-DbaCredential -SqlInstance $instance3 -Credential dbatoolsci_thor_crypto -Confirm:$false - $instance3.Query("ALTER CRYPTOGRAPHIC PROVIDER $cryptoProvider DISABLE") - $results = Copy-DbaCredential -Source $instance2 -Destination $instance3 -Name dbatoolsci_thor_crypto - $instance3.Query("ALTER CRYPTOGRAPHIC PROVIDER $cryptoProvider ENABLE") + Remove-DbaCredential -SqlInstance $server3 -Credential dbatoolsci_thor_crypto -Confirm:$false + $server3.Query("ALTER CRYPTOGRAPHIC PROVIDER $cryptoProvider DISABLE") + $results = Copy-DbaCredential -Source $server2 -Destination $server3 -Name dbatoolsci_thor_crypto + $server3.Query("ALTER CRYPTOGRAPHIC PROVIDER $cryptoProvider ENABLE") $results.Status | Should Be Failed $results.Notes | Should -Match "The cryptographic provider $cryptoProvider needs to be configured and enabled on" } diff --git a/tests/Copy-DbaDbAssembly.Tests.ps1 b/tests/Copy-DbaDbAssembly.Tests.ps1 index a2ab7cf804..f0efe59544 100644 --- a/tests/Copy-DbaDbAssembly.Tests.ps1 +++ b/tests/Copy-DbaDbAssembly.Tests.ps1 @@ -15,22 +15,22 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 - $instance3.Query("CREATE DATABASE dbclrassembly") - $instance3.Query("EXEC sp_configure 'CLR ENABLED' , '1'") - $instance3.Query("RECONFIGURE") + $server3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server3.Query("CREATE DATABASE dbclrassembly") + $server3.Query("EXEC sp_configure 'CLR ENABLED' , '1'") + $server3.Query("RECONFIGURE") - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance2.Query("CREATE DATABASE dbclrassembly") - $instance2.Query("EXEC sp_configure 'CLR ENABLED' , '1'") - $instance2.Query("RECONFIGURE") + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2.Query("CREATE DATABASE dbclrassembly") + $server2.Query("EXEC sp_configure 'CLR ENABLED' , '1'") + $server2.Query("RECONFIGURE") $instance2DB = Get-DbaDatabase -SqlInstance $script:instance2 -Database dbclrassembly $instance2DB.Query("CREATE ASSEMBLY [resolveDNS] AUTHORIZATION [dbo] FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010300457830570000000000000000E00002210B010B000008000000060000000000002E260000002000000040000000000010002000000002000004000000000000000400000000000000008000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000E02500004B00000000400000B002000000000000000000000000000000000000006000000C000000A82400001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E7465787400000034060000002000000008000000020000000000000000000000000000200000602E72737263000000B00200000040000000040000000A0000000000000000000000000000400000402E72656C6F6300000C0000000060000000020000000E0000000000000000000000000000400000420000000000000000000000000000000010260000000000004800000002000500A42000000404000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001B3001002F000000010000110000026F0500000A280600000A6F0700000A6F0800000A0A06730900000A0BDE0B260002730900000A0BDE0000072A0001100000000001002021000B010000011E02280A00000A2A42534A4201000100000000000C00000076322E302E35303732370000000005006C00000070010000237E0000DC010000A401000023537472696E67730000000080030000080000002355530088030000100000002347554944000000980300006C00000023426C6F620000000000000002000001471502000900000000FA253300160000010000000A0000000200000002000000010000000A0000000400000001000000010000000300000000000A0001000000000006003E0037000A006600510006009D008A000F00B10000000600E000C00006000001C0000A00440129010600590137000E00700165010E007401650100000000010000000000010001000100100019000000050001000100502000000000960070000A0001009C200000000086187D001000020000000100830019007D00140029007D001A0031007D00100039007D00100041006001240049008001280051008D01240009009A01240011007D002E0009007D001000200023001F002E000B0039002E00130042002E001B004B0033000480000000000000000000000000000000001E01000002000000000000000000000001002E00000000000200000000000000000000000100450000000000020000000000000000000000010037000000000000000000003C4D6F64756C653E007265736F6C7665444E532E646C6C0055736572446566696E656446756E6374696F6E73006D73636F726C69620053797374656D004F626A6563740053797374656D2E446174610053797374656D2E446174612E53716C54797065730053716C537472696E67004950746F486F73744E616D65002E63746F72006970616464720053797374656D2E446961676E6F73746963730044656275676761626C6541747472696275746500446562756767696E674D6F6465730053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300436F6D70696C6174696F6E52656C61786174696F6E734174747269627574650052756E74696D65436F6D7061746962696C697479417474726962757465007265736F6C7665444E53004D6963726F736F66742E53716C5365727665722E5365727665720053716C46756E6374696F6E41747472696275746500537472696E67005472696D0053797374656D2E4E657400446E73004950486F7374456E74727900476574486F7374456E747279006765745F486F73744E616D6500546F537472696E6700000003200000000000BBBB2D2F51E12E4791398BFA79459ABA0008B77A5C561934E08905000111090E03200001052001011111042001010804010000000320000E05000112290E042001010E0507020E11090801000701000000000801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F7773010000000000004578305700000000020000001C010000C4240000C40600005253445357549849C5462E43AD588F97CA53634201000000633A5C74656D705C4461746162617365315C4461746162617365315C6F626A5C44656275675C7265736F6C7665444E532E706462000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000826000000000000000000001E260000002000000000000000000000000000000000000000000000102600000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF25002000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100100000001800008000000000000000000000000000000100010000003000008000000000000000000000000000000100000000004800000058400000540200000000000000000000540234000000560053005F00560045005200530049004F004E005F0049004E0046004F0000000000BD04EFFE00000100000000000000000000000000000000003F000000000000000400000002000000000000000000000000000000440000000100560061007200460069006C00650049006E0066006F00000000002400040000005400720061006E0073006C006100740069006F006E00000000000000B004B4010000010053007400720069006E006700460069006C00650049006E0066006F0000009001000001003000300030003000300034006200300000002C0002000100460069006C0065004400650073006300720069007000740069006F006E000000000020000000300008000100460069006C006500560065007200730069006F006E000000000030002E0030002E0030002E003000000040000F00010049006E007400650072006E0061006C004E0061006D00650000007200650073006F006C007600650044004E0053002E0064006C006C00000000002800020001004C006500670061006C0043006F00700079007200690067006800740000002000000048000F0001004F0072006900670069006E0061006C00460069006C0065006E0061006D00650000007200650073006F006C007600650044004E0053002E0064006C006C0000000000340008000100500072006F006400750063007400560065007200730069006F006E00000030002E0030002E0030002E003000000038000800010041007300730065006D0062006C0079002000560065007200730069006F006E00000030002E0030002E0030002E003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000C000000303600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") $hash = $instance2DB.Query("SELECT HASHBYTES('SHA2_512', content) AS SHA2_512 FROM sys.assembly_files WHERE name = 'resolveDNS'") $hexStr = "0x$(($hash.SHA2_512 | ForEach-Object ToString X2) -join '')" - $instance3.Query(" + $server3.Query(" DECLARE @hash VARBINARY(64) = $hexStr , @assemblyName NVARCHAR(4000) = 'resolveDNS'; @@ -41,7 +41,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } AfterAll { Get-DbaDatabase -SqlInstance $script:instance2, $script:instance3 -Database dbclrassembly | Remove-DbaDatabase -Confirm:$false - $instance3.Query(" + $server3.Query(" DECLARE @hash VARBINARY(64) = $hexStr , @assemblyName NVARCHAR(4000) = 'resolveDNS'; diff --git a/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 b/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 index 181cff049f..3ae73a5444 100644 --- a/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 +++ b/tests/Copy-DbaDbQueryStoreOption.Tests.ps1 @@ -16,35 +16,35 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { Context "Verifying query store options are copied" { BeforeAll { - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 } BeforeEach { $db1Name = "dbatoolsci_querystoretest1" - $db1 = New-DbaDatabase -SqlInstance $instance2 -Name $db1Name + $db1 = New-DbaDatabase -SqlInstance $server2 -Name $db1Name - $db1QSOptions = Get-DbaDbQueryStoreOption -SqlInstance $instance2 -Database $db1Name + $db1QSOptions = Get-DbaDbQueryStoreOption -SqlInstance $server2 -Database $db1Name $originalQSOptionValue = $db1QSOptions.DataFlushIntervalInSeconds $updatedQSOption = $db1QSOptions.DataFlushIntervalInSeconds + 1 - $updatedDB1Options = Set-DbaDbQueryStoreOption -SqlInstance $instance2 -Database $db1Name -FlushInterval $updatedQSOption -State ReadWrite + $updatedDB1Options = Set-DbaDbQueryStoreOption -SqlInstance $server2 -Database $db1Name -FlushInterval $updatedQSOption -State ReadWrite $db2Name = "dbatoolsci_querystoretest2" - $db2 = New-DbaDatabase -SqlInstance $instance2 -Name $db2Name + $db2 = New-DbaDatabase -SqlInstance $server2 -Name $db2Name $db3Name = "dbatoolsci_querystoretest3" - $db3 = New-DbaDatabase -SqlInstance $instance2 -Name $db3Name + $db3 = New-DbaDatabase -SqlInstance $server2 -Name $db3Name $db4Name = "dbatoolsci_querystoretest4" - $db4 = New-DbaDatabase -SqlInstance $instance2 -Name $db4Name + $db4 = New-DbaDatabase -SqlInstance $server2 -Name $db4Name } AfterEach { $db1, $db2, $db3, $db4 | Remove-DbaDatabase -Confirm:$false } It "Copy the query store options from one db to another on the same instance" { - $db2QSOptions = Get-DbaDbQueryStoreOption -SqlInstance $instance2 -Database $db2Name + $db2QSOptions = Get-DbaDbQueryStoreOption -SqlInstance $server2 -Database $db2Name $db2QSOptions.DataFlushIntervalInSeconds | Should -Be $originalQSOptionValue - $result = Copy-DbaDbQueryStoreOption -Source $instance2 -SourceDatabase $db1Name -Destination $instance2 -DestinationDatabase $db2Name + $result = Copy-DbaDbQueryStoreOption -Source $server2 -SourceDatabase $db1Name -Destination $server2 -DestinationDatabase $db2Name $result.Status | Should -Be Successful $result.SourceDatabase | Should -Be $db1Name @@ -52,15 +52,15 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $result.Name | Should -Be $db2Name $result.DestinationDatabaseID | Should -Be $db2.ID - $db2QSOptions = Get-DbaDbQueryStoreOption -SqlInstance $instance2 -Database $db2Name + $db2QSOptions = Get-DbaDbQueryStoreOption -SqlInstance $server2 -Database $db2Name $db2QSOptions.DataFlushIntervalInSeconds | Should -Be ($originalQSOptionValue + 1) } It "Apply to all databases except db4" { - $db3QSOptions = Get-DbaDbQueryStoreOption -SqlInstance $instance2 -Database $db3Name + $db3QSOptions = Get-DbaDbQueryStoreOption -SqlInstance $server2 -Database $db3Name $db3QSOptions.DataFlushIntervalInSeconds | Should -Be $originalQSOptionValue - $result = Copy-DbaDbQueryStoreOption -Source $instance2 -SourceDatabase $db1Name -Destination $instance2 -Exclude $db4Name + $result = Copy-DbaDbQueryStoreOption -Source $server2 -SourceDatabase $db1Name -Destination $server2 -Exclude $db4Name $result.Status | Should -Not -Contain 'Failed' $result.Status | Should -Not -Contain 'Skipped' @@ -76,10 +76,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $result.DestinationDatabaseID | Should -Contain $db2.ID $result.DestinationDatabaseID | Should -Contain $db3.ID - $dbQSOptions = Get-DbaDbQueryStoreOption -SqlInstance $instance2 -Database $db1Name, $db2Name, $db3Name + $dbQSOptions = Get-DbaDbQueryStoreOption -SqlInstance $server2 -Database $db1Name, $db2Name, $db3Name ($dbQSOptions | Where-Object { $_.DataFlushIntervalInSeconds -eq ($originalQSOptionValue + 1) }).Count | Should -Be 3 - $db4QSOptions = Get-DbaDbQueryStoreOption -SqlInstance $instance2 -Database $db4Name + $db4QSOptions = Get-DbaDbQueryStoreOption -SqlInstance $server2 -Database $db4Name $db4QSOptions.DataFlushIntervalInSeconds | Should -Be $originalQSOptionValue } } diff --git a/tests/Get-DbaDbSchema.Tests.ps1 b/tests/Get-DbaDbSchema.Tests.ps1 index 1beebf2a71..7c5835925f 100644 --- a/tests/Get-DbaDbSchema.Tests.ps1 +++ b/tests/Get-DbaDbSchema.Tests.ps1 @@ -16,11 +16,11 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance1 = Connect-DbaInstance -SqlInstance $script:instance1 - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Get-DbaProcess -SqlInstance $instance1, $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false + $server1 = Connect-DbaInstance -SqlInstance $script:instance1 + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" - $newDbs = New-DbaDatabase -SqlInstance $instance1, $instance2 -Name $newDbName + $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName $schemaName = "TestSchema" $schemaName2 = "TestSchema2" @@ -29,10 +29,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $userName2 = "user2_$random" $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $logins = New-DbaLogin -SqlInstance $instance1, $instance2 -Login $userName, $userName2 -Password $securePassword -Force + $logins = New-DbaLogin -SqlInstance $server1, $server2 -Login $userName, $userName2 -Password $securePassword -Force - $null = New-DbaDbUser -SqlInstance $instance1, $instance2 -Database $newDbName -Login $userName - $null = New-DbaDbUser -SqlInstance $instance1, $instance2 -Database $newDbName -Login $userName2 + $null = New-DbaDbUser -SqlInstance $server1, $server2 -Database $newDbName -Login $userName + $null = New-DbaDbUser -SqlInstance $server1, $server2 -Database $newDbName -Login $userName2 $newDbs[0].Query("CREATE SCHEMA $schemaName AUTHORIZATION [$userName]") $newDbs[0].Schemas.Refresh() @@ -48,7 +48,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "commands work as expected" { It "get all schemas from all databases including system dbs and schemas" { - $schemas = Get-DbaDbSchema -SqlInstance $instance1 -IncludeSystemDatabases -IncludeSystemSchemas + $schemas = Get-DbaDbSchema -SqlInstance $server1 -IncludeSystemDatabases -IncludeSystemSchemas $schemas.Count | Should -BeGreaterThan 1 $schemas.Parent.Name | Should -Contain master $schemas.Parent.Name | Should -Contain msdb @@ -59,7 +59,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "get all schemas from user databases including system schemas" { - $schemas = Get-DbaDbSchema -SqlInstance $instance1 -IncludeSystemSchemas + $schemas = Get-DbaDbSchema -SqlInstance $server1 -IncludeSystemSchemas $schemas.Count | Should -BeGreaterThan 1 $schemas.Parent.Name | Should -Not -Contain master $schemas.Parent.Name | Should -Not -Contain msdb @@ -70,34 +70,34 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "get non-system schemas from a user database" { - $schemas = Get-DbaDbSchema -SqlInstance $instance1 -Schema $schemaName + $schemas = Get-DbaDbSchema -SqlInstance $server1 -Schema $schemaName $schemas.Name | Should -Contain $schemaName $schemas.Parent.Name | Should -Contain $newDbName } It "get a schema by name from a user database" { - $schemas = Get-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema $schemaName + $schemas = Get-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema $schemaName $schemas.Count | Should -Be 1 $schemas.Name | Should -Be $schemaName $schemas.DatabaseName | Should -Be $newDbName $schemas.DatabaseId | Should -Be $newDbs[0].Id - $schemas.ComputerName | Should -Be $instance1.ComputerName + $schemas.ComputerName | Should -Be $server1.ComputerName } It "get the dbo schema" { - $schemas = Get-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema dbo -IncludeSystemSchemas + $schemas = Get-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema dbo -IncludeSystemSchemas $schemas.Count | Should -Be 1 $schemas.Name | Should -Be dbo } It "get schemas by owner from a user database" { - $schemas = Get-DbaDbSchema -SqlInstance $instance1 -SchemaOwner $userName + $schemas = Get-DbaDbSchema -SqlInstance $server1 -SchemaOwner $userName $schemas.Count | Should -Be 1 $schemas.Name | Should -Be $schemaName $schemas.Owner | Should -Be $userName $schemas.Parent.Name | Should -Be $newDbName - $schemas = Get-DbaDbSchema -SqlInstance $instance1, $instance2 -Database $newDbName -SchemaOwner $userName, $userName2 + $schemas = Get-DbaDbSchema -SqlInstance $server1, $server2 -Database $newDbName -SchemaOwner $userName, $userName2 $schemas.Count | Should -Be 2 $schemas.Name | Should -Be $schemaName, $schemaName2 $schemas.Owner | Should -Be $userName, $userName2 @@ -113,26 +113,26 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "get a schema and then change the owner" { - $schemas = Get-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema $schemaName + $schemas = Get-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema $schemaName $schemas.Count | Should -Be 1 $schemas.Owner | Should -Be $userName $schemas.Owner = $userName2 $schemas.Alter() - $schemas = Get-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema $schemaName + $schemas = Get-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema $schemaName $schemas.Count | Should -Be 1 $schemas.Owner | Should -Be $userName2 } It "get a schema and then drop it (assuming that it does not contain any objects)" { - $schemas = Get-DbaDbSchema -SqlInstance $instance2 -Database $newDbName -Schema $schemaName2 + $schemas = Get-DbaDbSchema -SqlInstance $server2 -Database $newDbName -Schema $schemaName2 $schemas.Count | Should -Be 1 $schemas.Owner | Should -Be $userName2 $schemas.Drop() - $schemas = Get-DbaDbSchema -SqlInstance $instance2 -Database $newDbName -Schema $schemaName2 + $schemas = Get-DbaDbSchema -SqlInstance $server2 -Database $newDbName -Schema $schemaName2 $schemas | Should -BeNullOrEmpty } } diff --git a/tests/Get-DbaExtendedProperty.Tests.ps1 b/tests/Get-DbaExtendedProperty.Tests.ps1 index a362171c38..d9fa10d14f 100644 --- a/tests/Get-DbaExtendedProperty.Tests.ps1 +++ b/tests/Get-DbaExtendedProperty.Tests.ps1 @@ -16,10 +16,10 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Get-DbaProcess -SqlInstance $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $null = Get-DbaProcess -SqlInstance $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" - $db = New-DbaDatabase -SqlInstance $instance2 -Name $newDbName + $db = New-DbaDatabase -SqlInstance $server2 -Name $newDbName $db.Query("EXEC sys.sp_addextendedproperty @name=N'dbatoolz', @value=N'woo'") #$tempdb = Get-DbaDatabase -SqlInstance $script:instance2 -Database tempdb #$tempdb.Query("EXEC sys.sp_addextendedproperty @name=N'temptoolz', @value=N'woo2'") @@ -32,12 +32,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "commands work as expected" { It "finds an extended property on an instance" { - $ep = Get-DbaExtendedProperty -SqlInstance $instance2 + $ep = Get-DbaExtendedProperty -SqlInstance $server2 $ep.Count | Should -BeGreaterThan 0 } It "finds a sequence in a single database" { - $ep = Get-DbaExtendedProperty -SqlInstance $instance2 -Database $db.Name + $ep = Get-DbaExtendedProperty -SqlInstance $server2 -Database $db.Name $ep.Parent.Name | Select-Object -Unique | Should -Be $db.Name $ep.Count | Should -Be 1 } diff --git a/tests/Get-DbaLinkedServerLogin.Tests.ps1 b/tests/Get-DbaLinkedServerLogin.Tests.ps1 index 772e2e411a..62abe23774 100644 --- a/tests/Get-DbaLinkedServerLogin.Tests.ps1 +++ b/tests/Get-DbaLinkedServerLogin.Tests.ps1 @@ -16,8 +16,8 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $instance3 = Connect-DbaInstance -SqlInstance $script:instance3 + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server3 = Connect-DbaInstance -SqlInstance $script:instance3 $securePassword = ConvertTo-SecureString -String 's3cur3P4ssw0rd?' -AsPlainText -Force $localLogin1Name = "dbatoolscli_localLogin1_$random" @@ -27,11 +27,11 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $linkedServer1Name = "dbatoolscli_linkedServer1_$random" $linkedServer2Name = "dbatoolscli_linkedServer2_$random" - New-DbaLogin -SqlInstance $instance2 -Login $localLogin1Name, $localLogin2Name -SecurePassword $securePassword - New-DbaLogin -SqlInstance $instance3 -Login $remoteLoginName -SecurePassword $securePassword + New-DbaLogin -SqlInstance $server2 -Login $localLogin1Name, $localLogin2Name -SecurePassword $securePassword + New-DbaLogin -SqlInstance $server3 -Login $remoteLoginName -SecurePassword $securePassword - $linkedServer1 = New-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServer1Name -ServerProduct mssql -Provider sqlncli -DataSource $instance3 - $linkedServer2 = New-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServer2Name -ServerProduct mssql -Provider sqlncli -DataSource $instance3 + $linkedServer1 = New-DbaLinkedServer -SqlInstance $server2 -LinkedServer $linkedServer1Name -ServerProduct mssql -Provider sqlncli -DataSource $server3 + $linkedServer2 = New-DbaLinkedServer -SqlInstance $server2 -LinkedServer $linkedServer2Name -ServerProduct mssql -Provider sqlncli -DataSource $server3 $newLinkedServerLogin1 = New-Object Microsoft.SqlServer.Management.Smo.LinkedServerLogin $newLinkedServerLogin1.Parent = $linkedServer1 @@ -58,27 +58,27 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $newLinkedServerLogin3.Create() } AfterAll { - Remove-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServer1Name, $linkedServer2Name -Confirm:$false -Force - Remove-DbaLogin -SqlInstance $instance2 -Login $localLogin1Name, $localLogin2Name -Confirm:$false - Remove-DbaLogin -SqlInstance $instance3 -Login $remoteLoginName -Confirm:$false + Remove-DbaLinkedServer -SqlInstance $server2 -LinkedServer $linkedServer1Name, $linkedServer2Name -Confirm:$false -Force + Remove-DbaLogin -SqlInstance $server2 -Login $localLogin1Name, $localLogin2Name -Confirm:$false + Remove-DbaLogin -SqlInstance $server3 -Login $remoteLoginName -Confirm:$false } Context "ensure command works" { It "Check the validation for a linked server" { - $results = Get-DbaLinkedServerLogin -SqlInstance $instance2 -LocalLogin $localLogin1Name -WarningVariable warnings 3> $null + $results = Get-DbaLinkedServerLogin -SqlInstance $server2 -LocalLogin $localLogin1Name -WarningVariable warnings 3> $null $warnings | Should -BeLike "*LinkedServer is required*" $results | Should -BeNullOrEmpty } It "Get a linked server login" { - $results = Get-DbaLinkedServerLogin -SqlInstance $instance2 -LinkedServer $linkedServer1Name -LocalLogin $localLogin1Name + $results = Get-DbaLinkedServerLogin -SqlInstance $server2 -LinkedServer $linkedServer1Name -LocalLogin $localLogin1Name $results | Should -Not -BeNullOrEmpty $results.Name | Should -Be $localLogin1Name $results.RemoteUser | Should -Be $remoteLoginName $results.Impersonate | Should -Be $false - $results = Get-DbaLinkedServerLogin -SqlInstance $instance2 -LinkedServer $linkedServer1Name -LocalLogin $localLogin1Name, $localLogin2Name + $results = Get-DbaLinkedServerLogin -SqlInstance $server2 -LinkedServer $linkedServer1Name -LocalLogin $localLogin1Name, $localLogin2Name $results.length | Should -Be 2 $results.Name | Should -Be $localLogin1Name, $localLogin2Name $results.RemoteUser | Should -Be $remoteLoginName, $remoteLoginName @@ -86,14 +86,14 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Get a linked server login and exclude a login" { - $results = Get-DbaLinkedServerLogin -SqlInstance $instance2 -LinkedServer $linkedServer1Name -ExcludeLocalLogin $localLogin1Name + $results = Get-DbaLinkedServerLogin -SqlInstance $server2 -LinkedServer $linkedServer1Name -ExcludeLocalLogin $localLogin1Name $results | Should -Not -BeNullOrEmpty $results.Name | Should -Contain $localLogin2Name $results.Name | Should -Not -Contain $localLogin1Name } It "Get a linked server login by passing in a server via pipeline" { - $results = $instance2 | Get-DbaLinkedServerLogin -LinkedServer $linkedServer1Name -LocalLogin $localLogin1Name + $results = $server2 | Get-DbaLinkedServerLogin -LinkedServer $linkedServer1Name -LocalLogin $localLogin1Name $results | Should -Not -BeNullOrEmpty $results.Name | Should -Be $localLogin1Name } @@ -105,7 +105,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Get a linked server login from multiple linked servers" { - $results = Get-DbaLinkedServerLogin -SqlInstance $instance2 -LinkedServer $linkedServer1Name, $linkedServer2Name -LocalLogin $localLogin1Name + $results = Get-DbaLinkedServerLogin -SqlInstance $server2 -LinkedServer $linkedServer1Name, $linkedServer2Name -LocalLogin $localLogin1Name $results | Should -Not -BeNullOrEmpty $results.Name | Should -Be $localLogin1Name, $localLogin1Name } diff --git a/tests/Get-DbaServerRoleMember.Tests.ps1 b/tests/Get-DbaServerRoleMember.Tests.ps1 index 1660ce4614..0f35bd6178 100644 --- a/tests/Get-DbaServerRoleMember.Tests.ps1 +++ b/tests/Get-DbaServerRoleMember.Tests.ps1 @@ -15,35 +15,35 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $instance = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 $password1 = ConvertTo-SecureString 'password1' -AsPlainText -Force $testLogin = 'getDbaInstanceRoleMemberLogin' - $null = New-DbaLogin -SqlInstance $instance -Login $testLogin -Password $password1 - $null = Set-DbaLogin -SqlInstance $instance -Login $testLogin -AddRole 'dbcreator' + $null = New-DbaLogin -SqlInstance $server2 -Login $testLogin -Password $password1 + $null = Set-DbaLogin -SqlInstance $server2 -Login $testLogin -AddRole 'dbcreator' - $instance1 = Connect-DbaInstance -SqlInstance $script:instance1 - $null = New-DbaLogin -SqlInstance $instance1 -Login $testLogin -Password $password1 - $null = Set-DbaLogin -SqlInstance $instance1 -Login $testLogin -AddRole 'dbcreator' + $server1 = Connect-DbaInstance -SqlInstance $script:instance1 + $null = New-DbaLogin -SqlInstance $server1 -Login $testLogin -Password $password1 + $null = Set-DbaLogin -SqlInstance $server1 -Login $testLogin -AddRole 'dbcreator' } Context "Functionality" { It 'Returns all role membership for server roles' { - $result = Get-DbaServerRoleMember -SqlInstance $instance + $result = Get-DbaServerRoleMember -SqlInstance $server2 # should have at least $testLogin and a sysadmin $result.Count | Should -BeGreaterOrEqual 2 } It 'Accepts a list of roles' { - $result = Get-DbaServerRoleMember -SqlInstance $instance -ServerRole 'sysadmin' + $result = Get-DbaServerRoleMember -SqlInstance $server2 -ServerRole 'sysadmin' $uniqueRoles = $result.Role | Select-Object -Unique $uniqueRoles | Should -Be 'sysadmin' } It 'Excludes roles' { - $result = Get-DbaServerRoleMember -SqlInstance $instance -ExcludeServerRole 'dbcreator' + $result = Get-DbaServerRoleMember -SqlInstance $server2 -ExcludeServerRole 'dbcreator' $uniqueRoles = $result.Role | Select-Object -Unique $uniqueRoles | Should -Not -Contain 'dbcreator' @@ -51,13 +51,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Excludes fixed roles' { - $result = Get-DbaServerRoleMember -SqlInstance $instance -ExcludeFixedRole + $result = Get-DbaServerRoleMember -SqlInstance $server2 -ExcludeFixedRole $uniqueRoles = $result.Role | Select-Object -Unique $uniqueRoles | Should -Not -Contain 'sysadmin' } It 'Filters by a specific login' { - $result = Get-DbaServerRoleMember -SqlInstance $instance -Login $testLogin + $result = Get-DbaServerRoleMember -SqlInstance $server2 -Login $testLogin $uniqueLogins = $result.Name | Select-Object -Unique $uniqueLogins.Count | Should -BeExactly 1 @@ -65,7 +65,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } It 'Returns results for all instances' { - $result = Get-DbaServerRoleMember -SqlInstance $instance, $instance1 -Login $testLogin + $result = Get-DbaServerRoleMember -SqlInstance $server2, $server1 -Login $testLogin $uniqueInstances = $result.SqlInstance | Select-Object -Unique $uniqueInstances.Count | Should -BeExactly 2 @@ -73,7 +73,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } AfterAll { - Remove-DbaLogin -SqlInstance $instance -Login $testLogin -Force -Confirm:$false - Remove-DbaLogin -SqlInstance $instance1 -Login $testLogin -Force -Confirm:$false + Remove-DbaLogin -SqlInstance $server2 -Login $testLogin -Force -Confirm:$false + Remove-DbaLogin -SqlInstance $server1 -Login $testLogin -Force -Confirm:$false } } \ No newline at end of file diff --git a/tests/New-DbaAgentOperator.Tests.ps1 b/tests/New-DbaAgentOperator.Tests.ps1 index 2197fff524..bc6fce76a2 100644 --- a/tests/New-DbaAgentOperator.Tests.ps1 +++ b/tests/New-DbaAgentOperator.Tests.ps1 @@ -15,7 +15,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $random = Get-Random - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 $email1 = "test1$($random)@test.com" $email2 = "test2$($random)@test.com" $email3 = "test3$($random)@test.com" @@ -23,31 +23,31 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { } AfterAll { - $null = Remove-DbaAgentOperator -SqlInstance $instance2 -Operator $email1 -Confirm:$false - $null = Remove-DbaAgentOperator -SqlInstance $instance2 -Operator $email2 -Confirm:$false - $null = Remove-DbaAgentOperator -SqlInstance $instance2 -Operator $email3 -Confirm:$false - $null = Remove-DbaAgentOperator -SqlInstance $instance2 -Operator $email4 -Confirm:$false + $null = Remove-DbaAgentOperator -SqlInstance $server2 -Operator $email1 -Confirm:$false + $null = Remove-DbaAgentOperator -SqlInstance $server2 -Operator $email2 -Confirm:$false + $null = Remove-DbaAgentOperator -SqlInstance $server2 -Operator $email3 -Confirm:$false + $null = Remove-DbaAgentOperator -SqlInstance $server2 -Operator $email4 -Confirm:$false } Context "New Agent Operator is added properly" { It "Should have the right name" { - $results = New-DbaAgentOperator -SqlInstance $instance2 -Operator $email1 -EmailAddress $email1 -PagerDay Everyday -Force + $results = New-DbaAgentOperator -SqlInstance $server2 -Operator $email1 -EmailAddress $email1 -PagerDay Everyday -Force $results.Name | Should Be $email1 } It "Create an agent operator with only the defaults" { - $results = New-DbaAgentOperator -SqlInstance $instance2 -Operator $email2 -EmailAddress $email2 + $results = New-DbaAgentOperator -SqlInstance $server2 -Operator $email2 -EmailAddress $email2 $results.Name | Should Be $email2 } It "Pipeline command" { - $results = $instance2 | New-DbaAgentOperator -Operator $email3 -EmailAddress $email3 + $results = $server2 | New-DbaAgentOperator -Operator $email3 -EmailAddress $email3 $results.Name | Should Be $email3 } It "Creates an agent operator with all params" { - $results = New-DbaAgentOperator -SqlInstance $instance2 -Operator $email4 -EmailAddress $email4 -NetSendAddress dbauser1 -PagerAddress dbauser1@pager.dbatools.io -PagerDay Everyday -SaturdayStartTime 070000 -SaturdayEndTime 180000 -SundayStartTime 080000 -SundayEndTime 170000 -WeekdayStartTime 060000 -WeekdayEndTime 190000 + $results = New-DbaAgentOperator -SqlInstance $server2 -Operator $email4 -EmailAddress $email4 -NetSendAddress dbauser1 -PagerAddress dbauser1@pager.dbatools.io -PagerDay Everyday -SaturdayStartTime 070000 -SaturdayEndTime 180000 -SundayStartTime 080000 -SundayEndTime 170000 -WeekdayStartTime 060000 -WeekdayEndTime 190000 $results.Enabled | Should -Be $true $results.Name | Should Be $email4 $results.EmailAddress | Should -Be $email4 diff --git a/tests/New-DbaDbSchema.Tests.ps1 b/tests/New-DbaDbSchema.Tests.ps1 index 39734bf7f0..abef66b323 100644 --- a/tests/New-DbaDbSchema.Tests.ps1 +++ b/tests/New-DbaDbSchema.Tests.ps1 @@ -16,18 +16,18 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance1 = Connect-DbaInstance -SqlInstance $script:instance1 - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Get-DbaProcess -SqlInstance $instance1, $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false + $server1 = Connect-DbaInstance -SqlInstance $script:instance1 + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" - $newDbs = New-DbaDatabase -SqlInstance $instance1, $instance2 -Name $newDbName + $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName $userName = "user_$random" $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $logins = New-DbaLogin -SqlInstance $instance1, $instance2 -Login $userName -Password $securePassword -Force + $logins = New-DbaLogin -SqlInstance $server1, $server2 -Login $userName -Password $securePassword -Force - $null = New-DbaDbUser -SqlInstance $instance1, $instance2 -Database $newDbName -Login $userName + $null = New-DbaDbUser -SqlInstance $server1, $server2 -Database $newDbName -Login $userName } AfterAll { @@ -38,23 +38,23 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "commands work as expected" { It "validates required Schema" { - $schema = New-DbaDbSchema -SqlInstance $instance1 + $schema = New-DbaDbSchema -SqlInstance $server1 $schema | Should -BeNullOrEmpty } It "validates required Database param" { - $schema = New-DbaDbSchema -SqlInstance $instance1 -Schema TestSchema1 + $schema = New-DbaDbSchema -SqlInstance $server1 -Schema TestSchema1 $schema | Should -BeNullOrEmpty } It "creates a new schema" { - $schema = New-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema TestSchema1 -SchemaOwner $userName + $schema = New-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema TestSchema1 -SchemaOwner $userName $schema.Count | Should -Be 1 $schema.Owner | Should -Be $userName $schema.Name | Should -Be TestSchema1 $schema.Parent.Name | Should -Be $newDbName - $schemas = New-DbaDbSchema -SqlInstance $instance1, $instance2 -Database $newDbName -Schema TestSchema2, TestSchema3 -SchemaOwner $userName + $schemas = New-DbaDbSchema -SqlInstance $server1, $server2 -Database $newDbName -Schema TestSchema2, TestSchema3 -SchemaOwner $userName $schemas.Count | Should -Be 4 $schemas.Owner | Should -Be $userName, $userName, $userName, $userName $schemas.Name | Should -Be TestSchema2, TestSchema3, TestSchema2, TestSchema3 @@ -62,12 +62,12 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "reports a warning that the schema already exists" { - $schema = New-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema TestSchema1 -SchemaOwner $userName + $schema = New-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema TestSchema1 -SchemaOwner $userName $schema | Should -BeNullOrEmpty } It "supports piping databases" { - $schema = Get-DbaDatabase -SqlInstance $instance1 -Database $newDbName | New-DbaDbSchema -Schema TestSchema4 + $schema = Get-DbaDatabase -SqlInstance $server1 -Database $newDbName | New-DbaDbSchema -Schema TestSchema4 $schema.Count | Should -Be 1 $schema.Owner | Should -Be dbo $schema.Name | Should -Be TestSchema4 diff --git a/tests/Remove-DbaDbSchema.Tests.ps1 b/tests/Remove-DbaDbSchema.Tests.ps1 index 12dfbae446..f532a3b434 100644 --- a/tests/Remove-DbaDbSchema.Tests.ps1 +++ b/tests/Remove-DbaDbSchema.Tests.ps1 @@ -16,11 +16,11 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance1 = Connect-DbaInstance -SqlInstance $script:instance1 - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Get-DbaProcess -SqlInstance $instance1, $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false + $server1 = Connect-DbaInstance -SqlInstance $script:instance1 + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" - $newDbs = New-DbaDatabase -SqlInstance $instance1, $instance2 -Name $newDbName + $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName } AfterAll { @@ -30,34 +30,34 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "commands work as expected" { It "drops the schema" { - $schema = New-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema TestSchema1 + $schema = New-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema TestSchema1 $schema.Count | Should -Be 1 $schema.Name | Should -Be TestSchema1 $schema.Parent.Name | Should -Be $newDbName - Remove-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema TestSchema1 -Confirm:$false + Remove-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema TestSchema1 -Confirm:$false - (Get-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema TestSchema1) | Should -BeNullOrEmpty + (Get-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema TestSchema1) | Should -BeNullOrEmpty - $schemas = New-DbaDbSchema -SqlInstance $instance1, $instance2 -Database $newDbName -Schema TestSchema2, TestSchema3 + $schemas = New-DbaDbSchema -SqlInstance $server1, $server2 -Database $newDbName -Schema TestSchema2, TestSchema3 $schemas.Count | Should -Be 4 $schemas.Name | Should -Be TestSchema2, TestSchema3, TestSchema2, TestSchema3 $schemas.Parent.Name | Should -Be $newDbName, $newDbName, $newDbName, $newDbName - Remove-DbaDbSchema -SqlInstance $instance1, $instance2 -Database $newDbName -Schema TestSchema2, TestSchema3 -Confirm:$false + Remove-DbaDbSchema -SqlInstance $server1, $server2 -Database $newDbName -Schema TestSchema2, TestSchema3 -Confirm:$false - (Get-DbaDbSchema -SqlInstance $instance1, $instance2 -Database $newDbName -Schema TestSchema2, TestSchema3) | Should -BeNullOrEmpty + (Get-DbaDbSchema -SqlInstance $server1, $server2 -Database $newDbName -Schema TestSchema2, TestSchema3) | Should -BeNullOrEmpty } It "supports piping databases" { - $schema = New-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema TestSchema1 + $schema = New-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema TestSchema1 $schema.Count | Should -Be 1 $schema.Name | Should -Be TestSchema1 $schema.Parent.Name | Should -Be $newDbName - Get-DbaDatabase -SqlInstance $instance1 -Database $newDbName | Remove-DbaDbSchema -Schema TestSchema1 -Confirm:$false + Get-DbaDatabase -SqlInstance $server1 -Database $newDbName | Remove-DbaDbSchema -Schema TestSchema1 -Confirm:$false - (Get-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema TestSchema1) | Should -BeNullOrEmpty + (Get-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema TestSchema1) | Should -BeNullOrEmpty } } } \ No newline at end of file diff --git a/tests/Set-DbaDbSchema.Tests.ps1 b/tests/Set-DbaDbSchema.Tests.ps1 index 637995e685..12a300cb5a 100644 --- a/tests/Set-DbaDbSchema.Tests.ps1 +++ b/tests/Set-DbaDbSchema.Tests.ps1 @@ -16,20 +16,20 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { BeforeAll { $random = Get-Random - $instance1 = Connect-DbaInstance -SqlInstance $script:instance1 - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 - $null = Get-DbaProcess -SqlInstance $instance1, $instance2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false + $server1 = Connect-DbaInstance -SqlInstance $script:instance1 + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 + $null = Get-DbaProcess -SqlInstance $server1, $server2 | Where-Object Program -match dbatools | Stop-DbaProcess -Confirm:$false $newDbName = "dbatoolsci_newdb_$random" - $newDbs = New-DbaDatabase -SqlInstance $instance1, $instance2 -Name $newDbName + $newDbs = New-DbaDatabase -SqlInstance $server1, $server2 -Name $newDbName $userName = "user_$random" $userName2 = "user2_$random" $password = 'MyV3ry$ecur3P@ssw0rd' $securePassword = ConvertTo-SecureString $password -AsPlainText -Force - $logins = New-DbaLogin -SqlInstance $instance1, $instance2 -Login $userName, $userName2 -Password $securePassword -Force + $logins = New-DbaLogin -SqlInstance $server1, $server2 -Login $userName, $userName2 -Password $securePassword -Force - $null = New-DbaDbUser -SqlInstance $instance1, $instance2 -Database $newDbName -Login $userName - $null = New-DbaDbUser -SqlInstance $instance1, $instance2 -Database $newDbName -Login $userName2 + $null = New-DbaDbUser -SqlInstance $server1, $server2 -Database $newDbName -Login $userName + $null = New-DbaDbUser -SqlInstance $server1, $server2 -Database $newDbName -Login $userName2 } AfterAll { @@ -40,25 +40,25 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "commands work as expected" { It "updates the schema to a different owner" { - $schema = New-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema TestSchema1 -SchemaOwner $userName + $schema = New-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema TestSchema1 -SchemaOwner $userName $schema.Count | Should -Be 1 $schema.Owner | Should -Be $userName $schema.Name | Should -Be TestSchema1 $schema.Parent.Name | Should -Be $newDbName - $updatedSchema = Set-DbaDbSchema -SqlInstance $instance1 -Database $newDbName -Schema TestSchema1 -SchemaOwner $userName2 + $updatedSchema = Set-DbaDbSchema -SqlInstance $server1 -Database $newDbName -Schema TestSchema1 -SchemaOwner $userName2 $updatedSchema.Count | Should -Be 1 $updatedSchema.Owner | Should -Be $userName2 $updatedSchema.Name | Should -Be TestSchema1 $updatedSchema.Parent.Name | Should -Be $newDbName - $schemas = New-DbaDbSchema -SqlInstance $instance1, $instance2 -Database $newDbName -Schema TestSchema2, TestSchema3 -SchemaOwner $userName + $schemas = New-DbaDbSchema -SqlInstance $server1, $server2 -Database $newDbName -Schema TestSchema2, TestSchema3 -SchemaOwner $userName $schemas.Count | Should -Be 4 $schemas.Owner | Should -Be $userName, $userName, $userName, $userName $schemas.Name | Should -Be TestSchema2, TestSchema3, TestSchema2, TestSchema3 $schemas.Parent.Name | Should -Be $newDbName, $newDbName, $newDbName, $newDbName - $updatedSchemas = Set-DbaDbSchema -SqlInstance $instance1, $instance2 -Database $newDbName -Schema TestSchema2, TestSchema3 -SchemaOwner $userName2 + $updatedSchemas = Set-DbaDbSchema -SqlInstance $server1, $server2 -Database $newDbName -Schema TestSchema2, TestSchema3 -SchemaOwner $userName2 $updatedSchemas.Count | Should -Be 4 $schemas.Owner | Should -Be $userName2, $userName2, $userName2, $userName2 $schemas.Name | Should -Be TestSchema2, TestSchema3, TestSchema2, TestSchema3 @@ -66,7 +66,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "supports piping databases" { - $schema = Get-DbaDatabase -SqlInstance $instance1 -Database $newDbName | Set-DbaDbSchema -Schema TestSchema1 -SchemaOwner $userName + $schema = Get-DbaDatabase -SqlInstance $server1 -Database $newDbName | Set-DbaDbSchema -Schema TestSchema1 -SchemaOwner $userName $schema.Count | Should -Be 1 $schema.Owner | Should -Be $userName $schema.Name | Should -Be TestSchema1 diff --git a/tests/Watch-DbaDbLogin.Tests.ps1 b/tests/Watch-DbaDbLogin.Tests.ps1 index 3e4f5af530..b00f74aa8a 100644 --- a/tests/Watch-DbaDbLogin.Tests.ps1 +++ b/tests/Watch-DbaDbLogin.Tests.ps1 @@ -29,8 +29,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $script:instance1, $script:instance2 | Out-File $testFile - $instance1 = Connect-DbaInstance -SqlInstance $script:instance1 - $instance2 = Connect-DbaInstance -SqlInstance $script:instance2 + $server1 = Connect-DbaInstance -SqlInstance $script:instance1 + $server2 = Connect-DbaInstance -SqlInstance $script:instance2 $regServer1 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $script:instance1 -Name "dbatoolsci_instance1_$random" $regServer2 = Add-DbaRegServer -SqlInstance $script:instance1 -ServerName $script:instance2 -Name "dbatoolsci_instance2_$random" @@ -50,7 +50,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Pipeline of instances" { - $instance1, $instance2 | Watch-DbaDbLogin -SqlInstance $script:instance1 -Database $databaseName -Table $tableName2 -EnableException + $server1, $server2 | Watch-DbaDbLogin -SqlInstance $script:instance1 -Database $databaseName -Table $tableName2 -EnableException $result = Get-DbaDbTable -SqlInstance $script:instance1 -Database $databaseName -Table $tableName2 -IncludeSystemDBs $result.Name | Should Be $tableName2 $result.Count | Should BeGreaterThan 0 From 7eec68081ee177f8923ad622f28c1187a8fb970e Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Mon, 14 Oct 2024 10:10:09 +0200 Subject: [PATCH 20/22] Mount-DbaDatabase: Deduplicate filepaths if more that one backup is in the last backup file (#9504) --- public/Mount-DbaDatabase.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/Mount-DbaDatabase.ps1 b/public/Mount-DbaDatabase.ps1 index 45670fbceb..c9eb8dcd2e 100644 --- a/public/Mount-DbaDatabase.ps1 +++ b/public/Mount-DbaDatabase.ps1 @@ -115,7 +115,7 @@ function Mount-DbaDatabase { } $backupfile = $backuphistory.Path[0] - $filepaths = (Read-DbaBackupHeader -SqlInstance $server -FileList -Path $backupfile).PhysicalName + $filepaths = (Read-DbaBackupHeader -SqlInstance $server -FileList -Path $backupfile).PhysicalName | Select-Object -Unique $FileStructure = New-Object System.Collections.Specialized.StringCollection foreach ($file in $filepaths) { From 0b9be65c359cbae08e9ec5d3ae0b1a37ff747c30 Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Mon, 14 Oct 2024 10:10:56 +0200 Subject: [PATCH 21/22] Connect-DbaInstance: Fix for issue when changing database context (#9505) --- public/Connect-DbaInstance.ps1 | 5 ++++- tests/Connect-DbaInstance.Tests.ps1 | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/public/Connect-DbaInstance.ps1 b/public/Connect-DbaInstance.ps1 index 368c8d6fdc..e8e4697123 100644 --- a/public/Connect-DbaInstance.ps1 +++ b/public/Connect-DbaInstance.ps1 @@ -639,10 +639,13 @@ function Connect-DbaInstance { if ($Database) { # Save StatementTimeout because it might be reset on GetDatabaseConnection $savedStatementTimeout = $connContext.StatementTimeout - $connContext = $connContext.GetDatabaseConnection($Database) + $connContext = $connContext.GetDatabaseConnection($Database, $false) $connContext.StatementTimeout = $savedStatementTimeout } $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $connContext + if ($Database -and $server.ConnectionContext.CurrentDatabase -ne $Database) { + Write-Message -Level Warning -Message "Changing connection context to database $Database was not successful. Current database is $($server.ConnectionContext.CurrentDatabase). Please open an issue on https://github.com/dataplat/dbatools/issues." + } } else { $server = $inputObject } diff --git a/tests/Connect-DbaInstance.Tests.ps1 b/tests/Connect-DbaInstance.Tests.ps1 index 7c066e83db..3f849bf67e 100644 --- a/tests/Connect-DbaInstance.Tests.ps1 +++ b/tests/Connect-DbaInstance.Tests.ps1 @@ -206,6 +206,13 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $serverClone.ConnectionContext.ServerInstance | Should -Match '^ADMIN:' $serverClone | Disconnect-DbaInstance } + + It "clones when using Backup-DabInstace" { + $server = Connect-DbaInstance -SqlInstance $script:instance1 -Database tempdb + $null = Backup-DbaDatabase -SqlInstance $server -Database msdb + $null = Backup-DbaDatabase -SqlInstance $server -Database msdb -WarningVariable warn + $warn | Should -BeNullOrEmpty + } } Context "multiple connections are properly made using strings" { From 1123b2df6b37ec83f24a87b1ba39cc57a7da86b1 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Mon, 14 Oct 2024 10:16:39 +0200 Subject: [PATCH 22/22] 2.1.26 --- bin/dbatools-index.json | Bin 8895224 -> 8895236 bytes dbatools.psd1 | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/dbatools-index.json b/bin/dbatools-index.json index 9c8e053d410b236b1dfa49a4eb914d16038328d6..3c2517a740efea3252b2f0dbdaa7c3d2927a6935 100644 GIT binary patch delta 500 zcmZ9_NjKF20EY2{D_1h4NlEBlMTwLqHxWvu42@JYpeRimToJc=uxr`f`2g0=`ET_B zTDEUt-Lc8B?6K=u{5J3Vp7XB#oe!}(A4-ryDrtmBXA>EO$z(HGY$2N*a>-*W`D|l5 zJJ`uC3fRpa3fW5$`zWS_QuY%eN*M<@NI4Z8;xLsQp^9pbQo}KhQ_BfXa*ETOp^g}5 zsplLGG;*G%#pdN7-+v|YgOWdy$&_GaBKkWsX#d%~Q2k%pSyWJ&5iIqLcBdxo`jX!w z(Qq&lZdt9^xJtTuI2Vt#=z=b)RhM*GSJbAfx~6t@s8e0Kt{b|kTe__~>Q;~L>Ynba zSABY*_0LCotbPq>P*3z!LmJjIJ=cg{=%rriwccn{Z}m>^^+98bYg`{Sp-Fwxl%|!? RXMNFEp&88v@z`8q`X9vW!;}C3 delta 552 zcmZw8SyPR10D$qSUdL+-*|KxwC|hJFN1c<_XyVUsG(ZWZlo2t76jOoy-f_cnm z0Sj3~C5u_YQkJot6|7_xt4XtlD%O%=9o5vZo(*hd6Pu}J3tOpU8{65zPIj@IJ?v#4 z_3S6h0UBr|_bos6BeaiIXG7QD`pWRLvoA^->M~VvQmDxME)B(8OLQS%y^i