diff --git a/bin/dbatools-index.json b/bin/dbatools-index.json index fa075fd97b..d78d379354 100644 Binary files a/bin/dbatools-index.json and b/bin/dbatools-index.json differ diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql index b73f294600..d2397de12f 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: May 2, 2024 +-- Last Modified: May 17, 2024 -- https://glennsqlperformance.com/ -- https://sqlserverperformance.wordpress.com/ -- YouTube: https://bit.ly/2PkoAM1 @@ -79,6 +79,7 @@ SELECT @@SERVERNAME AS [Server Name], @@VERSION AS [SQL Server and OS Version In -- 16.0.4105.2 CU11 1/11/2024 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate11 -- 16.0.4115.5 CU12 3/14/2024 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate12 -- 16.0.4120.1 CU12 + GDR 4/9/2024 https://support.microsoft.com/en-us/topic/kb5036343-description-of-the-security-update-for-sql-server-2022-cu12-april-9-2024-e11a0715-435f-42be-89ff-4b3d8f9734fc +-- 16.0.4125.3 CU13 5/16/2024 https://learn.microsoft.com/en-us/troubleshoot/sql/releases/sqlserver-2022/cumulativeupdate13 -- What's new in SQL Server 2022 (16.x) -- https://bit.ly/3MJEjR1 @@ -195,6 +196,7 @@ ORDER BY name OPTION (RECOMPILE); -- Data processed monthly limit in TB SQL On-demand data processed monthly limit in TB -- Data processed weekly limit in TB SQL On-demand data processed weekly limit in TB -- hardware offload config Offload processing to specialized hardware +-- max RPC request params (KB) Maximum memory for RPC request parameters (kBytes) (added in CU13) -- openrowset auto_create_statistics Enable or disable auto create statistics for openrowset sources. -- suppress recovery model errors Return warning instead of error for unsupported ALTER DATABASE SET RECOVERY command diff --git a/dbatools.psd1 b/dbatools.psd1 index 998f59aac6..b77e63d024 100644 --- a/dbatools.psd1 +++ b/dbatools.psd1 @@ -11,7 +11,7 @@ RootModule = 'dbatools.psm1' # Version number of this module. - ModuleVersion = '2.1.15' + ModuleVersion = '2.1.16' # ID used to uniquely identify this module GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789' diff --git a/public/Backup-DbaDbMasterKey.ps1 b/public/Backup-DbaDbMasterKey.ps1 index 07b2f60e14..1c1ac00bb1 100644 --- a/public/Backup-DbaDbMasterKey.ps1 +++ b/public/Backup-DbaDbMasterKey.ps1 @@ -144,16 +144,16 @@ function Backup-DbaDbMasterKey { } $fileinstance = $instance.ToString().Replace('\', '$') - $fullKeyName = Join-DbaPath -SqlInstance $server -Path $actualPath -ChildPath "$fileinstance-$dbname-masterkey" + $filename = Join-DbaPath -SqlInstance $server -Path $actualPath -ChildPath "$fileinstance-$dbname-masterkey.key" # if the base file name exists, then default to old style of appending a timestamp - if (Test-DbaPath -SqlInstance $server -Path "$fullKeyName.key") { - $fullKeyName = "$fullKeyName-$time" + if (Test-DbaPath -SqlInstance $server -Path $filename) { + $filename = Join-DbaPath -SqlInstance $server -Path $actualPath -ChildPath "$fileinstance-$dbname-masterkey-$time.key" } - if ($Pscmdlet.ShouldProcess($instance, "Backing up master key to $fullKeyName")) { + if ($Pscmdlet.ShouldProcess($instance, "Backing up master key to $filename")) { try { - $masterkey.Export("$fullKeyName.key", ($SecurePassword | ConvertFrom-SecurePass)) + $masterkey.Export($filename, ($SecurePassword | ConvertFrom-SecurePass)) $status = "Success" } catch { $status = "Failure" @@ -168,7 +168,7 @@ function Backup-DbaDbMasterKey { Add-Member -Force -InputObject $masterkey -MemberType NoteProperty -Name SqlInstance -value $server.DomainInstanceName Add-Member -Force -InputObject $masterkey -MemberType NoteProperty -Name Database -value $dbName Add-Member -Force -InputObject $masterkey -MemberType NoteProperty -Name DatabaseID -value $db.ID - Add-Member -Force -InputObject $masterkey -MemberType NoteProperty -Name Filename -value $fullKeyName + Add-Member -Force -InputObject $masterkey -MemberType NoteProperty -Name Filename -value $filename Add-Member -Force -InputObject $masterkey -MemberType NoteProperty -Name Status -value $status Select-DefaultView -InputObject $masterkey -Property ComputerName, InstanceName, SqlInstance, Database, 'Filename as Path', Status diff --git a/public/ConvertTo-DbaDataTable.ps1 b/public/ConvertTo-DbaDataTable.ps1 index c0bbecd772..c09613162c 100644 --- a/public/ConvertTo-DbaDataTable.ps1 +++ b/public/ConvertTo-DbaDataTable.ps1 @@ -166,11 +166,13 @@ function ConvertTo-DbaDataTable { } } $specialType = 'Size' - } elseif ($type -eq 'Dataplat.Dbatools.Utility.DbaDateTime') { - $special = $true - $value = [System.DateTime]$value.DateTime - $type = 'System.DateTime' - $specialType = 'DateTime' + } elseif ($type -eq 'Dataplat.Dbatools.Utility.DbaDateTime[]') { + if (-not ($null -eq $value)) { + $special = $true + $value = $value + $type = 'System.String' + $specialType = 'String' + } } elseif (-not ($type -in $types)) { # All types which are not found in the array will be converted into strings. # In this way we don't ignore it completely and it will be clear in the end why it looks as it does. @@ -204,7 +206,7 @@ function ConvertTo-DbaDataTable { [CmdletBinding()] param ( $Value, - [ValidateSet('Timespan', 'Size')] + [ValidateSet('Timespan', 'Size', 'DateTime', 'String')] [string]$Type, [string]$SizeType, [string]$TimeSpanType @@ -225,6 +227,9 @@ function ConvertTo-DbaDataTable { 'DateTime' { return [System.DateTime]$Value.DateTime } + 'String' { + return ($Value | Foreach-Object { $_.ToString() }) -join ', ' + } } } diff --git a/public/Install-DbaInstance.ps1 b/public/Install-DbaInstance.ps1 index a3609befae..13a98f78a4 100644 --- a/public/Install-DbaInstance.ps1 +++ b/public/Install-DbaInstance.ps1 @@ -304,6 +304,7 @@ function Install-DbaInstance { [PSCredential]$FTCredential, [PSCredential]$PBEngineCredential, [string]$SaveConfiguration, + [Alias('InstantFileInitialization', 'IFI')] [switch]$PerformVolumeMaintenanceTasks, [switch]$Restart, [switch]$NoPendingRenameCheck = (Get-DbatoolsConfigValue -Name 'OS.PendingRename' -Fallback $false), @@ -701,6 +702,10 @@ function Install-DbaInstance { $configNode.SQLTEMPDBFILECOUNT = $cores } } + if ($canonicVersion -ge '13.0' -and $PerformVolumeMaintenanceTasks) { + $configNode.SQLSVCINSTANTFILEINIT = 'True' + $PerformVolumeMaintenanceTasks = $false + } if ($canonicVersion -ge '16.0') { $null = $configNode.Remove('X86') } diff --git a/public/Invoke-DbaDbLogShipping.ps1 b/public/Invoke-DbaDbLogShipping.ps1 index 3a5dd34b2a..2dbdc3a44c 100644 --- a/public/Invoke-DbaDbLogShipping.ps1 +++ b/public/Invoke-DbaDbLogShipping.ps1 @@ -928,20 +928,20 @@ function Invoke-DbaDbLogShipping { if (-not $IsDestinationLocal -and $DestinationCredential) { Invoke-Command2 -ComputerName $DestinationServerName -Credential $DestinationCredential -ScriptBlock { Write-Message -Message "Creating copy destination folder $CopyDestinationFolder" -Level Verbose - New-Item -Path $CopyDestinationFolder -ItemType Directory -Credential $DestinationCredential -Force:$Force | Out-Null + $null = New-Item -Path $CopyDestinationFolder -ItemType Directory -Force:$Force } } # If the server is local and the credential is set elseif ($DestinationCredential) { Invoke-Command2 -Credential $DestinationCredential -ScriptBlock { Write-Message -Message "Creating copy destination folder $CopyDestinationFolder" -Level Verbose - New-Item -Path $CopyDestinationFolder -ItemType Directory -Credential $DestinationCredential -Force:$Force | Out-Null + $null = New-Item -Path $CopyDestinationFolder -ItemType Directory -Force:$Force } } # If the server is local and the credential is not set else { Write-Message -Message "Creating copy destination folder $CopyDestinationFolder" -Level Verbose - New-Item -Path $CopyDestinationFolder -Force:$Force -ItemType Directory | Out-Null + $null = New-Item -Path $CopyDestinationFolder -ItemType Directory -Force:$Force } Write-Message -Message "Copy destination $CopyDestinationFolder created." -Level Verbose } catch { @@ -963,7 +963,7 @@ function Invoke-DbaDbLogShipping { # Try to create the copy destination on the local server try { Write-Message -Message "Creating copy destination folder $CopyDestinationFolder" -Level Verbose - New-Item $CopyDestinationFolder -ItemType Directory -Credential $DestinationCredential -Force:$Force | Out-Null + $null = New-Item -Path $CopyDestinationFolder -ItemType Directory -Force:$Force Write-Message -Message "Copy destination $CopyDestinationFolder created." -Level Verbose } catch { $setupResult = "Failed" @@ -1090,7 +1090,7 @@ function Invoke-DbaDbLogShipping { Invoke-Command2 -Credential $SourceCredential -ScriptBlock { Write-Message -Message "Creating backup folder $DatabaseSharedPath" -Level Verbose - $null = New-Item -Path $DatabaseSharedPath -ItemType Directory -Credential $SourceCredential -Force:$Force + $null = New-Item -Path $DatabaseSharedPath -ItemType Directory -Force:$Force } } catch { $setupResult = "Failed" @@ -1193,7 +1193,7 @@ function Invoke-DbaDbLogShipping { try { Invoke-Command2 -Credential $DestinationCredential -ScriptBlock { Write-Message -Message "Creating data folder $DatabaseRestoreDataFolder" -Level Verbose - $null = New-Item -Path $DatabaseRestoreDataFolder -ItemType Directory -Credential $DestinationCredential -Force:$Force + $null = New-Item -Path $DatabaseRestoreDataFolder -ItemType Directory -Force:$Force } } catch { $setupResult = "Failed" @@ -1213,7 +1213,7 @@ function Invoke-DbaDbLogShipping { Invoke-Command2 -Credential $DestinationCredential -ScriptBlock { Write-Message -Message "Restore log folder $DatabaseRestoreLogFolder not found. Trying to create it.." -Level Verbose - $null = New-Item -Path $DatabaseRestoreLogFolder -ItemType Directory -Credential $DestinationCredential -Force:$Force + $null = New-Item -Path $DatabaseRestoreLogFolder -ItemType Directory -Force:$Force } } catch { $setupResult = "Failed" @@ -1308,7 +1308,7 @@ function Invoke-DbaDbLogShipping { try { Invoke-Command2 -Credential $DestinationCredential -ScriptBlock { Write-Message -Message "Copy destination folder $DatabaseCopyDestinationFolder not found. Trying to create it.. ." -Level Verbose - $null = New-Item -Path $DatabaseCopyDestinationFolder -ItemType Directory -Credential $DestinationCredential -Force:$Force + $null = New-Item -Path $DatabaseCopyDestinationFolder -ItemType Directory -Force:$Force } } catch { $setupResult = "Failed" diff --git a/public/Write-DbaDbTableData.ps1 b/public/Write-DbaDbTableData.ps1 index f2f8b28e31..27abc87d6d 100644 --- a/public/Write-DbaDbTableData.ps1 +++ b/public/Write-DbaDbTableData.ps1 @@ -342,6 +342,11 @@ function Write-DbaDbTableData { $columns = $DataTable.Table.Columns } + if ($null -eq $columns) { + Stop-Function -Message "Unable to get column definition from input data, so AutoCreateTable is not possible" + return + } + foreach ($column in $columns) { $sqlColumnName = $column.ColumnName diff --git a/tests/ConvertTo-DbaDataTable.Tests.ps1 b/tests/ConvertTo-DbaDataTable.Tests.ps1 index eac3148f6c..c152adb932 100644 --- a/tests/ConvertTo-DbaDataTable.Tests.ps1 +++ b/tests/ConvertTo-DbaDataTable.Tests.ps1 @@ -4,7 +4,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[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('WhatIf', 'Confirm') } [object[]]$knownParameters = 'InputObject', 'TimeSpanType', 'SizeType', 'IgnoreNull', 'Raw', 'EnableException' $knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters It "Should only contain our specific parameters" { @@ -15,30 +15,32 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "Testing data table output when using a complex object" { $obj = New-Object -TypeName psobject -Property @{ - guid = [system.guid]'32ccd4c4-282a-4c0d-997c-7b5deb97f9e0' - timespan = New-TimeSpan -Start 2016-10-30 -End 2017-04-30 - datetime = Get-Date -Year 2016 -Month 10 -Day 30 -Hour 5 -Minute 52 -Second 0 -Millisecond 0 - char = [System.Char]'T' - true = $true - false = $false - null = [bool]$null - string = "it's a boy." - UInt64 = [System.UInt64]123456 + guid = [system.guid]'32ccd4c4-282a-4c0d-997c-7b5deb97f9e0' + timespan = New-TimeSpan -Start 2016-10-30 -End 2017-04-30 + datetime = Get-Date -Year 2016 -Month 10 -Day 30 -Hour 5 -Minute 52 -Second 0 -Millisecond 0 + char = [System.Char]'T' + true = $true + false = $false + null = $null + string = "it's a boy." + UInt64 = [System.UInt64]123456 + dbadatetime = [dbadatetime[]]$(Get-Date -Year 2024 -Month 05 -Day 19 -Hour 5 -Minute 52 -Second 0 -Millisecond 0) + dbadatetimeArray = [dbadatetime[]]($(Get-Date -Year 2024 -Month 05 -Day 19 -Hour 5 -Minute 52 -Second 0 -Millisecond 0), $(Get-Date -Year 2024 -Month 05 -Day 19 -Hour 5 -Minute 52 -Second 0 -Millisecond 0).AddHours(1)) } $innedobj = New-Object -TypeName psobject -Property @{ Mission = 'Keep Hank alive' } - Add-Member -Force -InputObject $obj -MemberType NoteProperty -Name myobject -Value $innedobj + Add-Member -Force -InputObject $obj -MemberType NoteProperty -Name myObject -Value $innedobj $result = ConvertTo-DbaDataTable -InputObject $obj Context "Property: guid" { It 'Has a column called "guid"' { - $result.Columns.ColumnName.Contains('guid') | Should Be $true + $result.Columns.ColumnName | Should -Contain 'guid' } It 'Has a [guid] data type on the column "guid"' { - $result.Columns | Where-Object -Property 'ColumnName' -eq 'guid' | Select-Object -ExpandProperty 'DataType' | Select-Object -ExpandProperty Name | Should Be 'guid' + $result.guid | Should -BeOfType [System.guid] } It 'Has the following guid: "32ccd4c4-282a-4c0d-997c-7b5deb97f9e0"' { $result.guid | Should Be '32ccd4c4-282a-4c0d-997c-7b5deb97f9e0' @@ -47,10 +49,11 @@ Describe "Testing data table output when using a complex object" { Context "Property: timespan" { It 'Has a column called "timespan"' { - $result.Columns.ColumnName.Contains('timespan') | Should Be $true + $result.Columns.ColumnName | Should -Contain 'timespan' } It 'Has a [long] data type on the column "timespan"' { - $result.Columns | Where-Object -Property 'ColumnName' -eq 'timespan' | Select-Object -ExpandProperty 'DataType' | Select-Object -ExpandProperty Name | Should Be 'Int64' + $result.timespan | Should -BeOfType [System.Int64] + } It "Has the following timespan: 15724800000" { $result.timespan | Should Be 15724800000 @@ -59,10 +62,10 @@ Describe "Testing data table output when using a complex object" { Context "Property: datetime" { It 'Has a column called "datetime"' { - $result.Columns.ColumnName.Contains('datetime') | Should Be $true + $result.Columns.ColumnName | Should -Contain 'datetime' } It 'Has a [datetime] data type on the column "datetime"' { - $result.Columns | Where-Object -Property 'ColumnName' -eq 'datetime' | Select-Object -ExpandProperty 'DataType' | Select-Object -ExpandProperty Name | Should Be 'datetime' + $result.datetime | Should -BeOfType [System.DateTime] } It "Has the following datetime: 2016-10-30 05:52:00.000" { $date = Get-Date -Year 2016 -Month 10 -Day 30 -Hour 5 -Minute 52 -Second 0 -Millisecond 0 @@ -72,10 +75,10 @@ Describe "Testing data table output when using a complex object" { Context "Property: char" { It 'Has a column called "char"' { - $result.Columns.ColumnName.Contains('char') | Should Be $true + $result.Columns.ColumnName | Should -Contain 'char' } It 'Has a [char] data type on the column "char"' { - $result.Columns | Where-Object -Property 'ColumnName' -eq 'char' | Select-Object -ExpandProperty 'DataType' | Select-Object -ExpandProperty Name | Should Be 'char' + $result.char | Should -BeOfType [System.Char] } It "Has the following char: T" { $result.char | Should Be "T" @@ -84,10 +87,10 @@ Describe "Testing data table output when using a complex object" { Context "Property: true" { It 'Has a column called "true"' { - $result.Columns.ColumnName.Contains('true') | Should Be $true + $result.Columns.ColumnName | Should -Contain 'true' } It 'Has a [bool] data type on the column "true"' { - $result.Columns | Where-Object -Property 'ColumnName' -eq 'true' | Select-Object -ExpandProperty 'DataType' | Select-Object -ExpandProperty Name | Should Be 'boolean' + $result.true | Should -BeOfType [System.Boolean] } It "Has the following bool: true" { $result.true | Should Be $true @@ -96,10 +99,10 @@ Describe "Testing data table output when using a complex object" { Context "Property: false" { It 'Has a column called "false"' { - $result.Columns.ColumnName.Contains('false') | Should Be $true + $result.Columns.ColumnName | Should -Contain 'false' } It 'Has a [bool] data type on the column "false"' { - $result.Columns | Where-Object -Property 'ColumnName' -eq 'false' | Select-Object -ExpandProperty 'DataType' | Select-Object -ExpandProperty Name | Should Be 'boolean' + $result.false | Should -BeOfType [System.Boolean] } It "Has the following bool: false" { $result.false | Should Be $false @@ -108,22 +111,22 @@ Describe "Testing data table output when using a complex object" { Context "Property: null" { It 'Has a column called "null"' { - $result.Columns.ColumnName.Contains('null') | Should Be $true + $result.Columns.ColumnName | Should -Contain 'null' } - It 'Has a [bool] data type on the column "null"' { - $result.Columns | Where-Object -Property 'ColumnName' -eq 'null' | Select-Object -ExpandProperty 'DataType' | Select-Object -ExpandProperty Name | Should Be 'boolean' + It 'Has a [null] data type on the column "null"' { + $result.null | Should -BeOfType [System.DBNull] } - It "Has the following bool: false" { - $result.null | Should Be $false #should actually be $null but its hard to compare :) + It "Has no value" { + $result.null | Should -BeNullOrEmpty } } Context "Property: string" { It 'Has a column called "string"' { - $result.Columns.ColumnName.Contains('string') | Should Be $true + $result.Columns.ColumnName | Should -Contain 'string' } It 'Has a [string] data type on the column "string"' { - $result.Columns | Where-Object -Property 'ColumnName' -eq 'string' | Select-Object -ExpandProperty 'DataType' | Select-Object -ExpandProperty Name | Should Be 'string' + $result.string | Should -BeOfType [System.String] } It "Has the following string: it's a boy." { $result.string | Should Be "it's a boy." @@ -132,29 +135,50 @@ Describe "Testing data table output when using a complex object" { Context "Property: UInt64" { It 'Has a column called "UInt64"' { - $result.Columns.ColumnName.Contains('UInt64') | Should Be $true + $result.Columns.ColumnName | Should -Contain 'UInt64' } It 'Has a [UInt64] data type on the column "UInt64"' { - $result.Columns | Where-Object -Property 'ColumnName' -eq 'UInt64' | Select-Object -ExpandProperty 'DataType' | Select-Object -ExpandProperty Name | Should Be 'UInt64' + $result.UInt64 | Should -BeOfType [System.UInt64] } It "Has the following number: 123456" { $result.UInt64 | Should Be 123456 } } - Context "Property: myobject" { - It 'Has a column called "myobject"' { - $result.Columns.ColumnName.Contains('myobject') | Should Be $true + Context "Property: myObject" { + It 'Has a column called "myObject"' { + $result.Columns.ColumnName | Should -Contain 'myObject' } - It 'Has a [string] data type on the column "myobject"' { - $result.Columns | Where-Object -Property 'ColumnName' -eq 'myobject' | Select-Object -ExpandProperty 'DataType' | Select-Object -ExpandProperty Name | Should Be 'String' + It 'Has a [string] data type on the column "myObject"' { + $result.myObject | Should -BeOfType [System.String] } - It "Has no value" { - # not sure if this is a feaure. Should probably be changed in the future - $result.myobject.GetType().FullName | Should Be "System.DBNull" + } + + Context "Property: dbadatetime" { + It 'Has a column called "dbadatetime"' { + $result.Columns.ColumnName | Should -Contain 'dbadatetime' + } + It 'Has a [dbadatetime] data type on the column "myObject"' { + $result.dbadatetime | Should -BeOfType [System.String] + } + It "Has the following dbadatetime: 2024-05-19 05:52:00.000" { + $date = Get-Date -Year 2024 -Month 5 -Day 19 -Hour 5 -Minute 52 -Second 0 -Millisecond 0 + [datetime]$result.dbadatetime -eq $date | Should Be $true } } + Context "Property: dbadatetimeArray" { + It 'Has a column called "dbadatetimeArray"' { + $result.Columns.ColumnName | Should -Contain 'dbadatetimeArray' + } + It 'Has a [dbadatetimeArray] data type on the column "myObject"' { + $result.dbadatetimeArray | Should -BeOfType [System.String] + } + It "Has the following dbadatetimeArray converted to strings: 2024-05-19 05:52:00.000, 2024-05-19 06:52:00.000" { + $string = '2024-05-19 05:52:00.000, 2024-05-19 06:52:00.000' + $result.dbadatetimeArray -eq $string | Should Be $true + } + } } Describe "Testing input parameters" { diff --git a/tests/Install-DbaInstance.Tests.ps1 b/tests/Install-DbaInstance.Tests.ps1 index 852616ab80..32a3d3a05e 100644 --- a/tests/Install-DbaInstance.Tests.ps1 +++ b/tests/Install-DbaInstance.Tests.ps1 @@ -128,7 +128,12 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Assert-MockCalled -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools Assert-MockCalled -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools Assert-MockCalled -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools - Assert-MockCalled -CommandName Set-DbaPrivilege -Exactly 1 -Scope It -ModuleName dbatools + if ($version -in '2008', '2008R2', '2012', '2014') { + Assert-MockCalled -CommandName Set-DbaPrivilege -Exactly 1 -Scope It -ModuleName dbatools + } else { + # SQLSVCINSTANTFILEINIT is used for version 2016 and later + Assert-MockCalled -CommandName Set-DbaPrivilege -Exactly 0 -Scope It -ModuleName dbatools + } Assert-MockCalled -CommandName Set-DbaTcpPort -Exactly 1 -Scope It -ModuleName dbatools $result | Should -Not -BeNullOrEmpty