Skip to content

Commit

Permalink
Merge pull request #4631 from sqlcollaborative/development
Browse files Browse the repository at this point in the history
0.9.520
  • Loading branch information
potatoqualitee committed Nov 22, 2018
2 parents 616fcd9 + 9978040 commit 1ffbbbb
Show file tree
Hide file tree
Showing 109 changed files with 4,895 additions and 5,955 deletions.
5,057 changes: 2,218 additions & 2,839 deletions allcommands.ps1

Large diffs are not rendered by default.

Binary file added bin/csv/LumenWorks.Framework.IO.dll
Binary file not shown.
1,295 changes: 645 additions & 650 deletions bin/dbatools-index.json

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions dbatools.psd1
Expand Up @@ -11,7 +11,7 @@
RootModule = 'dbatools.psm1'

# Version number of this module.
ModuleVersion = '0.9.519'
ModuleVersion = '0.9.520'

# ID used to uniquely identify this module
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'
Expand Down Expand Up @@ -76,7 +76,7 @@
'Copy-DbaDbMail',
'Copy-DbaDbAssembly',
'Copy-DbaPolicyManagement',
'Copy-DbaAgentSharedSchedule',
'Copy-DbaAgentSchedule',
'Copy-DbaAgentOperator',
'Copy-DbaAgentJob',
'Copy-DbaDataCollector',
Expand All @@ -86,21 +86,21 @@
'Copy-DbaServerAudit',
'Copy-DbaServerRole',
'Copy-DbaResourceGovernor',
'Copy-DbaExtendedEvent',
'Copy-DbaXESession',
'Copy-DbaBackupDevice',
'Copy-DbaServerTrigger',
'Copy-DbaCredential',
'Copy-DbaCentralManagementServer',
'Copy-DbaCmsRegServer',
'Copy-DbaSysDbUserObject',
'Copy-DbaAgentProxyAccount',
'Copy-DbaAgentProxy',
'Copy-DbaAgentAlert',
'Import-DbaSpConfigure',
'Export-DbaSpConfigure'
'Get-DbaDetachedDatabaseInfo',
'Restore-DbaBackupFromDirectory',
'Test-DbaConnection',
'Import-DbaCsvToSql',
'Copy-DbaAgentCategory',
'Import-DbaCsv',
'Copy-DbaAgentJobCategory',
'Update-Dbatools',
'Test-DbaPath',
'Export-DbaLogin',
Expand Down Expand Up @@ -212,7 +212,7 @@
'Get-DbaDbQueryStoreOption',
'Set-DbaDbQueryStoreOption',
'Restore-DbaDatabase',
'Copy-DbaQueryStoreConfig',
'Copy-DbaDbQueryStoreOption',
'Get-DbaExecutionPlan',
'Export-DbaExecutionPlan',
'Get-DbaServerProtocol',
Expand Down Expand Up @@ -757,7 +757,14 @@
'Get-DbaRoleMember',
'Get-DbaRestoreHistory',
'Expand-DbaTLogResponsibly',
'Test-DbaRecoveryModel'
'Test-DbaRecoveryModel',
'Copy-DbaAgentCategory',
'Copy-DbaAgentProxyAccount',
'Copy-DbaAgentSharedSchedule',
'Copy-DbaCentralManagementServer',
'Copy-DbaExtendedEvent',
'Copy-DbaQueryStoreConfig',
'Import-DbaCsvToSql'

# List of all modules packaged with this module
ModuleList = @()
Expand Down
45 changes: 40 additions & 5 deletions dbatools.psm1
Expand Up @@ -233,7 +233,7 @@ Write-ImportTime -Text "Script: Maintenance"
$script:renames = @(
@{
"AliasName" = "Copy-SqlAgentCategory"
"Definition" = "Copy-DbaAgentCategory"
"Definition" = "Copy-DbaAgentJobCategory"
},
@{
"AliasName" = "Copy-SqlAlert"
Expand All @@ -253,7 +253,7 @@ $script:renames = @(
},
@{
"AliasName" = "Copy-SqlCentralManagementServer"
"Definition" = "Copy-DbaCentralManagementServer"
"Definition" = "Copy-DbaCmsRegServer"
},
@{
"AliasName" = "Copy-SqlCredential"
Expand Down Expand Up @@ -285,7 +285,7 @@ $script:renames = @(
},
@{
"AliasName" = "Copy-SqlExtendedEvent"
"Definition" = "Copy-DbaExtendedEvent"
"Definition" = "Copy-DbaXESession"
},
@{
"AliasName" = "Copy-SqlJob"
Expand Down Expand Up @@ -313,7 +313,7 @@ $script:renames = @(
},
@{
"AliasName" = "Copy-SqlProxyAccount"
"Definition" = "Copy-DbaAgentProxyAccount"
"Definition" = "Copy-DbaAgentProxy"
},
@{
"AliasName" = "Copy-SqlResourceGovernor"
Expand All @@ -329,7 +329,7 @@ $script:renames = @(
},
@{
"AliasName" = "Copy-SqlSharedSchedule"
"Definition" = "Copy-DbaAgentSharedSchedule"
"Definition" = "Copy-DbaAgentSchedule"
},
@{
"AliasName" = "Copy-SqlSpConfigure"
Expand Down Expand Up @@ -933,6 +933,34 @@ $script:renames = @(
@{
"AliasName" = "Test-DbaRecoveryModel"
"Definition" = "Test-DbaDbRecoveryModel"
},
@{
"AliasName" = "Copy-DbaAgentCategory"
"Definition" = "Copy-DbaAgentJobCategory"
},
@{
"AliasName" = "Copy-DbaAgentProxyAccount"
"Definition" = "Copy-DbaAgentProxy"
},
@{
"AliasName" = "Copy-DbaAgentSharedSchedule"
"Definition" = "Copy-DbaAgentSchedule"
},
@{
"AliasName" = "Copy-DbaCentralManagementServer"
"Definition" = "Copy-DbaCmsRegServer"
},
@{
"AliasName" = "Copy-DbaExtendedEvent"
"Definition" = "Copy-DbaXESession"
},
@{
"AliasName" = "Copy-DbaQueryStoreConfig"
"Definition" = "Copy-DbaDbQueryStoreOption"
},
@{
"AliasName" = "Import-DbaCsvToSql"
"Definition" = "Import-DbaCsv"
}
)

Expand Down Expand Up @@ -1005,4 +1033,11 @@ if ($PSCommandPath -like "*.psm1") {

[Sqlcollaborative.Dbatools.dbaSystem.SystemHost]::ModuleImported = $true;

if (Get-Module -Name sqlserver, sqlps) {
if (Get-DbatoolsConfigValue -FullName Import.SqlpsCheck) {
Write-Warning -Message 'SQLPS or SqlServer was previously imported during this session. If you encounter weird issues with dbatools, please restart PowerShell, then import dbatools without loading SQLPS or SqlServer first.'
Write-Warning -Message 'To disable this message, type: Set-DbatoolsConfig -Name Import.SqlpsCheck -Value $false'
}
}

#endregion Post-Import Cleanup
36 changes: 20 additions & 16 deletions functions/Add-DbaAgDatabase.ps1
Expand Up @@ -109,23 +109,27 @@ function Add-DbaAgDatabase {

foreach ($replica in $replicas) {
$replicadb = Get-DbaAgDatabase -SqlInstance $replica -SqlCredential $SqlCredential -Database $db.Name -AvailabilityGroup $ag.Name
$timeout = 1
do {
try {
Write-Message -Level Verbose -Message "Trying to add $($replicadb.Name) to $replica"
$timeout++
$replicadb.JoinAvailablityGroup()
$replicadb.Refresh()
Start-Sleep -Seconds 1
} catch {
Stop-Function -Message "Error joining database to availability group" -ErrorRecord $_ -Continue
if ($replicadb) {
if ($Pscmdlet.ShouldProcess($ag.Parent.Name, "Joining availability group $db to $($db.Parent.Name)")) {
$timeout = 1
do {
try {
Write-Message -Level Verbose -Message "Trying to add $($replicadb.Name) to $replica"
$timeout++
$replicadb.JoinAvailablityGroup()
$replicadb.Refresh()
Start-Sleep -Seconds 1
} catch {
Stop-Function -Message "Error joining database to availability group" -ErrorRecord $_ -Continue
}
} while (-not $replicadb.IsJoined -and $timeout -lt 10)

if ($replicadb.IsJoined) {
$replicadb
} else {
Stop-Function -Continue -Message "Could not join $($replicadb.Name) to $replica"
}
}
} while (-not $replicadb.IsJoined -and $timeout -lt 10)

if ($replicadb.IsJoined) {
$replicadb
} else {
Stop-Function -Continue -Message "Could not join $($replicadb.Name) to $replica"
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions functions/Add-DbaComputerCertificate.ps1
Expand Up @@ -13,7 +13,7 @@ function Add-DbaComputerCertificate {
.PARAMETER Credential
Allows you to login to $ComputerName using alternative credentials.
.PARAMETER Password
.PARAMETER SecurePassword
The password for the certificate, if it is password protected.
.PARAMETER Certificate
Expand Down Expand Up @@ -63,7 +63,8 @@ function Add-DbaComputerCertificate {
[Alias("ServerInstance", "SqlServer", "SqlInstance")]
[DbaInstance[]]$ComputerName = $env:COMPUTERNAME,
[PSCredential]$Credential,
[SecureString]$Password,
[Alias("Password")]
[SecureString]$SecurePassword,
[parameter(ValueFromPipeline)]
[System.Security.Cryptography.X509Certificates.X509Certificate2[]]$Certificate,
[string]$Path,
Expand All @@ -85,7 +86,7 @@ function Add-DbaComputerCertificate {
# This may be too much, but oh well
$bytes = [System.IO.File]::ReadAllBytes($Path)
$Certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$Certificate.Import($bytes, $Password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::DefaultKeySet)
$Certificate.Import($bytes, $SecurePassword, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::DefaultKeySet)
} catch {
Stop-Function -Message "Can't import certificate." -ErrorRecord $_
return
Expand All @@ -98,15 +99,15 @@ function Add-DbaComputerCertificate {
param (
$CertificateData,

[SecureString]$Password,
[SecureString]$SecurePassword,

$Store,

$Folder
)

$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($CertificateData, $Password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::DefaultKeySet)
$cert.Import($CertificateData, $SecurePassword, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::DefaultKeySet)
Write-Message -Level Verbose -Message "Importing cert to $Folder\$Store"
$tempStore = New-Object System.Security.Cryptography.X509Certificates.X509Store($Folder, $Store)
$tempStore.Open('ReadWrite')
Expand All @@ -129,7 +130,7 @@ function Add-DbaComputerCertificate {
foreach ($cert in $Certificate) {

try {
$certData = $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::PFX, $Password)
$certData = $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::PFX, $SecurePassword)
} catch {
Stop-Function -Message "Can't export certificate" -ErrorRecord $_ -Continue
}
Expand All @@ -138,7 +139,7 @@ function Add-DbaComputerCertificate {

if ($PSCmdlet.ShouldProcess("local", "Connecting to $computer to import cert")) {
try {
Invoke-Command2 -ComputerName $computer -Credential $Credential -ArgumentList $certdata, $Password, $Store, $Folder -ScriptBlock $scriptblock -ErrorAction Stop |
Invoke-Command2 -ComputerName $computer -Credential $Credential -ArgumentList $certdata, $SecurePassword, $Store, $Folder -ScriptBlock $scriptblock -ErrorAction Stop |
Select-DefaultView -Property FriendlyName, DnsNameList, Thumbprint, NotBefore, NotAfter, Subject, Issuer
} catch {
Stop-Function -Message "Failure" -ErrorRecord $_ -Target $computer -Continue
Expand Down
17 changes: 9 additions & 8 deletions functions/Backup-DbaDbMasterKey.ps1
Expand Up @@ -25,7 +25,7 @@ function Backup-DbaDbMasterKey {
.PARAMETER Credential
Pass a credential object for the password
.PARAMETER Password
.PARAMETER SecurePassword
The password to encrypt the exported key. This must be a SecureString.
.PARAMETER InputObject
Expand Down Expand Up @@ -76,15 +76,16 @@ function Backup-DbaDbMasterKey {
[PSCredential]$Credential,
[string[]]$Database,
[string[]]$ExcludeDatabase,
[Security.SecureString]$Password,
[Alias("Password")]
[Security.SecureString]$SecurePassword,
[string]$Path,
[parameter(ValueFromPipeline)]
[Microsoft.SqlServer.Management.Smo.Database[]]$InputObject,
[switch]$EnableException
)
begin {
if ($Credential) {
$Password = $Credential.Password
$SecurePassword = $Credential.Password
}
}
process {
Expand Down Expand Up @@ -120,11 +121,11 @@ function Backup-DbaDbMasterKey {
}

# If you pass a password param, then you will not be prompted for each database, but it wouldn't be a good idea to build in insecurity
if (-not $Password -and -not $Credential) {
$password = Read-Host -AsSecureString -Prompt "You must enter Service Key password for $instance"
$password2 = Read-Host -AsSecureString -Prompt "Type the password again"
if (-not $SecurePassword -and -not $Credential) {
$SecurePassword = Read-Host -AsSecureString -Prompt "You must enter Service Key password for $instance"
$SecurePassword2 = Read-Host -AsSecureString -Prompt "Type the password again"

if (([System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($password))) -ne ([System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($password2)))) {
if (([System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($SecurePassword))) -ne ([System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($SecurePassword2)))) {
Stop-Function -Message "Passwords do not match" -Continue
}
}
Expand All @@ -137,7 +138,7 @@ function Backup-DbaDbMasterKey {

if ($Pscmdlet.ShouldProcess($instance, "Backing up master key to $filename")) {
try {
$masterkey.Export($filename, [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($password)))
$masterkey.Export($filename, [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($SecurePassword)))
$status = "Success"
} catch {
$status = "Failure"
Expand Down

0 comments on commit 1ffbbbb

Please sign in to comment.