Skip to content

Commit dfae1fd

Browse files
Merge branch 'development'
2 parents cd47830 + 5c29bc7 commit dfae1fd

File tree

91 files changed

+529
-417
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+529
-417
lines changed

bin/dbatools-index.json

5.75 KB
Binary file not shown.

bin/type-extensions.ps1

-45
This file was deleted.

dbatools.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RootModule = 'dbatools.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '2.1.18'
14+
ModuleVersion = '2.1.19'
1515

1616
# ID used to uniquely identify this module
1717
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'

dbatools.psm1

-3
Original file line numberDiff line numberDiff line change
@@ -1069,9 +1069,6 @@ if ($option.LoadTypes -or
10691069
Write-ImportTime -Text "Updating type data"
10701070
}
10711071

1072-
Import-Command -Path "$script:PSModuleRoot/bin/type-extensions.ps1"
1073-
Write-ImportTime -Text "Loading type extensions"
1074-
10751072
$loadedModuleNames = (Get-Module sqlserver, sqlps -ErrorAction Ignore).Name
10761073
if ($loadedModuleNames -contains 'sqlserver' -or $loadedModuleNames -contains 'sqlps') {
10771074
if (Get-DbatoolsConfigValue -FullName Import.SqlpsCheck) {

private/functions/flowcontrol/Stop-Function.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function Stop-Function {
252252
}
253253

254254
# Extra insurance that it'll stop
255-
Set-Variable -Name "__dbatools_interrupt_function_78Q9VPrM6999g6zo24Qn83m09XF56InEn4hFrA8Fwhu5xJrs6r" -Scope 1 -Value $true
255+
Set-Variable -Name "__dbatools_interrupt_function_78Q9VPrM6999g6zo24Qn83m09XF56InEn4hFrA8Fwhu5xJrs6r" -Scope 1 -Value $true -WhatIf:$false
256256

257257
throw $records[0]
258258
}
@@ -273,7 +273,7 @@ function Stop-Function {
273273
}
274274
} else {
275275
# Make sure the function knows it should be stopping
276-
Set-Variable -Name "__dbatools_interrupt_function_78Q9VPrM6999g6zo24Qn83m09XF56InEn4hFrA8Fwhu5xJrs6r" -Scope 1 -Value $true
276+
Set-Variable -Name "__dbatools_interrupt_function_78Q9VPrM6999g6zo24Qn83m09XF56InEn4hFrA8Fwhu5xJrs6r" -Scope 1 -Value $true -WhatIf:$false
277277

278278
return
279279
}

public/Add-DbaRegServer.ps1

-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ function Add-DbaRegServer {
5656
5757
.PARAMETER EnableException
5858
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
59-
6059
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
61-
6260
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
6361
6462
.NOTES

public/Add-DbaRegServerGroup.ps1

-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ function Add-DbaRegServerGroup {
3737
3838
.PARAMETER EnableException
3939
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
40-
4140
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
42-
4341
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
4442
4543
.NOTES

public/Connect-DbaInstance.ps1

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ function Connect-DbaInstance {
142142
143143
Note that the token is valid for only one hour and cannot be renewed automatically.
144144
145+
Note that the returned SMO is not a fully functional SMO. It can only be used in a limited list of commands like Invoke-DbaQuery, Import-DbaCsv or Write-DbaDbTableData.
146+
145147
.PARAMETER DedicatedAdminConnection
146148
Connects using "ADMIN:" to create a dedicated admin connection (DAC) as a non-pooled connection.
147149
If the instance is on a remote server, the remote access has to be enabled via "Set-DbaSpConfigure -Name RemoteDacConnectionsEnabled -Value $true" or "sp_configure 'remote admin connections', 1".

public/Copy-DbaDbQueryStoreOption.ps1

+9-14
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ function Copy-DbaDbQueryStoreOption {
104104

105105
$sourceDB = Get-DbaDatabase -SqlInstance $sourceServer -Database $SourceDatabase
106106

107-
if ($sourceServer.VersionMajor -eq 14) {
108-
$QueryStoreOptions = $sourceDB.Query("SELECT max_plans_per_query AS MaxPlansPerQuery, wait_stats_capture_mode_desc AS WaitStatsCaptureMode FROM sys.database_query_store_options;", $sourceDB.Name)
109-
} elseif ($sourceServer.VersionMajor -ge 15) {
110-
$QueryStoreOptions = $sourceDB.Query("SELECT max_plans_per_query AS MaxPlansPerQuery, wait_stats_capture_mode_desc AS WaitStatsCaptureMode, capture_policy_execution_count AS CustomCapturePolicyExecutionCount, capture_policy_stale_threshold_hours AS CustomCapturePolicyStaleThresholdHours, capture_policy_total_compile_cpu_time_ms AS CustomCapturePolicyTotalCompileCPUTimeMS, capture_policy_total_execution_cpu_time_ms AS CustomCapturePolicyTotalExecutionCPUTimeMS FROM sys.database_query_store_options;", $sourceDB.Name)
111-
}
112-
113107
foreach ($destinstance in $Destination) {
114108

115109
if (!$DestinationDatabase -and !$Exclude -and !$AllDatabases) {
@@ -152,6 +146,7 @@ function Copy-DbaDbQueryStoreOption {
152146
DestinationDatabaseID = $destDB.ID
153147
Type = "QueryStore Configuration"
154148
Status = $null
149+
Notes = $null
155150
DateTime = [Dataplat.Dbatools.Utility.DbaDateTime](Get-Date)
156151
}
157152

@@ -191,8 +186,8 @@ function Copy-DbaDbQueryStoreOption {
191186
CaptureMode = $SourceQSConfig.QueryCaptureMode
192187
CleanupMode = $SourceQSConfig.SizeBasedCleanupMode
193188
StaleQueryThreshold = $SourceQSConfig.StaleQueryThresholdInDays
194-
MaxPlansPerQuery = $QueryStoreOptions.MaxPlansPerQuery
195-
WaitStatsCaptureMode = $QueryStoreOptions.WaitStatsCaptureMode
189+
MaxPlansPerQuery = $SourceQSConfig.MaxPlansPerQuery
190+
WaitStatsCaptureMode = $SourceQSConfig.WaitStatsCaptureMode
196191
}
197192
} elseif ($sourceServer.VersionMajor -ge 15) {
198193
$setDbaDbQueryStoreOptionParameters = @{
@@ -206,12 +201,12 @@ function Copy-DbaDbQueryStoreOption {
206201
CaptureMode = $SourceQSConfig.QueryCaptureMode
207202
CleanupMode = $SourceQSConfig.SizeBasedCleanupMode
208203
StaleQueryThreshold = $SourceQSConfig.StaleQueryThresholdInDays
209-
MaxPlansPerQuery = $QueryStoreOptions.MaxPlansPerQuery
210-
WaitStatsCaptureMode = $QueryStoreOptions.WaitStatsCaptureMode
211-
CustomCapturePolicyExecutionCount = $QueryStoreOptions.CustomCapturePolicyExecutionCount
212-
CustomCapturePolicyTotalCompileCPUTimeMS = $QueryStoreOptions.CustomCapturePolicyTotalCompileCPUTimeMS
213-
CustomCapturePolicyTotalExecutionCPUTimeMS = $QueryStoreOptions.CustomCapturePolicyTotalExecutionCPUTimeMS
214-
CustomCapturePolicyStaleThresholdHours = $QueryStoreOptions.CustomCapturePolicyStaleThresholdHours
204+
MaxPlansPerQuery = $SourceQSConfig.MaxPlansPerQuery
205+
WaitStatsCaptureMode = $SourceQSConfig.WaitStatsCaptureMode
206+
CustomCapturePolicyExecutionCount = $SourceQSConfig.CustomCapturePolicyExecutionCount
207+
CustomCapturePolicyTotalCompileCPUTimeMS = $SourceQSConfig.CustomCapturePolicyTotalCompileCPUTimeMS
208+
CustomCapturePolicyTotalExecutionCPUTimeMS = $SourceQSConfig.CustomCapturePolicyTotalExecutionCPUTimeMS
209+
CustomCapturePolicyStaleThresholdHours = $SourceQSConfig.CustomCapturePolicyStaleThresholdHours
215210
}
216211
}
217212

public/Disable-DbaDbEncryption.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Disable-DbaDbEncryption {
3434
.PARAMETER EnableException
3535
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
3636
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
37-
Using this switch turns this "nice by default" feature off and disables you to catch exceptions with your own try/catch.
37+
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
3838
3939
.PARAMETER WhatIf
4040
Shows what would happen if the command were to run. No actions are actually performed.

public/Export-DbaRegServer.ps1

-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ function Export-DbaRegServer {
4141
4242
.PARAMETER EnableException
4343
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
44-
4544
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
46-
4745
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
4846
4947
.NOTES

public/Export-DbaUser.ps1

+60-7
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,6 @@ function Export-DbaUser {
250250
$FilePath = Get-ExportFilePath -Path $PSBoundParameters.Path -FilePath $PSBoundParameters.FilePath -Type sql -ServerName $db.Parent.Name -Unique
251251
}
252252

253-
# Store roles between users so if we hit the same one we don't create it again
254-
$roles = @()
255253
$stepCounter = 0
256254
foreach ($dbuser in $users) {
257255

@@ -274,14 +272,69 @@ function Export-DbaUser {
274272
}
275273

276274
try {
275+
<#
276+
In this approach, we do not maintain a variable to track the roles that have been scripted. Our method involves a
277+
consistent verification process for each user against the complete list of roles. This ensures that we dynamically
278+
include only the roles to which a user belongs. For example, consider two users: user1 is associated with role1 and
279+
role2, while user2 is associated with role1 and role3.
280+
281+
Attempting to memorize the scripted roles could result in Transact-SQL (T-SQL) statements such as:
282+
283+
IF NOT EXISTS (role1)
284+
CREATE ROLE role1
285+
IF NOT EXISTS (role2)
286+
CREATE ROLE role2
287+
IF NOT EXISTS (user1)
288+
CREATE USER user1
289+
ADD user1 TO role1
290+
ADD user1 TO role2
291+
292+
-- And for another user:
293+
294+
IF NOT EXISTS (role3)
295+
CREATE ROLE role3
296+
IF NOT EXISTS (user2)
297+
CREATE USER user2
298+
ADD user2 TO role1
299+
ADD user2 TO role3
300+
301+
However, this script inadvertently introduces a dependency issue. To ensure user2 is properly configured, the script
302+
segment for user1 must be executed first due to the shared role1. To circumvent this issue and remove interdependencies,
303+
we opt to match each user against all potential roles. Consequently, roles are scripted per user membership, resulting
304+
in T-SQL like:
305+
306+
IF NOT EXISTS (role1)
307+
CREATE ROLE role1
308+
IF NOT EXISTS (role2)
309+
CREATE ROLE role2
310+
IF NOT EXISTS (user1)
311+
CREATE USER user1
312+
ADD user1 TO role1
313+
ADD user1 TO role2
314+
315+
-- And for another user:
316+
317+
IF NOT EXISTS (role1)
318+
CREATE ROLE role1
319+
IF NOT EXISTS (role3)
320+
CREATE ROLE role3
321+
IF NOT EXISTS (user2)
322+
CREATE USER user2
323+
ADD user2 TO role1
324+
ADD user2 TO role3
325+
326+
While this method may produce some redundant code (e.g., checking and creating role1 twice), it guarantees that each
327+
portion of the script is self-sufficient and can be executed independently of others. Therefore, users can selectively
328+
execute any segment of the script without concern for execution order or dependencies.
329+
#>
277330
#Fixed Roles #Dependency Issue. Create Role, before add to role.
278-
foreach ($rolePermission in ($db.Roles | Where-Object { $_.IsFixedRole -eq $false })) {
279-
foreach ($rolePermissionScript in $rolePermission.Script($ScriptingOptionsObject)) {
280-
if ($rolePermission.ToString() -notin $roles) {
281-
$roles += , $rolePermission.ToString()
331+
foreach ($role in ($db.Roles | Where-Object { $_.IsFixedRole -eq $false })) {
332+
# Check if the user is a member of the role
333+
$isUserMember = $role.EnumMembers() | Where-Object { $_ -eq $dbuser.Name }
334+
if ($isUserMember) {
335+
foreach ($rolePermissionScript in $role.Script($ScriptingOptionsObject)) {
282336
$outsql += "$($rolePermissionScript.ToString())"
283337
}
284-
285338
}
286339
}
287340

public/Export-DbatoolsConfig.ps1

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ function Export-DbatoolsConfig {
4040
(Note: Settings that were updated with the same value as the original default will still be considered changed)
4141
4242
.PARAMETER EnableException
43-
This parameters disables user-friendly warnings and enables the throwing of exceptions.
44-
This is less user friendly, but allows catching exceptions in calling scripts.
43+
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
44+
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
45+
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
4546
4647
.NOTES
4748
Tags: Module

public/Get-DbaBackupInformation.ps1

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ function Get-DbaBackupInformation {
7878
When specified along with a path the command will import a previously exported BackupHistory object from an xml file.
7979
8080
.PARAMETER EnableException
81-
Replaces user friendly yellow warnings with bloody red exceptions of doom!
82-
Use this if you want the function to throw terminating errors you want to catch.
81+
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
82+
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
83+
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
8384
8485
.NOTES
8586
Tags: DisasterRecovery, Backup, Restore

public/Get-DbaDbAssembly.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function Get-DbaDbAssembly {
2424
Specify an Assembly to be fetched. If not specified all Assemblies will be returned
2525
2626
.PARAMETER EnableException
27-
By default, when something goes wrong, we try to catch it, interpret it and give you a friendly warning message.
27+
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
2828
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
2929
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
3030

public/Get-DbaDbDetachedFileInfo.ps1

+4
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ function Get-DbaDbDetachedFileInfo {
8686
Stop-Function -Message "$servername cannot read the file $filepath. Is the database detached?" -Continue
8787
}
8888

89+
# Source: https://sqlserverbuilds.blogspot.com/2014/01/sql-server-internal-database-versions.html
8990
switch ($exactdbversion) {
91+
957 { $dbversion = "SQL Server 2022" }
92+
904 { $dbversion = "SQL Server 2019" }
9093
869 { $dbversion = "SQL Server 2017" }
94+
868 { $dbversion = "SQL Server 2017" }
9195
852 { $dbversion = "SQL Server 2016" }
9296
782 { $dbversion = "SQL Server 2014" }
9397
706 { $dbversion = "SQL Server 2012" }

public/Get-DbaDbObjectTrigger.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function Get-DbaDbObjectTrigger {
3131
.PARAMETER EnableException
3232
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
3333
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
34-
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/ca
34+
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
3535
3636
.NOTES
3737
Tags: Database, Trigger

0 commit comments

Comments
 (0)