Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed Jul 1, 2024
2 parents cd47830 + 5c29bc7 commit dfae1fd
Show file tree
Hide file tree
Showing 91 changed files with 529 additions and 417 deletions.
Binary file modified bin/dbatools-index.json
Binary file not shown.
45 changes: 0 additions & 45 deletions bin/type-extensions.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion dbatools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RootModule = 'dbatools.psm1'

# Version number of this module.
ModuleVersion = '2.1.18'
ModuleVersion = '2.1.19'

# ID used to uniquely identify this module
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'
Expand Down
3 changes: 0 additions & 3 deletions dbatools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1069,9 +1069,6 @@ if ($option.LoadTypes -or
Write-ImportTime -Text "Updating type data"
}

Import-Command -Path "$script:PSModuleRoot/bin/type-extensions.ps1"
Write-ImportTime -Text "Loading type extensions"

$loadedModuleNames = (Get-Module sqlserver, sqlps -ErrorAction Ignore).Name
if ($loadedModuleNames -contains 'sqlserver' -or $loadedModuleNames -contains 'sqlps') {
if (Get-DbatoolsConfigValue -FullName Import.SqlpsCheck) {
Expand Down
4 changes: 2 additions & 2 deletions private/functions/flowcontrol/Stop-Function.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function Stop-Function {
}

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

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

return
}
Expand Down
2 changes: 0 additions & 2 deletions public/Add-DbaRegServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ function Add-DbaRegServer {
.PARAMETER EnableException
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
.NOTES
Expand Down
2 changes: 0 additions & 2 deletions public/Add-DbaRegServerGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ function Add-DbaRegServerGroup {
.PARAMETER EnableException
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
.NOTES
Expand Down
2 changes: 2 additions & 0 deletions public/Connect-DbaInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ function Connect-DbaInstance {
Note that the token is valid for only one hour and cannot be renewed automatically.
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.
.PARAMETER DedicatedAdminConnection
Connects using "ADMIN:" to create a dedicated admin connection (DAC) as a non-pooled connection.
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".
Expand Down
23 changes: 9 additions & 14 deletions public/Copy-DbaDbQueryStoreOption.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ function Copy-DbaDbQueryStoreOption {

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

if ($sourceServer.VersionMajor -eq 14) {
$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)
} elseif ($sourceServer.VersionMajor -ge 15) {
$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)
}

foreach ($destinstance in $Destination) {

if (!$DestinationDatabase -and !$Exclude -and !$AllDatabases) {
Expand Down Expand Up @@ -152,6 +146,7 @@ function Copy-DbaDbQueryStoreOption {
DestinationDatabaseID = $destDB.ID
Type = "QueryStore Configuration"
Status = $null
Notes = $null
DateTime = [Dataplat.Dbatools.Utility.DbaDateTime](Get-Date)
}

Expand Down Expand Up @@ -191,8 +186,8 @@ function Copy-DbaDbQueryStoreOption {
CaptureMode = $SourceQSConfig.QueryCaptureMode
CleanupMode = $SourceQSConfig.SizeBasedCleanupMode
StaleQueryThreshold = $SourceQSConfig.StaleQueryThresholdInDays
MaxPlansPerQuery = $QueryStoreOptions.MaxPlansPerQuery
WaitStatsCaptureMode = $QueryStoreOptions.WaitStatsCaptureMode
MaxPlansPerQuery = $SourceQSConfig.MaxPlansPerQuery
WaitStatsCaptureMode = $SourceQSConfig.WaitStatsCaptureMode
}
} elseif ($sourceServer.VersionMajor -ge 15) {
$setDbaDbQueryStoreOptionParameters = @{
Expand All @@ -206,12 +201,12 @@ function Copy-DbaDbQueryStoreOption {
CaptureMode = $SourceQSConfig.QueryCaptureMode
CleanupMode = $SourceQSConfig.SizeBasedCleanupMode
StaleQueryThreshold = $SourceQSConfig.StaleQueryThresholdInDays
MaxPlansPerQuery = $QueryStoreOptions.MaxPlansPerQuery
WaitStatsCaptureMode = $QueryStoreOptions.WaitStatsCaptureMode
CustomCapturePolicyExecutionCount = $QueryStoreOptions.CustomCapturePolicyExecutionCount
CustomCapturePolicyTotalCompileCPUTimeMS = $QueryStoreOptions.CustomCapturePolicyTotalCompileCPUTimeMS
CustomCapturePolicyTotalExecutionCPUTimeMS = $QueryStoreOptions.CustomCapturePolicyTotalExecutionCPUTimeMS
CustomCapturePolicyStaleThresholdHours = $QueryStoreOptions.CustomCapturePolicyStaleThresholdHours
MaxPlansPerQuery = $SourceQSConfig.MaxPlansPerQuery
WaitStatsCaptureMode = $SourceQSConfig.WaitStatsCaptureMode
CustomCapturePolicyExecutionCount = $SourceQSConfig.CustomCapturePolicyExecutionCount
CustomCapturePolicyTotalCompileCPUTimeMS = $SourceQSConfig.CustomCapturePolicyTotalCompileCPUTimeMS
CustomCapturePolicyTotalExecutionCPUTimeMS = $SourceQSConfig.CustomCapturePolicyTotalExecutionCPUTimeMS
CustomCapturePolicyStaleThresholdHours = $SourceQSConfig.CustomCapturePolicyStaleThresholdHours
}
}

Expand Down
2 changes: 1 addition & 1 deletion public/Disable-DbaDbEncryption.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Disable-DbaDbEncryption {
.PARAMETER EnableException
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and disables you to catch exceptions with your own try/catch.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
.PARAMETER WhatIf
Shows what would happen if the command were to run. No actions are actually performed.
Expand Down
2 changes: 0 additions & 2 deletions public/Export-DbaRegServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ function Export-DbaRegServer {
.PARAMETER EnableException
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
.NOTES
Expand Down
67 changes: 60 additions & 7 deletions public/Export-DbaUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ function Export-DbaUser {
$FilePath = Get-ExportFilePath -Path $PSBoundParameters.Path -FilePath $PSBoundParameters.FilePath -Type sql -ServerName $db.Parent.Name -Unique
}

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

Expand All @@ -274,14 +272,69 @@ function Export-DbaUser {
}

try {
<#
In this approach, we do not maintain a variable to track the roles that have been scripted. Our method involves a
consistent verification process for each user against the complete list of roles. This ensures that we dynamically
include only the roles to which a user belongs. For example, consider two users: user1 is associated with role1 and
role2, while user2 is associated with role1 and role3.
Attempting to memorize the scripted roles could result in Transact-SQL (T-SQL) statements such as:
IF NOT EXISTS (role1)
CREATE ROLE role1
IF NOT EXISTS (role2)
CREATE ROLE role2
IF NOT EXISTS (user1)
CREATE USER user1
ADD user1 TO role1
ADD user1 TO role2
-- And for another user:
IF NOT EXISTS (role3)
CREATE ROLE role3
IF NOT EXISTS (user2)
CREATE USER user2
ADD user2 TO role1
ADD user2 TO role3
However, this script inadvertently introduces a dependency issue. To ensure user2 is properly configured, the script
segment for user1 must be executed first due to the shared role1. To circumvent this issue and remove interdependencies,
we opt to match each user against all potential roles. Consequently, roles are scripted per user membership, resulting
in T-SQL like:
IF NOT EXISTS (role1)
CREATE ROLE role1
IF NOT EXISTS (role2)
CREATE ROLE role2
IF NOT EXISTS (user1)
CREATE USER user1
ADD user1 TO role1
ADD user1 TO role2
-- And for another user:
IF NOT EXISTS (role1)
CREATE ROLE role1
IF NOT EXISTS (role3)
CREATE ROLE role3
IF NOT EXISTS (user2)
CREATE USER user2
ADD user2 TO role1
ADD user2 TO role3
While this method may produce some redundant code (e.g., checking and creating role1 twice), it guarantees that each
portion of the script is self-sufficient and can be executed independently of others. Therefore, users can selectively
execute any segment of the script without concern for execution order or dependencies.
#>
#Fixed Roles #Dependency Issue. Create Role, before add to role.
foreach ($rolePermission in ($db.Roles | Where-Object { $_.IsFixedRole -eq $false })) {
foreach ($rolePermissionScript in $rolePermission.Script($ScriptingOptionsObject)) {
if ($rolePermission.ToString() -notin $roles) {
$roles += , $rolePermission.ToString()
foreach ($role in ($db.Roles | Where-Object { $_.IsFixedRole -eq $false })) {
# Check if the user is a member of the role
$isUserMember = $role.EnumMembers() | Where-Object { $_ -eq $dbuser.Name }
if ($isUserMember) {
foreach ($rolePermissionScript in $role.Script($ScriptingOptionsObject)) {
$outsql += "$($rolePermissionScript.ToString())"
}

}
}

Expand Down
5 changes: 3 additions & 2 deletions public/Export-DbatoolsConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ function Export-DbatoolsConfig {
(Note: Settings that were updated with the same value as the original default will still be considered changed)
.PARAMETER EnableException
This parameters disables user-friendly warnings and enables the throwing of exceptions.
This is less user friendly, but allows catching exceptions in calling scripts.
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
.NOTES
Tags: Module
Expand Down
5 changes: 3 additions & 2 deletions public/Get-DbaBackupInformation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ function Get-DbaBackupInformation {
When specified along with a path the command will import a previously exported BackupHistory object from an xml file.
.PARAMETER EnableException
Replaces user friendly yellow warnings with bloody red exceptions of doom!
Use this if you want the function to throw terminating errors you want to catch.
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
.NOTES
Tags: DisasterRecovery, Backup, Restore
Expand Down
2 changes: 1 addition & 1 deletion public/Get-DbaDbAssembly.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Get-DbaDbAssembly {
Specify an Assembly to be fetched. If not specified all Assemblies will be returned
.PARAMETER EnableException
By default, when something goes wrong, we try to catch it, interpret it and give you a friendly warning message.
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
Expand Down
4 changes: 4 additions & 0 deletions public/Get-DbaDbDetachedFileInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ function Get-DbaDbDetachedFileInfo {
Stop-Function -Message "$servername cannot read the file $filepath. Is the database detached?" -Continue
}

# Source: https://sqlserverbuilds.blogspot.com/2014/01/sql-server-internal-database-versions.html
switch ($exactdbversion) {
957 { $dbversion = "SQL Server 2022" }
904 { $dbversion = "SQL Server 2019" }
869 { $dbversion = "SQL Server 2017" }
868 { $dbversion = "SQL Server 2017" }
852 { $dbversion = "SQL Server 2016" }
782 { $dbversion = "SQL Server 2014" }
706 { $dbversion = "SQL Server 2012" }
Expand Down
2 changes: 1 addition & 1 deletion public/Get-DbaDbObjectTrigger.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Get-DbaDbObjectTrigger {
.PARAMETER EnableException
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/ca
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
.NOTES
Tags: Database, Trigger
Expand Down
Loading

0 comments on commit dfae1fd

Please sign in to comment.