Skip to content

Commit

Permalink
Merge branch 'development' into shawn/syncpwd
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Jun 19, 2023
2 parents aaeb71b + e996def commit 3db7742
Show file tree
Hide file tree
Showing 23 changed files with 292 additions and 208 deletions.
12 changes: 11 additions & 1 deletion bin/dbatools-buildref-index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"LastUpdated": "2023-06-07T00:00:00",
"LastUpdated": "2023-06-15T00:00:00",
"Data": [
{
"Version": "8.0.47",
Expand Down Expand Up @@ -4505,6 +4505,11 @@
"Version": "15.0.4312",
"KBList": "5024276"
},
{
"CU": "CU21",
"Version": "15.0.4316",
"KBList": "5025808"
},
{
"Version": "16.0.100",
"Name": "2022"
Expand Down Expand Up @@ -4545,6 +4550,11 @@
"CU": "CU4",
"Version": "16.0.4035",
"KBList": "5026717"
},
{
"CU": "CU5",
"Version": "16.0.4045",
"KBList": "5026806"
}
]
}
2 changes: 1 addition & 1 deletion private/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ $script:path_typedata = [IO.Path]::Combine($script:AppData, $psVersionName, "dba
#endregion Paths

# Determine Registry Availability
$script:NoRegistry = $true
$script:NoRegistry = $false
if (($PSVersionTable.PSVersion.Major -ge 6) -and ($PSVersionTable.OS -notlike "*Windows*")) {
$script:NoRegistry = $true
}
Expand Down
2 changes: 1 addition & 1 deletion public/Backup-DbaDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ function Backup-DbaDatabase {
Write-Message -Message "Exception thrown by db going into restoring mode due to recovery" -Leve Verbose
} else {
Write-Progress -Id $ProgressId -Activity "Backup" -Status "Failed" -Completed
Stop-Function -message "Backup Failed" -ErrorRecord $_ -Continue
Stop-Function -message "Backup of [$dbName] failed" -ErrorRecord $_ -Target $dbName -Continue
$BackupComplete = $false
}
}
Expand Down
38 changes: 31 additions & 7 deletions public/Connect-DbaInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,39 @@ function Connect-DbaInstance {
} elseif ($inputObjectType -eq 'SqlConnection') {
$server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $inputObject
} elseif ($inputObjectType -in 'RegisteredServer', 'ConnectionString') {
$server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $serverName
# Parameter TrustServerCertificate changes the connection string be allow connections to instances with the default self-signed certificate
# Create the server SMO in the same way as when passing a string (see #8962 for details).
# Best way to get connection pooling to work is to use SqlConnectionInfo -> ServerConnection -> Server
$sqlConnectionInfo = New-Object -TypeName Microsoft.SqlServer.Management.Common.SqlConnectionInfo

# Set properties of SqlConnectionInfo based on the used properties of the connection string.
$csb = New-Object -TypeName Microsoft.Data.SqlClient.SqlConnectionStringBuilder -ArgumentList $connectionString
if ($csb.ShouldSerialize('Data Source')) {
Write-Message -Level Debug -Message "ServerName will be set to '$($csb.DataSource)'"
$sqlConnectionInfo.ServerName = $csb.DataSource
$null = $csb.Remove('Data Source')
}
if ($csb.ShouldSerialize('User ID')) {
Write-Message -Level Debug -Message "UserName will be set to '$($csb.UserID)'"
$sqlConnectionInfo.UserName = $csb.UserID
$null = $csb.Remove('User ID')
}
if ($csb.ShouldSerialize('Password')) {
Write-Message -Level Debug -Message "Password will be set"
$sqlConnectionInfo.Password = $csb.Password
$null = $csb.Remove('Password')
}

# Add all remaining parts of the connection string as additional parameters.
$sqlConnectionInfo.AdditionalParameters = $csb.ConnectionString

# Set properties based on used parameters.
if ($TrustServerCertificate) {
Write-Message -Level Verbose -Message "TrustServerCertificate will be set to 'True'"
$csb = New-Object -TypeName Microsoft.Data.SqlClient.SqlConnectionStringBuilder -ArgumentList $connectionString
$csb.TrustServerCertificate = $true
$connectionString = $csb.ConnectionString
Write-Message -Level Debug -Message "TrustServerCertificate will be set to '$TrustServerCertificate'"
$sqlConnectionInfo.TrustServerCertificate = $TrustServerCertificate
}
$server.ConnectionContext.ConnectionString = $connectionString

$serverConnection = New-Object -TypeName Microsoft.SqlServer.Management.Common.ServerConnection -ArgumentList $sqlConnectionInfo
$server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $serverConnection
} elseif ($inputObjectType -eq 'String') {
# Identify authentication method
if (Test-Azure -SqlInstance $instance) {
Expand Down
4 changes: 3 additions & 1 deletion public/Export-DbaUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function Export-DbaUser {
[string[]]$Database,
[string[]]$ExcludeDatabase,
[string[]]$User,
[ValidateSet('SQLServer2000', 'SQLServer2005', 'SQLServer2008/2008R2', 'SQLServer2012', 'SQLServer2014', 'SQLServer2016', 'SQLServer2017', 'SQLServer2019')]
[ValidateSet('SQLServer2000', 'SQLServer2005', 'SQLServer2008/2008R2', 'SQLServer2012', 'SQLServer2014', 'SQLServer2016', 'SQLServer2017', 'SQLServer2019', 'SQLServer2022')]
[string]$DestinationVersion,
[string]$Path = (Get-DbatoolsConfigValue -FullName 'Path.DbatoolsExport'),
[Alias("OutFile", "FileName")]
Expand Down Expand Up @@ -185,6 +185,7 @@ function Export-DbaUser {
'SQLServer2016' = 'Version130'
'SQLServer2017' = 'Version140'
'SQLServer2019' = 'Version150'
'SQLServer2022' = 'Version160'
}

$versionName = @{
Expand All @@ -196,6 +197,7 @@ function Export-DbaUser {
'Version130' = 'SQLServer2016'
'Version140' = 'SQLServer2017'
'Version150' = 'SQLServer2019'
'Version160' = 'SQLServer2022'
}

$eol = [System.Environment]::NewLine
Expand Down
2 changes: 1 addition & 1 deletion public/Get-DbaAvailableCollation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Get-DbaAvailableCollation {
Only the connect permission is required to get this information.
.PARAMETER SqlInstance
TThe target SQL Server instance or instances. Only connect permission is required.
The target SQL Server instance or instances. Only connect permission is required.
.PARAMETER SqlCredential
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Expand Down
2 changes: 1 addition & 1 deletion public/Get-DbaDbMail.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Get-DbaDbMail {
Gets the database mail from SQL Server
.PARAMETER SqlInstance
TThe target SQL Server instance or instances.
The target SQL Server instance or instances.
.PARAMETER SqlCredential
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Expand Down
2 changes: 1 addition & 1 deletion public/Get-DbaDbMailConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Get-DbaDbMailConfig {
Gets database mail configs from SQL Server
.PARAMETER SqlInstance
TThe target SQL Server instance or instances.
The target SQL Server instance or instances.
.PARAMETER SqlCredential
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Expand Down
2 changes: 1 addition & 1 deletion public/Get-DbaDbMailHistory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Get-DbaDbMailHistory {
Gets the history of mail sent from a SQL instance
.PARAMETER SqlInstance
TThe target SQL Server instance or instances.
The target SQL Server instance or instances.
.PARAMETER SqlCredential
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Expand Down
2 changes: 1 addition & 1 deletion public/Get-DbaDbMailLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Get-DbaDbMailLog {
Gets the DBMail log from a SQL instance
.PARAMETER SqlInstance
TThe target SQL Server instance or instances.
The target SQL Server instance or instances.
.PARAMETER SqlCredential
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Expand Down
2 changes: 1 addition & 1 deletion public/Get-DbaDbMailServer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Get-DbaDbMailServer {
Gets database mail servers from SQL Server
.PARAMETER SqlInstance
TThe target SQL Server instance or instances.
The target SQL Server instance or instances.
.PARAMETER SqlCredential
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Expand Down
11 changes: 3 additions & 8 deletions public/Get-DbaDbRole.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,26 @@ function Get-DbaDbRole {
#>
[CmdletBinding()]
param (
[parameter(ValueFromPipeline)]
[Parameter(ValueFromPipeline)]
[DbaInstance[]]$SqlInstance,
[PSCredential]$SqlCredential,
[string[]]$Database,
[string[]]$ExcludeDatabase,
[string[]]$Role,
[string[]]$ExcludeRole,
[switch]$ExcludeFixedRole,
[parameter(ValueFromPipeline)]
[Parameter(ValueFromPipeline)]
[Microsoft.SqlServer.Management.Smo.Database[]]$InputObject,
[switch]$EnableException
)

process {
if (-not $InputObject -and -not $SqlInstance) {
Stop-Function -Message "You must pipe in a database or specify a SqlInstance"
return
}

if ($SqlInstance) {
$InputObject += Get-DbaDatabase -SqlInstance $SqlInstance -SqlCredential $SqlCredential -Database $Database -ExcludeDatabase $ExcludeDatabase
$InputObject += Get-DbaDatabase -SqlInstance $SqlInstance -SqlCredential $SqlCredential -Database $Database -ExcludeDatabase $ExcludeDatabase -EnableException:$EnableException
}

foreach ($db in $InputObject) {
Expand All @@ -115,15 +114,12 @@ function Get-DbaDbRole {
Write-Message -Level 'Verbose' -Message "Getting Database Roles for $db on $server"

$dbRoles = $db.Roles

if ($Role) {
$dbRoles = $dbRoles | Where-Object { $_.Name -in $Role }
}

if ($ExcludeRole) {
$dbRoles = $dbRoles | Where-Object { $_.Name -notin $ExcludeRole }
}

if ($ExcludeFixedRole) {
$dbRoles = $dbRoles | Where-Object { $_.IsFixedRole -eq $false -and $_.Name -ne 'public' }
}
Expand All @@ -133,7 +129,6 @@ function Get-DbaDbRole {
Add-Member -Force -InputObject $dbRole -MemberType NoteProperty -Name InstanceName -Value $server.ServiceName
Add-Member -Force -InputObject $dbRole -MemberType NoteProperty -Name SqlInstance -Value $server.DomainInstanceName
Add-Member -Force -InputObject $dbRole -MemberType NoteProperty -Name Database -Value $db.Name

Select-DefaultView -InputObject $dbRole -Property "ComputerName", "InstanceName", "Database", "Name", "IsFixedRole"
}
}
Expand Down
23 changes: 18 additions & 5 deletions public/Get-DbaDbRoleMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function Get-DbaDbRoleMember {
#>
[CmdletBinding()]
param (
[parameter(ValueFromPipeline)]
[Parameter(ValueFromPipeline)]
[DbaInstance[]]$SqlInstance,
[PSCredential]$SqlCredential,
[string[]]$Database,
Expand All @@ -101,7 +101,7 @@ function Get-DbaDbRoleMember {
[string[]]$ExcludeRole,
[switch]$ExcludeFixedRole,
[switch]$IncludeSystemUser,
[parameter(ValueFromPipeline)]
[Parameter(ValueFromPipeline)]
[object[]]$InputObject,
[switch]$EnableException
)
Expand All @@ -118,18 +118,31 @@ function Get-DbaDbRoleMember {

foreach ($input in $InputObject) {
$inputType = $input.GetType().FullName
$dbRoleParams = @{
SqlInstance = $input
SqlCredential = $SqlCredential
Database = $Database
ExcludeDatabase = $ExcludeDatabase
Role = $Role
ExcludeRole = $ExcludeRole
ExcludeFixedRole = $ExcludeFixedRole
EnableException = $EnableException
}
switch ($inputType) {
'Dataplat.Dbatools.Parameter.DbaInstanceParameter' {
Write-Message -Level Verbose -Message "Processing DbaInstanceParameter through InputObject"
$dbRoles = Get-DbaDBRole -SqlInstance $input -SqlCredential $SqlCredential -Database $Database -ExcludeDatabase $ExcludeDatabase -Role $Role -ExcludeRole $ExcludeRole -ExcludeFixedRole:$ExcludeFixedRole
$dbRoles = Get-DbaDbRole @dbRoleParams
}
'Microsoft.SqlServer.Management.Smo.Server' {
Write-Message -Level Verbose -Message "Processing Server through InputObject"
$dbRoles = Get-DbaDBRole -SqlInstance $input -SqlCredential $SqlCredential -Database $Database -ExcludeDatabase $ExcludeDatabase -Role $Role -ExcludeRole $ExcludeRole -ExcludeFixedRole:$ExcludeFixedRole
$dbRoles = Get-DbaDbRole @dbRoleParams
}
'Microsoft.SqlServer.Management.Smo.Database' {
$dbRoleParams.Remove('SqlInstance')
$dbRoleParams.Remove('SqlCredential')
$dbRoleParams.Remove('Database')
Write-Message -Level Verbose -Message "Processing Database through InputObject"
$dbRoles = $input | Get-DbaDBRole -Role $Role -ExcludeRole $ExcludeRole -ExcludeFixedRole:$ExcludeFixedRole
$dbRoles = $input | Get-DbaDbRole @dbRoleParams
}
'Microsoft.SqlServer.Management.Smo.DatabaseRole' {
Write-Message -Level Verbose -Message "Processing DatabaseRole through InputObject"
Expand Down
2 changes: 1 addition & 1 deletion public/Get-DbaDefaultPath.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Get-DbaDefaultPath {
Gets the default SQL Server paths for data, logs and backups
.PARAMETER SqlInstance
TThe target SQL Server instance or instances.
The target SQL Server instance or instances.
.PARAMETER SqlCredential
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Expand Down
2 changes: 1 addition & 1 deletion public/Get-DbaErrorLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Get-DbaErrorLog {
Gets the "SQL Error Log" of an instance. Returns all 10 error logs by default.
.PARAMETER SqlInstance
TThe target SQL Server instance or instances.
The target SQL Server instance or instances.
.PARAMETER SqlCredential
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Expand Down
4 changes: 4 additions & 0 deletions public/Get-DbaMaintenanceSolutionLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ function Get-DbaMaintenanceSolutionLog {
.DESCRIPTION
Ola wrote a .sql script to get the content from the commandLog table. However, if LogToTable='N', there will be no logging in that table. This function reads the text files that are written in the SQL Instance's Log directory.
Be aware that this command only works if sqlcmd is used to execute the procedures, which is a legacy way to start them and not used by new installations.
We would instead recommend installing using Install-DbaMaintenanceSolution and calling the procedures with the LogToTable='Y' parameter.
.PARAMETER SqlInstance
The target SQL Server instance or instances.
Expand Down
16 changes: 9 additions & 7 deletions public/Get-DbaStartupParameter.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ function Get-DbaStartupParameter {
$masterLog = $params | Where-Object { $_.StartsWith('-l') }
$errorLog = $params | Where-Object { $_.StartsWith('-e') }
$traceFlags = $params | Where-Object { $_.StartsWith('-T') }

$debugflag = $params | Where-Object { $_.StartsWith('-t') }

if ($debugflag.length -ne 0) {
Write-Message -Level Warning "$instance is using the lowercase -t trace flag. This is for internal debugging only. Please ensure this was intentional."
}
#>
$debugFlags = $params | Where-Object { $_.StartsWith('-t') }

if ($traceFlags.length -eq 0) {
$traceFlags = "None"
} else {
[int[]]$traceFlags = $traceFlags.substring(2)
}

if ($debugFlags.length -eq 0) {
$debugFlags = "None"
} else {
[int[]]$debugFlags = $debugFlags.substring(2)
}

if ($Simple -eq $true) {
[PSCustomObject]@{
ComputerName = $computerName
Expand All @@ -106,6 +106,7 @@ function Get-DbaStartupParameter {
MasterLog = $masterLog.TrimStart('-l')
ErrorLog = $errorLog.TrimStart('-e')
TraceFlags = $traceFlags
DebugFlags = $debugFlags
ParameterString = $wmisvc.StartupParameters
}
} else {
Expand Down Expand Up @@ -159,6 +160,7 @@ function Get-DbaStartupParameter {
MasterLog = $masterLog -replace '^-[lL]', ''
ErrorLog = $errorLog -replace '^-[eE]', ''
TraceFlags = $traceFlags
DebugFlags = $debugFlags
CommandPromptStart = $commandPrompt
MinimalStart = $minimalStart
MemoryToReserve = $memoryToReserve
Expand Down
6 changes: 3 additions & 3 deletions public/Install-DbaMaintenanceSolution.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ function Install-DbaMaintenanceSolution {
https://dbatools.io/Install-DbaMaintenanceSolution
.EXAMPLE
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -CleanupTime 72
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -InstallJobs -CleanupTime 72
Installs Ola Hallengren's Solution objects on RES14224 in the DBA database.
Backups will default to the default Backup Directory.
If the Maintenance Solution already exists, the script will be halted.
.EXAMPLE
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -BackupLocation "Z:\SQLBackup" -CleanupTime 72
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -InstallJobs -BackupLocation "Z:\SQLBackup" -CleanupTime 72
This will create the Ola Hallengren's Solution objects. Existing objects are not affected in any way.
Expand All @@ -120,7 +120,7 @@ function Install-DbaMaintenanceSolution {
Installs Maintenance Solution to myserver in database. Adds Agent Jobs, and if any currently exist, they'll be replaced.
.EXAMPLE
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -BackupLocation "Z:\SQLBackup" -CleanupTime 72 -ReplaceExisting
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -InstallJobs -BackupLocation "Z:\SQLBackup" -CleanupTime 72 -ReplaceExisting
This will drop and then recreate the Ola Hallengren's Solution objects
The cleanup script will drop and recreate:
Expand Down
Loading

0 comments on commit 3db7742

Please sign in to comment.