From af2a959f33fa1416398f5056484a144fbe559645 Mon Sep 17 00:00:00 2001 From: Chrissy LeMaire Date: Tue, 11 Sep 2018 16:43:11 +0200 Subject: [PATCH] 0.9.418 --- allcommands.ps1 | 2466 +++++++++-------- bin/dbatools-index.json | 40 +- ...SQLServerDiagnosticQueries_2012_201807.sql | 2 +- ...SQLServerDiagnosticQueries_2014_201807.sql | 2 +- ...ServerDiagnosticQueries_2016SP2_201807.sql | 2 +- ...SQLServerDiagnosticQueries_2016_201807.sql | 2 +- ...SQLServerDiagnosticQueries_2017_201807.sql | 2 +- ...gnosticQueries_AzureSQLDatabase_201807.sql | 2 +- dbatools.psd1 | 36 +- dbatools.psm1 | 14 +- install.ps1 | 14 +- xml/dbatools.Format.ps1xml | 14 +- xml/dbatools.Types.ps1xml | 14 +- 13 files changed, 1376 insertions(+), 1234 deletions(-) diff --git a/allcommands.ps1 b/allcommands.ps1 index 332615efcf..0a33d54fa2 100644 --- a/allcommands.ps1 +++ b/allcommands.ps1 @@ -42,7 +42,7 @@ function Add-DbaComputerCertificate { .NOTES Tags: Certificate - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -191,6 +191,7 @@ function Add-DbaPfDataCollectorCounter { .NOTES Tags: PerfMon + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -333,7 +334,7 @@ function Add-DbaRegisteredServer { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Author: Chrissy LeMaire (@cl) + Author: Chrissy LeMaire (@cl), netnerds.net Tags: RegisteredServer, CMS Website: https://dbatools.io @@ -480,7 +481,7 @@ function Add-DbaRegisteredServerGroup { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Author: Chrissy LeMaire (@cl) + Author: Chrissy LeMaire (@cl), netnerds.net Tags: RegisteredServer, CMS Website: https://dbatools.io @@ -1428,7 +1429,7 @@ Database object piped in from Get-DbaDatabase .NOTES Tags: Certificate, Database - +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -1566,7 +1567,7 @@ function Clear-DbaConnectionPool { .NOTES Tags: Connection - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -1754,6 +1755,7 @@ function Clear-DbaWaitStatistics { .NOTES Tags: WaitStatistic + Author: Chrissy LeMaire (@cl) Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -1933,6 +1935,7 @@ function Connect-DbaInstance { .NOTES Tags: Connect, Connection + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -2851,6 +2854,7 @@ function ConvertTo-DbaXESession { .NOTES Tags: Trace, ExtendedEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -11729,7 +11733,7 @@ function Copy-DbaSysDbUserObject { .NOTES Tags: Migration, SystemDatabase, UserObject - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -12115,6 +12119,7 @@ function Copy-DbaXESessionTemplate { .NOTES Tags: ExtendedEvent, XE, XEvent Website: https://dbatools.io + Author: Chrissy LeMaire (@cl), netnerds.net Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -12387,7 +12392,7 @@ function Disable-DbaForceNetworkEncryption { .NOTES Tags: Certificate - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -12619,6 +12624,7 @@ function Dismount-DbaDatabase { .NOTES Tags: Database + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -13044,7 +13050,7 @@ function Enable-DbaForceNetworkEncryption { .NOTES Tags: Certificate - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -13971,6 +13977,7 @@ function Export-DbaCredential { .NOTES Tags: Credential + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -14363,7 +14370,6 @@ function Export-DbaDiagnosticQuery { $SqlInstance = $row.SqlInstance.Replace("\", "$") $dbname = $row.Database $number = $row.Number - $note = $row.Note if ($null -eq $result) { Stop-Function -Message "Result was empty for $name" -Target $result -Continue @@ -14451,7 +14457,7 @@ function Export-DbaExecutionPlan { Exports execution plans to disk. .DESCRIPTION - Exports execution plans to disk. Can pipe from Export-DbaExecutionPlan + Exports execution plans to disk. Can pipe from Get-DbaExecutionPlan Thanks to https://www.simple-talk.com/sql/t-sql-programming/dmvs-for-query-plan-metadata/ @@ -14496,7 +14502,8 @@ function Export-DbaExecutionPlan { .NOTES Tags: Performance, ExecutionPlan - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io Copyright (C) 2016 Chrissy LeMaire License: MIT https://opensource.org/licenses/MIT @@ -14504,14 +14511,25 @@ function Export-DbaExecutionPlan { https://dbatools.io/Export-DbaExecutionPlan .EXAMPLE - Export-DbaExecutionPlan -SqlInstance sqlserver2014a + Export-DbaExecutionPlan -SqlInstance sqlserver2014a -Path C:\Temp + + Exports all execution plans for sqlserver2014a. Files saved in to C:\Temp + + .EXAMPLE + Export-DbaExecutionPlan -SqlInstance sqlserver2014a -Database db1, db2 -SinceLastExecution '2016-07-01 10:47:00' -Path C:\Temp + + Exports all execution plans for databases db1 and db2 on sqlserver2014a since July 1, 2016 at 10:47 AM. Files saved in to C:\Temp + + .EXAMPLE + Get-DbaExecutionPlan -SqlInstance sqlserver2014a | Export-DbaExecutionPlan -Path C:\Temp - Exports all execution plans for sqlserver2014a. + Gets all execution plans for sqlserver2014a. Using Pipeline exports them all to C:\Temp .EXAMPLE - Export-DbaExecutionPlan -SqlInstance sqlserver2014a -Database db1, db2 -SinceLastExecution '7/1/2016 10:47:00' + Get-DbaExecutionPlan -SqlInstance sqlserver2014a | Export-DbaExecutionPlan -Path C:\Temp -WhatIf + + Gets all execution plans for sqlserver2014a. Then shows what would happen if the results where piped to Export-DbaExecutionPlan - Exports all execution plans for databases db1 and db2 on sqlserver2014a since July 1, 2016 at 10:47 AM. #> [cmdletbinding(SupportsShouldProcess = $true, DefaultParameterSetName = "Default")] param ( @@ -14537,13 +14555,6 @@ function Export-DbaExecutionPlan { ) begin { - if ($SinceCreation -ne $null) { - $SinceCreation = $SinceCreation.ToString("yyyy-MM-dd HH:mm:ss") - } - - if ($SinceLastExecution -ne $null) { - $SinceLastExecution = $SinceLastExecution.ToString("yyyy-MM-dd HH:mm:ss") - } function Export-Plan { param( @@ -14626,7 +14637,7 @@ function Export-DbaExecutionPlan { CROSS APPLY sys.dm_exec_query_plan(deqs.plan_handle) AS deqp CROSS APPLY sys.dm_exec_sql_text(deqs.plan_handle) AS execText" - if ($ExcludeDatabase -or $Database -or $SinceCreation.Length -gt 0 -or $SinceLastExecution.length -gt 0 -or $ExcludeEmptyQueryPlan -eq $true) { + if ($ExcludeDatabase -or $Database -or $SinceCreation -or $SinceLastExecution -or $ExcludeEmptyQueryPlan -eq $true) { $where = " WHERE " } @@ -14639,12 +14650,12 @@ function Export-DbaExecutionPlan { if (Test-Bound 'SinceCreation') { Write-Message -Level Verbose -Message "Adding creation time" - $whereArray += " creation_time >= '$SinceCreation' " + $whereArray += " creation_time >= '" + $SinceCreation.ToString("yyyy-MM-dd HH:mm:ss") + "' " } if (Test-Bound 'SinceLastExecution') { Write-Message -Level Verbose -Message "Adding last execution time" - $whereArray += " last_execution_time >= '$SinceLastExecution' " + $whereArray += " last_execution_time >= '" + $SinceLastExecution.ToString("yyyy-MM-dd HH:mm:ss") + "' " } if (Test-Bound 'ExcludeDatabase') { @@ -14819,7 +14830,7 @@ function Export-DbaInstance { .NOTES Tags: Export - Author: Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net Limitations: Doesn't cover what it doesn't cover (certificates, etc) SQL Server 2000 login exports have some limitations (server perms aren't exported) SQL Server 2000 databases cannot be directly exported to SQL Server 2012 and above. @@ -15128,6 +15139,7 @@ function Export-DbaLinkedServer { .NOTES Tags: LinkedServer + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -15693,6 +15705,7 @@ function Export-DbaPfDataCollectorSetTemplate { .NOTES Tags: Performance, DataCollector + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -15792,7 +15805,7 @@ function Export-DbaRegisteredServer { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Author: Chrissy LeMaire (@cl) + Author: Chrissy LeMaire (@cl), netnerds.net Tags: RegisteredServer, CMS Website: https://dbatools.io @@ -15945,7 +15958,7 @@ function Export-DbaScript { .NOTES Tags: Migration, Backup, Export - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -16220,6 +16233,7 @@ function Export-DbaSpConfigure { .NOTES Tags: SpConfig, Configure, Configuration Website: https://dbatools.io + Author: Chrissy LeMaire (@cl), netnerds.net Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -16313,8 +16327,8 @@ function Export-DbaUser { .PARAMETER DestinationVersion To say to which version the script should be generated. If not specified will use database compatibility level - .PARAMETER FilePath - The file to write to. + .PARAMETER Path + Specifies the full path of a file to write the script to. .PARAMETER NoClobber Do not overwrite file @@ -16352,27 +16366,27 @@ function Export-DbaUser { https://dbatools.io/Export-DbaUser .EXAMPLE - Export-DbaUser -SqlInstance sql2005 -FilePath C:\temp\sql2005-users.sql + Export-DbaUser -SqlInstance sql2005 -Path C:\temp\sql2005-users.sql Exports SQL for the users in server "sql2005" and writes them to the file "C:\temp\sql2005-users.sql" .EXAMPLE - Export-DbaUser -SqlInstance sqlserver2014a $scred -FilePath C:\temp\users.sql -Append + Export-DbaUser -SqlInstance sqlserver2014a $scred -Path C:\temp\users.sql -Append Authenticates to sqlserver2014a using SQL Authentication. Exports all users to C:\temp\users.sql, and appends to the file if it exists. If not, the file will be created. .EXAMPLE - Export-DbaUser -SqlInstance sqlserver2014a -User User1, User2 -FilePath C:\temp\users.sql + Export-DbaUser -SqlInstance sqlserver2014a -User User1, User2 -Path C:\temp\users.sql Exports ONLY users User1 and User2 from sqlsever2014a to the file C:\temp\users.sql .EXAMPLE - Export-DbaUser -SqlInstance sqlserver2008 -User User1 -FilePath C:\temp\users.sql -DestinationVersion SQLServer2016 + Export-DbaUser -SqlInstance sqlserver2008 -User User1 -Path C:\temp\users.sql -DestinationVersion SQLServer2016 Exports user User1 from sqlsever2008 to the file C:\temp\users.sql with syntax to run on SQL Server 2016 .EXAMPLE - Export-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -FilePath C:\temp\users.sql + Export-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -Path C:\temp\users.sql Exports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\temp\users.sql file. @@ -16381,13 +16395,13 @@ function Export-DbaUser { $options.ScriptDrops = $false $options.WithDependencies = $true - Export-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -FilePath C:\temp\users.sql -ScriptingOptionsObject $options + Export-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -Path C:\temp\users.sql -ScriptingOptionsObject $options Exports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\temp\users.sql file. It will not script drops but will script dependencies. .EXAMPLE - Export-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -FilePath C:\temp\users.sql -ExcludeGoBatchSeparator + Export-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -Path C:\temp\users.sql -ExcludeGoBatchSeparator Exports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\temp\users.sql file without the 'GO' batch separator. @@ -16407,8 +16421,8 @@ function Export-DbaUser { [object[]]$User, [ValidateSet('SQLServer2000', 'SQLServer2005', 'SQLServer2008/2008R2', 'SQLServer2012', 'SQLServer2014', 'SQLServer2016', 'SQLServer2017')] [string]$DestinationVersion, - [Alias("OutFile", "Path", "FileName")] - [string]$FilePath, + [Alias("OutFile", "FilePath", "FileName")] + [string]$Path, [Alias("NoOverwrite")] [switch]$NoClobber, [switch]$Append, @@ -16419,9 +16433,9 @@ function Export-DbaUser { ) begin { - if ($FilePath) { - if ($FilePath -notlike "*\*") { $FilePath = ".\$filepath" } - $directory = Split-Path $FilePath + if ($Path) { + if ($Path -notlike "*\*") { $Path = ".\$Path" } + $directory = Split-Path $Path $exists = Test-Path $directory if ($exists -eq $false) { @@ -16457,7 +16471,7 @@ function Export-DbaUser { if (Test-FunctionInterrupt) { return } try { - Write-Message -Level Verbose -Message "Connecting to $sqlinstance" + Write-Message -Level Verbose -Message "Connecting to $SqlInstance" $server = Connect-SqlInstance -SqlInstance $SqlInstance -SqlCredential $SqlCredential } catch { @@ -16750,8 +16764,8 @@ function Export-DbaUser { $sql += "`r`nGO" } - if ($FilePath) { - $sql | Out-File -Encoding UTF8 -FilePath $FilePath -Append:$Append -NoClobber:$NoClobber + if ($Path) { + $sql | Out-File -Encoding UTF8 -FilePath $Path -Append:$Append -NoClobber:$NoClobber } else { $sql @@ -16925,10 +16939,10 @@ function Export-DbaXECsv { function Export-DbaXESessionTemplate { <# .SYNOPSIS - Exports an XESession XML Template. + Exports an XESession XML Template using XE Session(s) output by Get-DbaXESession .DESCRIPTION - Exports an XESession XML Template either from the dbatools repository or a file you specify. Exports to "$home\Documents\SQL Server Management Studio\Templates\XEventTemplates" by default + Exports an XESession XML Template either from the Target SQL Server or XE Session(s) output by Get-DbaXESession. Exports to "$home\Documents\SQL Server Management Studio\Templates\XEventTemplates" by default .PARAMETER SqlInstance Target SQL Server. You must have sysadmin access and server version must be SQL Server version 2008 or higher. @@ -16952,6 +16966,7 @@ function Export-DbaXESessionTemplate { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -16962,12 +16977,12 @@ function Export-DbaXESessionTemplate { .EXAMPLE Export-DbaXESessionTemplate -SqlInstance sql2017 -Path C:\temp\xe - Exports XE Session Template to the C:\temp\xe folder. + Exports an XESession XML Template for all Extended Event Sessions on sql2017 to the C:\temp\xe folder. .EXAMPLE - Get-DbaXESession -SqlInstance sql2017 -Session session_health | Export-DbaXESessionTemplate -Path C:\temp + Get-DbaXESession -SqlInstance sql2017 -Session system_health | Export-DbaXESessionTemplate -Path C:\temp\xe - Returns a new XE Session object from sql2017 then adds an event, an action then creates it. + Gets the system_health Extended Events Session from sql2017 and then exports as an XESession XML Template to C:\temp\xe #> [CmdletBinding()] @@ -17077,7 +17092,7 @@ function Find-DbaAgentJob { https://dbatools.io/Find-DbaAgentJob .EXAMPLE - Find-DbaAgentJob -SqlInstance Dev01 -JobName backup* + Find-DbaAgentJob -SqlInstance Dev01 -JobName *backup* Returns all agent job(s) that have backup in the name @@ -17104,7 +17119,7 @@ function Find-DbaAgentJob { .EXAMPLE Find-DbaAgentJob -SqlInstance Dev01 -LastUsed 10 -Exclude "Yearly - RollUp Workload", "SMS - Notification" - Returns all agent jobs that havent ran in the last 10 ignoring jobs "Yearly - RollUp Workload" and "SMS - Notification" + Returns all agent jobs that havent ran in the last 10 days ignoring jobs "Yearly - RollUp Workload" and "SMS - Notification" .EXAMPLE Find-DbaAgentJob -SqlInstance Dev01 -Category "REPL-Distribution", "REPL-Snapshot" -Detailed | Format-Table -AutoSize -Wrap @@ -17112,9 +17127,9 @@ function Find-DbaAgentJob { Returns all job/s on Dev01 that are in either category "REPL-Distribution" or "REPL-Snapshot" with detailed output .EXAMPLE - Find-DbaAgentJob -SqlInstance Dev01, Dev02 -IsFailed -Since '7/1/2016 10:47:00' + Find-DbaAgentJob -SqlInstance Dev01, Dev02 -IsFailed -Since '2016-07-01 10:47:00' - Returns all agent job(s) that have failed since July of 2016 (and still have history in msdb) + Returns all agent job(s) on Dev01 and Dev02 that have failed since July of 2016 (and still have history in msdb) .EXAMPLE Get-DbaRegisteredServer -SqlInstance CMSServer -Group Production | Find-DbaAgentJob -Disabled -IsNotScheduled | Format-Table -AutoSize -Wrap @@ -20950,8 +20965,8 @@ function Find-DbaUnusedIndex { .PARAMETER ExcludeDatabase Specifies the database(s) to exclude from processing. Options for this list are auto-populated from the server. - .PARAMETER FilePath - Specifies the path of a file to write the DROP statements to. + .PARAMETER Path + Specifies the full path of a file to write the DROP statements to. .PARAMETER NoClobber If this switch is enabled, the output file will not be overwritten. @@ -20985,12 +21000,12 @@ function Find-DbaUnusedIndex { https://dbatools.io/Find-DbaUnusedIndex .EXAMPLE - Find-DbaUnusedIndex -SqlInstance sql2005 -FilePath C:\temp\sql2005-UnusedIndexes.sql + Find-DbaUnusedIndex -SqlInstance sql2005 -Path C:\temp\sql2005-UnusedIndexes.sql Generates the SQL statements to drop the selected unused indexes on server "sql2005". The statements are written to the file "C:\temp\sql2005-UnusedIndexes.sql" .EXAMPLE - Find-DbaUnusedIndex -SqlInstance sql2005 -FilePath C:\temp\sql2005-UnusedIndexes.sql -Append + Find-DbaUnusedIndex -SqlInstance sql2005 -Path C:\temp\sql2005-UnusedIndexes.sql -Append Generates the SQL statements to drop the selected unused indexes on server "sql2005". The statements are written to the file "C:\temp\sql2005-UnusedIndexes.sql", appending if the file already exists. @@ -21002,18 +21017,18 @@ function Find-DbaUnusedIndex { .EXAMPLE Find-DbaUnusedIndex -SqlInstance sqlserver2016 -Database db1, db2 - Generates the SQL Statement to to drop selected indexes in databases db1 & db2 on server "sqlserver2016". + Generates the SQL Statement to drop the selected unused indexes in databases db1 & db2 on server "sqlserver2016". .EXAMPLE Find-DbaUnusedIndex -SqlInstance sqlserver2016 - Generates the SQL statements to drop selected indexes on all user databases. + Generates the SQL statements to drop the selected unused indexes on all user databases. .EXAMPLE Fine-DbaUnusedIndex -SqlInstance sqlserver2016 -IgnoreUptime - Generates the SQL statements to drop selected indexes on all user databases even if the instance has been online for less than 7 days. - Note that results may not have enough detail for all indexes, so care should be taken when using them or the generated scripts. Best practice is to allow a full week to capture the mmajority of index use cases + Generates the SQL statements to drop the selected unused indexes on all user databases even if the instance has been online for less than 7 days. + Note that results may not have enough detail for all indexes, so care should be taken when using them or the generated scripts. Best practice is to allow a full week to capture the majority of index use cases #> [CmdletBinding(SupportsShouldProcess = $true)] @@ -21025,8 +21040,8 @@ function Find-DbaUnusedIndex { [Alias("Databases")] [object[]]$Database, [object[]]$ExcludeDatabase, - [Alias("OutFile", "Path")] - [string]$FilePath, + [Alias("OutFile", "FilePath")] + [string]$Path, [switch]$NoClobber, [switch]$Append, [switch]$IgnoreUptime, @@ -21076,11 +21091,11 @@ function Find-DbaUnusedIndex { AND user_lookups = 0 AND i.type_desc NOT IN ('HEAP', 'CLUSTERED COLUMNSTORE')" - if ($FilePath.Length -gt 0) { - if ($FilePath -notlike "*\*") { - $FilePath = ".\$FilePath" + if ($Path.Length -gt 0) { + if ($Path -notlike "*\*") { + $Path = ".\$Path" } - $directory = Split-Path $FilePath + $directory = Split-Path $Path $exists = Test-Path $directory if ($exists -eq $false) { @@ -21090,7 +21105,7 @@ function Find-DbaUnusedIndex { } Write-Message -Level Output -Message "Connecting to SQL Server." - $server = Connect-SqlInstance -SqlInstance $SqlInstance -SqlCredential $SqlCredential + $server = Connect-SqlInstance -SqlInstance $SqlInstance -SqlCredential $SqlCredential -MinimumVersion 9 } process { if (Test-FunctionInterrupt) { return } @@ -21164,7 +21179,7 @@ function Find-DbaUnusedIndex { if ($indexesToDrop.Count -gt 0 -or !([string]::IsNullOrEmpty($indexesToDrop))) { foreach ($index in $indexesToDrop) { - if ($FilePath.Length -gt 0) { + if ($Path.Length -gt 0) { Write-Message -Level Output -Message "Exporting $($index.TableName).$($index.IndexName)" $sqlout += "USE [$($index.DatabaseName)]`r`n" $sqlout += "GO`r`n" @@ -21175,8 +21190,8 @@ function Find-DbaUnusedIndex { } } - if ($FilePath.Length -gt 0) { - $sqlout | Out-File -FilePath $FilePath -Append:$Append -NoClobber:$NoClobber + if ($Path.Length -gt 0) { + $sqlout | Out-File -FilePath $Path -Append:$Append -NoClobber:$NoClobber } else { $indexesToDrop @@ -21197,8 +21212,8 @@ function Find-DbaUnusedIndex { if ($scriptGenerated) { Write-Message -Level Warning -Message "Confirm the generated script before execute!" } - if ($FilePath.Length -gt 0) { - Write-Message -Level Output -Message "Script generated to $FilePath" + if ($Path.Length -gt 0) { + Write-Message -Level Output -Message "Script generated to $Path" } } else { @@ -22232,7 +22247,7 @@ function Get-DbaAgentJob { .EXAMPLE $servers | Get-DbaAgentJob | Out-GridView -Passthru | Start-DbaAgentJob -WhatIf - Find all of your Jobs from servers in the $server collection, select the jobs you want to start then see jobs would start if you ran Start-DbaAgentJob + Find all of your Jobs from SQL Server instances in the $servers collection, select the jobs you want to start then see jobs would start if you ran Start-DbaAgentJob #> [CmdletBinding()] param ( @@ -22914,7 +22929,7 @@ function Get-DbaAgentJobStep { .EXAMPLE Get-DbaAgentJobStep -SqlInstance localhost, sql2016 - Returns all SQl Agent Job Steps for the local and sql2016 SQL Server instances + Returns all SQL Agent Job Steps for the local and sql2016 SQL Server instances .EXAMPLE Get-DbaAgentJobStep -SqlInstance localhost -Job BackupData, BackupDiff @@ -22924,17 +22939,17 @@ function Get-DbaAgentJobStep { .EXAMPLE Get-DbaAgentJobStep -SqlInstance localhost -ExcludeJob BackupDiff - Returns all SQl Agent Job Steps for the local SQL Server instances, except for the BackupDiff Job. + Returns all SQL Agent Job Steps for the local SQL Server instances, except for the BackupDiff Job. .EXAMPLE Get-DbaAgentJobStep -SqlInstance localhost -NoDisabledJobs - Returns all SQl Agent Job Steps for the local SQL Server instances, excluding the disabled jobs. + Returns all SQL Agent Job Steps for the local SQL Server instances, excluding the disabled jobs. .EXAMPLE $servers | Get-DbaAgentJobStep - Find all of your Job Steps from servers in the $server collection + Find all of your Job Steps from SQL Server instances in the $servers collection #> [CmdletBinding()] param ( @@ -23008,6 +23023,7 @@ function Get-DbaAgentLog { .NOTES Tags: Logging + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -23120,7 +23136,6 @@ function Get-DbaAgentOperator { .NOTES Tags: Agent, Operator Author: Klaas Vandenberghe ( @PowerDBAKlaas ) - Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -23240,7 +23255,7 @@ function Get-DbaAgentProxy { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Author: Chrissy LeMaire ( @cl ) + Author: Chrissy LeMaire (@cl), netnerds.net Tags: Agent, SMO Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com @@ -24183,16 +24198,16 @@ function Get-DbaBackupHistory { .EXAMPLE Get-DbaBackupHistory -SqlInstance SqlInstance2014a - Returns server name, database, username, backup type, date for all backups databases on SqlInstance2014a. This may return many rows; consider using filters that are included in other examples. + Returns server name, database, username, backup type, date for all database backups still in msdb history on SqlInstance2014a. This may return many rows; consider using filters that are included in other examples. .EXAMPLE $cred = Get-Credential sqladmin Get-DbaBackupHistory -SqlInstance SqlInstance2014a -SqlCredential $cred - Does the same as above but logs in as SQL user "sqladmin" + Does the same as above but connect to SqlInstance2014a as SQL user "sqladmin" .EXAMPLE - Get-DbaBackupHistory -SqlInstance SqlInstance2014a -Database db1, db2 -Since '7/1/2016 10:47:00' + Get-DbaBackupHistory -SqlInstance SqlInstance2014a -Database db1, db2 -Since '2016-07-01 10:47:00' Returns backup information only for databases db1 and db2 on SqlInstance2014a since July 1, 2016 at 10:47 AM. @@ -24780,11 +24795,6 @@ function Get-DbaBackupInformation { 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. - .EXAMPLE - Get-DbaBackupInformation -SqlInstance Server1 -Path c:\backups\ -DirectoryRecurse - - Will use the Server1 instance to recursively read all backup files under c:\backups, and return a dbatools BackupHistory object - .NOTES Tags: DisasterRecovery, Backup, Restore @@ -24795,6 +24805,11 @@ function Get-DbaBackupInformation { .LINK https://dbatools.io/Get-DbaBackupInformation + .EXAMPLE + Get-DbaBackupInformation -SqlInstance Server1 -Path c:\backups\ -DirectoryRecurse + + Will use the Server1 instance to recursively read all backup files under c:\backups, and return a dbatools BackupHistory object + .EXAMPLE Get-DbaBackupInformation -SqlInstance Server1 -Path c:\backups\ -DirectoryRecurse -ExportPath c:\store\BackupHistory.xml @@ -24833,7 +24848,7 @@ function Get-DbaBackupInformation { .EXAMPLE $Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\network\backups -MaintenanceSolution -IgnoreLogBackup - As we know we are dealing with an Ola Hallengren style backup folder from the MaintenanceSolution switch, when IgnoreLogBackup is also included we can ignore the LOG folder to skip any scanning of log backups. Note this also means then WON'T be restored + As we know we are dealing with an Ola Hallengren style backup folder from the MaintenanceSolution switch, when IgnoreLogBackup is also included we can ignore the LOG folder to skip any scanning of log backups. Note this also means they WON'T be restored #> [CmdletBinding( DefaultParameterSetName = "Create")] param ( @@ -25003,7 +25018,7 @@ function Get-DbaBackupInformation { catch { Stop-Function -Message "Failure reading backup header" -ErrorRecord $_ -Target $server -Continue } - + $groupdetails = $FileDetails | group-object -Property BackupSetGUID foreach ($Group in $GroupDetails) { @@ -25368,43 +25383,51 @@ function Get-DbaBuildReference { } function Get-DbaClientAlias { <# - .SYNOPSIS - Creates/updates a sql alias for the specified server - mimics cliconfg.exe + .SYNOPSIS + Gets any SQL Server alias for the specified server(s) - .DESCRIPTION - Creates/updates a SQL Server alias by altering HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client + .DESCRIPTION + Gets SQL Server alias by reading HKLM:\SOFTWARE\Microsoft\MSSQLServer\Client - .PARAMETER ComputerName - The target computer where the alias will be created + .PARAMETER ComputerName + The target computer where the alias has been created - .PARAMETER Credential - Allows you to login to remote computers using alternative credentials + .PARAMETER Credential + Allows you to login to remote computers using alternative credentials - .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. + .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 - Tags: Alias + .NOTES + Tags: Alias + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com + License: MIT https://opensource.org/licenses/MIT - Website: https://dbatools.io - Copyright: (C) Chrissy LeMaire, clemaire@gmail.com - License: MIT https://opensource.org/licenses/MIT + .LINK + https://dbatools.io/Get-DbaClientAlias - .LINK - https://dbatools.io/Get-DbaClientAlias + .EXAMPLE + Get-DbaClientAlias + + Gets all SQL Server client aliases on the local computer .EXAMPLE - Get-DbaClientAlias - Gets all SQL Server client aliases on the local computer + Get-DbaClientAlias -ComputerName workstationx - .EXAMPLE - Get-DbaClientAlias -ComputerName workstationx - Gets all SQL Server client aliases on Workstationx + Gets all SQL Server client aliases on Workstationx + + .EXAMPLE + 'Server1', 'Server2' | Get-DbaClientAlias + + Gets all SQL Server client aliases on Server1 and Server2 #> - [CmdletBinding()] + [CmdletBinding()] Param ( + [Parameter(ValueFromPipeline)] [DbaInstanceParameter[]]$ComputerName = $env:COMPUTERNAME, [PSCredential]$Credential, [Alias('Silent')] @@ -25453,7 +25476,7 @@ function Get-DbaClientAlias { $architecture = "64-bit" } - # "Creating/updating alias for $ComputerName for $architecture" + # "Get SQL Server alias for $ComputerName for $architecture" $all = Get-Item -Path $connect foreach ($entry in $all.Property) { $value = Get-ItemPropertyValue -Path $connect -Name $entry @@ -25472,14 +25495,12 @@ function Get-DbaClientAlias { } } - if ($PScmdlet.ShouldProcess($computer, "Getting aliases")) { - try { - Invoke-Command2 -ComputerName $computer -Credential $Credential -ScriptBlock $scriptblock -ErrorAction Stop | - Select-DefaultView -Property ComputerName, Architecture, NetworkLibrary, ServerName, AliasName - } - catch { - Stop-Function -Message "Failure" -ErrorRecord $_ -Target $computer -Continue - } + try { + Invoke-Command2 -ComputerName $computer -Credential $Credential -ScriptBlock $scriptblock -ErrorAction Stop | + Select-DefaultView -Property ComputerName, Architecture, NetworkLibrary, ServerName, AliasName + } + catch { + Stop-Function -Message "Failure" -ErrorRecord $_ -Target $computer -Continue } } } @@ -25614,6 +25635,7 @@ function Get-DbaClusterNode { .NOTES Tags: Cluster, WSFC, FCI + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -26190,6 +26212,7 @@ function Get-DbaComputerCertificate { .NOTES Tags: Certificate + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -26299,7 +26322,7 @@ function Get-DbaComputerSystem { Tags: ServerInfo Author: Shawn Melton (@wsmelton | http://blog.wsmelton.info) - Website: https: //dbatools.io + Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -26453,8 +26476,9 @@ function Get-DbaConnection { .NOTES Tags: Connection - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -26546,6 +26570,7 @@ function Get-DbaCpuUsage { .NOTES Tags: CPU + Author: Chrissy LeMaire (@cl), netnerds.net dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) Copyright (C) 2016 Chrissy LeMaire License: MIT https://opensource.org/licenses/MIT @@ -27318,6 +27343,7 @@ Get specific certificate .NOTES Tags: Certificate +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -28436,6 +28462,7 @@ function Get-DbaDbMail { .NOTES Tags: databasemail, dbmail, mail + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -28523,9 +28550,10 @@ function Get-DbaDbMailAccount { .NOTES Tags: databasemail, dbmail, mail + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com - License: MIT https://opensource.org/licenses/MIT + License: MIT https://opensource.org/licenses/MITIT .LINK https://dbatools.io/Get-DbaDbMailAccount @@ -28626,6 +28654,7 @@ function Get-DbaDbMailConfig { .NOTES Tags: databasemail, dbmail, mail + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -28723,7 +28752,8 @@ function Get-DbaDbMailHistory { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Tags: Logging + Tags: databasemail, dbmail, mail + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -28867,7 +28897,8 @@ function Get-DbaDbMailLog { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Tags: Logging + Tags: databasemail, dbmail, mail + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -28997,6 +29028,7 @@ function Get-DbaDbMailProfile { .NOTES Tags: databasemail, dbmail, mail + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -29105,6 +29137,7 @@ function Get-DbaDbMailServer { .NOTES Tags: databasemail, dbmail, mail + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -29212,7 +29245,7 @@ Prompts you for confirmation before executing any changing operations within the .NOTES Tags: Certificate, Database - +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -29320,6 +29353,7 @@ function Get-DbaDbPageInfo { .NOTES Tags: Database, Page + Author: Chrissy LeMaire (@cl), netnerds.net dbatools PowerShell module (https://dbatools.io) Copyright (C) 2016 Chrissy LeMaire License: MIT https://opensource.org/licenses/MIT @@ -30813,7 +30847,7 @@ Using this switch turns this "nice by default" feature off and enables you to ca .NOTES Tags: Database, Trigger - +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -31275,7 +31309,7 @@ function Get-DbaDbVirtualLogFile { .NOTES Tags: VLF, Database, LogFile - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -31389,6 +31423,7 @@ function Get-DbaDefaultPath { .NOTES Tags: Config + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -31511,6 +31546,7 @@ function Get-DbaDependency { .NOTES Tags: Database, Dependent, Dependency, Object dbatools PowerShell module (https://dbatools.io) + Author: Chrissy LeMaire (@cl), netnerds.net Copyright (C) 2016 Chrissy LeMaire License: MIT https://opensource.org/licenses/MIT @@ -31746,7 +31782,7 @@ function Get-DbaDetachedDatabaseInfo { .NOTES Tags: Database, Detach - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -32273,6 +32309,7 @@ function Get-DbaErrorLog { .NOTES Tags: Instance, ErrorLog + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -32498,6 +32535,7 @@ The database(s) to exclude - this list is auto-populated from the server .NOTES Tags: Database +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -32616,7 +32654,7 @@ function Get-DbaExecutionPlan { Gets execution plans and metadata .DESCRIPTION -Gets execution plans and metadata. Can pipe to Export-DbaExecutionPlan :D +Gets execution plans and metadata. Can pipe to Export-DbaExecutionPlan Thanks to https://www.simple-talk.com/sql/t-sql-programming/dmvs-for-query-plan-metadata/ @@ -32656,8 +32694,9 @@ Returns a ton of raw information about the execution plans .NOTES Tags: Performance -dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) -Copyright (C) 2016 Chrissy LeMaire +Author: Chrissy LeMaire (@cl), netnerds.net +Website: https://dbatools.io +Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -32700,16 +32739,6 @@ Gets super detailed information for execution plans on only for AdventureWorks20 [switch]$EnableException ) - begin { - - if ($SinceCreation -ne $null) { - $SinceCreation = $SinceCreation.ToString("yyyy-MM-dd HH:mm:ss") - } - - if ($SinceLastExecution -ne $null) { - $SinceLastExecution = $SinceLastExecution.ToString("yyyy-MM-dd HH:mm:ss") - } - } process { foreach ($instance in $sqlinstance) { @@ -32743,7 +32772,7 @@ Gets super detailed information for execution plans on only for AdventureWorks20 CROSS APPLY sys.dm_exec_query_plan(deqs.plan_handle) AS deqp CROSS APPLY sys.dm_exec_sql_text(deqs.plan_handle) AS execText" - if ($ExcludeDatabase -or $Database -or $SinceCreation.length -gt 0 -or $SinceLastExecution.length -gt 0 -or $ExcludeEmptyQueryPlan -eq $true) { + if ($ExcludeDatabase -or $Database -or $SinceCreation -or $SinceLastExecution -or $ExcludeEmptyQueryPlan -eq $true) { $where = " WHERE " } @@ -32756,12 +32785,12 @@ Gets super detailed information for execution plans on only for AdventureWorks20 if ($null -ne $SinceCreation) { Write-Message -Level Verbose -Message "Adding creation time" - $wherearray += " creation_time >= '$SinceCreation' " + $wherearray += " creation_time >= '" + $SinceCreation.ToString("yyyy-MM-dd HH:mm:ss") + "' " } if ($null -ne $SinceLastExecution) { Write-Message -Level Verbose -Message "Adding last exectuion time" - $wherearray += " last_execution_time >= '$SinceLastExecution' " + $wherearray += " last_execution_time >= '" + $SinceLastExecution.ToString("yyyy-MM-dd HH:mm:ss") + "' " } if ($ExcludeDatabase) { @@ -32872,7 +32901,7 @@ function Get-DbaFeature { .NOTES Tags: Feature, Component - Author: Chrissy LeMaire (@cl) + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -33209,7 +33238,7 @@ function Get-DbaForceNetworkEncryption { .NOTES Tags: Certificate - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -36081,8 +36110,9 @@ function Get-DbaMaxMemory { .NOTES Tags: MaxMemory, Memory - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -36785,7 +36815,7 @@ Allows you to login to $ComputerName using alternative credentials. .NOTES Tags: Certificate - +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -36918,6 +36948,7 @@ function Get-DbaOpenTransaction { .NOTES Tags: Database, Process, Session, ActivityMonitor + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -37020,7 +37051,7 @@ function Get-DbaOperatingSystem { Tags: ServerInfo, OperatingSystem Author: Shawn Melton (@wsmelton | http://blog.wsmelton.info) - Website: https: //dbatools.io + Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -37422,7 +37453,7 @@ function Get-DbaPbmCategory { .NOTES Tags: Policy, PoilcyBasedManagement, PBM - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -37501,7 +37532,7 @@ function Get-DbaPbmCategorySubscription { .NOTES Tags: Policy, PoilcyBasedManagement, PBM - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -37577,7 +37608,7 @@ function Get-DbaPbmCondition { .NOTES Tags: Policy, PoilcyBasedManagement, PBM - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -37663,7 +37694,7 @@ function Get-DbaPbmObjectSet { .NOTES Tags: Policy, PoilcyBasedManagement, PBM - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -37853,7 +37884,7 @@ function Get-DbaPbmStore { .NOTES Tags: Policy, PoilcyBasedManagement, PBM - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -38184,6 +38215,7 @@ function Get-DbaPfAvailableCounter { .NOTES Tags: Performance, DataCollector, PerfCounter + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -38291,8 +38323,8 @@ function Get-DbaPfDataCollector { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Tags: PerfMon - + Tags: Performance, DataCollector, PerfCounter + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -38431,8 +38463,8 @@ function Get-DbaPfDataCollectorCounter { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Tags: PerfMon - + Tags: Performance, DataCollector, PerfCounter + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -38564,8 +38596,8 @@ function Get-DbaPfDataCollectorCounterSample { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Tags: PerfMon - + Tags: Performance, DataCollector, PerfCounter + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -38738,8 +38770,8 @@ function Get-DbaPfDataCollectorSet { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Tags: PerfMon - + Tags: Performance, DataCollector, PerfCounter + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -38927,6 +38959,7 @@ function Get-DbaPfDataCollectorSetTemplate { .NOTES Tags: Performance, DataCollector, PerfCounter + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -40288,6 +40321,7 @@ function Get-DbaRegisteredServerStore { .NOTES Tags: RegisteredServer,CMS + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -40359,7 +40393,7 @@ Allows you to login to $ComputerName using alternative Windows credentials .NOTES Tags: Configuration, Registry - +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -40657,6 +40691,7 @@ Using this switch turns this "nice by default" feature off and enables you to ca .NOTES Tags: ResourceGovernor +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -41016,6 +41051,7 @@ Using this switch turns this "nice by default" feature off and enables you to ca .NOTES Tags: ResourceGovernor +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -41103,6 +41139,7 @@ Using this switch turns this "nice by default" feature off and enables you to ca .NOTES Tags: ResourceGovernor +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -41965,7 +42002,7 @@ function Get-DbaServerRole { Tags: ServerRole, Security Original Author: Shawn Melton (@wsmelton) - Website: https: //dbatools.io + Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -42050,6 +42087,7 @@ Using this switch turns this "nice by default" feature off and enables you to ca .NOTES Tags: Database, Trigger +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -43145,8 +43183,9 @@ function Get-DbaStartupParameter { .NOTES Tags: WSMan, SQLWMI, Memory - dbatools PowerShell module (https://dbatools.io) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -43436,11 +43475,12 @@ function Get-DbaTcpPort { .NOTES Tags: SQLWMI, tcp - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT + .LINK https://dbatools.io/Get-DbaTcpPort @@ -43629,8 +43669,9 @@ function Get-DbaTempdbUsage { .NOTES Tags: Tempdb, Space - dbatools PowerShell module (https://dbatools.io) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -44031,6 +44072,7 @@ function Get-DbaTopResourceUsage { .NOTES Tags: Query, Performance + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -45278,6 +45320,7 @@ function Get-DbaWaitStatistic { .NOTES Tags: WaitStatistic + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -46479,6 +46522,7 @@ function Get-DbaXEObject { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -46705,6 +46749,7 @@ function Get-DbaXESessionTarget { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -46834,6 +46879,7 @@ function Get-DbaXESessionTargetFile { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -46926,6 +46972,7 @@ function Get-DbaXESessionTemplate { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -47043,6 +47090,7 @@ function Get-DbaXESmartTarget { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -47092,6 +47140,7 @@ function Get-DbaXEStore { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -48574,6 +48623,7 @@ function Import-DbaPfDataCollectorSetTemplate { .NOTES Tags: Performance, DataCollector, PerfCounter + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -48826,7 +48876,7 @@ function Import-DbaRegisteredServer { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Author: Chrissy LeMaire (@cl) + Author: Chrissy LeMaire (@cl), netnerds.net Tags: RegisteredServer, CMS Website: https://dbatools.io @@ -48988,7 +49038,8 @@ function Import-DbaSpConfigure { If this switch is enabled, you will be prompted for confirmation before executing any operations that change state. .NOTES - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) + Tags: sp_configure + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -49182,6 +49233,7 @@ function Import-DbaXESessionTemplate { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -50002,6 +50054,7 @@ function Install-DbaWatchUpdate { .NOTES Tags: Module + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -50139,6 +50192,8 @@ function Install-DbaWhoIsActive { Install-DbaWhoIsActive -SqlInstance $instances -Database master .NOTES + Tags: AdamMechanic, WhoIsActive, SpWhoIsActive + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -51853,7 +51908,7 @@ function Invoke-DbaDbShrink { .NOTES Tags: Shrink, Database - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -53265,7 +53320,7 @@ function Invoke-DbaLogShipping { [parameter(Mandatory)] [ValidateNotNullOrEmpty()] [Alias("DestinationServerInstance", "DestinationSqlServer", "Destination")] - [object]$DestinationSqlInstance, + [object[]]$DestinationSqlInstance, [Parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] @@ -53522,10 +53577,10 @@ function Invoke-DbaLogShipping { ) begin { - Write-Message -Message "Started log shipping for $SourceSqlInstance to $DestinationSqlInstance" -Level Output + Write-Message -Message "Started log shipping for $SourceSqlInstance to $DestinationSqlInstance" -Level Verbose # Try connecting to the instance - Write-Message -Message "Connecting to source Sql Server $SourceSqlInstance.." -Level Output + Write-Message -Message "Connecting to source Sql Server $SourceSqlInstance.." -Level Verbose try { $SourceServer = Connect-SqlInstance -SqlInstance $SourceSqlInstance -SqlCredential $SourceSqlCredential } @@ -53534,49 +53589,26 @@ function Invoke-DbaLogShipping { return } - # Try connecting to the instance - Write-Message -Message "Connecting to destination Sql Server $DestinationSqlInstance.." -Level Output - try { - $DestinationServer = Connect-SqlInstance -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationSqlCredential - } - catch { - Stop-Function -Message "Could not connect to Sql Server instance $DestinationSqlInstance" -ErrorRecord $_ -Target $DestinationSqlInstance - return - } # Check the instance if it is a named instance $SourceServerName, $SourceInstanceName = $SourceSqlInstance.Split("\") - $DestinationServerName, $DestinationInstanceName = $DestinationSqlInstance.Split("\") - if ($SourceInstanceName -eq $null) { + if ($null -eq $SourceInstanceName) { $SourceInstanceName = "MSSQLSERVER" } - if ($DestinationInstanceName -eq $null) { - $DestinationInstanceName = "MSSQLSERVER" - } - $IsSourceLocal = $false - $IsDestinationLocal = $false # Check if it's local or remote if ($SourceServerName -in ".", "localhost", $env:ServerName, "127.0.0.1") { $IsSourceLocal = $true } - if ($DestinationServerName -in ".", "localhost", $env:ServerName, "127.0.0.1") { - $IsDestinationLocal = $true - } # Set up regex strings for several checks $RegexDate = '(?:`"/\\|?*]+)+$' - # Check the instance names and the database settings - if (($SourceSqlInstance -eq $DestinationSqlInstance) -and (-not $SecondaryDatabasePrefix -or $SecondaryDatabaseSuffix)) { - Stop-Function -Message "The destination database is the same as the source`nPlease enter a prefix or suffix using -SecondaryDatabasePrefix or -SecondaryDatabaseSuffix." -Target $SourceSqlInstance - return - } # Check the connection timeout if ($SourceServer.ConnectionContext.StatementTimeout -ne 0) { @@ -53584,11 +53616,6 @@ function Invoke-DbaLogShipping { Write-Message -Message "Connection timeout of $SourceServer is set to 0" -Level Verbose } - if ($DestinationServer.ConnectionContext.StatementTimeout -ne 0) { - $DestinationServer.ConnectionContext.StatementTimeout = 0 - Write-Message -Message "Connection timeout of $DestinationServer is set to 0" -Level Verbose - } - # Check the backup network path Write-Message -Message "Testing backup network path $BackupNetworkPath" -Level Verbose if ((Test-DbaPath -Path $BackupNetworkPath -SqlInstance $SourceSqlInstance -SqlCredential $SourceCredential) -ne $true) { @@ -53600,89 +53627,6 @@ function Invoke-DbaLogShipping { return } - # Check the copy destination - if (-not $CopyDestinationFolder) { - # Make a default copy destination by retrieving the backup folder and adding a directory - $CopyDestinationFolder = "$($DestinationServer.Settings.BackupDirectory)\Logshipping" - - # Check to see if the path already exists - Write-Message -Message "Testing copy destination path $CopyDestinationFolder" -Level Verbose - if (Test-DbaPath -Path $CopyDestinationFolder -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationCredential) { - Write-Message -Message "Copy destination $CopyDestinationFolder already exists" -Level Verbose - } - else { - # Check if force is being used - if (-not $Force) { - # Set up the confirm part - $message = "The copy destination is missing. Do you want to use the default $($CopyDestinationFolder)?" - $choiceYes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Answer Yes." - $choiceNo = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Answer No." - $options = [System.Management.Automation.Host.ChoiceDescription[]]($choiceYes, $choiceNo) - $result = $host.ui.PromptForChoice($title, $message, $options, 0) - - # Check the result from the confirm - switch ($result) { - # If yes - 0 { - # Try to create the new directory - try { - # If the destination server is remote and the credential is set - 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 - } - } - # 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 - } - } - # 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 - } - Write-Message -Message "Copy destination $CopyDestinationFolder created." -Level Verbose - } - catch { - Stop-Function -Message "Something went wrong creating the copy destination folder $CopyDestinationFolder. `n$_" -Target $DestinationSqlInstance -ErrorRecord $_ - return - } - } - 1 { - Stop-Function -Message "Copy destination is a mandatory parameter. Please make sure the value is entered." -Target $DestinationSqlInstance - return - } - } # switch - } # if not force - else { - # 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 - Write-Message -Message "Copy destination $CopyDestinationFolder created." -Level Verbose - } - catch { - Stop-Function -Message "Something went wrong creating the copy destination folder $CopyDestinationFolder. `n$_" -Target $DestinationSqlInstance -ErrorRecord $_ - return - } - } # else not force - } # if test path copy destination - } # if not copy destination - - Write-Message -Message "Testing copy destination path $CopyDestinationFolder" -Level Verbose - if ((Test-DbaPath -Path $CopyDestinationFolder -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationCredential) -ne $true) { - Stop-Function -Message "Copy destination folder $CopyDestinationFolder is not valid or can't be reached." -Target $DestinationSqlInstance - return - } - elseif ($CopyDestinationFolder.StartsWith("\\") -and $CopyDestinationFolder -notmatch $RegexUnc) { - Stop-Function -Message "Copy destination folder $CopyDestinationFolder has to be in the form of \\server\share." -Target $DestinationSqlInstance - return - } - # Check the backup compression if ($SourceServer.Version.Major -gt 9) { if ($CompressBackup) { @@ -53836,15 +53780,6 @@ function Invoke-DbaLogShipping { $RestoreScheduleFrequencyRecurrenceFactor = 0 Write-Message -Message "Restore frequency recurrence factor set to $RestoreScheduleFrequencyRecurrenceFactor" -Level Verbose } - if (-not ($SecondaryDatabasePrefix -or $SecondaryDatabaseSuffix) -and ($SourceServer.Name -eq $DestinationServer.Name) -and ($SourceServer.InstanceName -eq $DestinationServer.InstanceName)) { - if ($Force) { - $SecondaryDatabaseSuffix = "_LS" - } - else { - Stop-Function -Message "Destination database is the same as source database.`nPlease check the secondary server, database prefix or suffix or use -Force to set the secondary databse using a suffix." -Target $SourceSqlInstance - return - } - } # Checking for contradicting variables if ($NoInitialization -and ($GenerateFullBackup -or $UseExistingFullBackup)) { @@ -54009,143 +53944,68 @@ function Invoke-DbaLogShipping { Stop-Function -Message "Restore end time $RestoreScheduleEndTime needs to match between '000000' and '235959'" -Target $SourceSqlInstance return } - - # Check if standby is being used - if ($Standby) { - - # Check the stand-by directory - if ($StandbyDirectory) { - # Check if the path is reachable for the destination server - if ((Test-DbaPath -Path $StandbyDirectory -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationCredential) -ne $true) { - Stop-Function -Message "The directory $StandbyDirectory cannot be reached by the destination instance. Please check the permission and credentials." -Target $DestinationSqlInstance - return - } - } - elseif (-not $StandbyDirectory -and $Force) { - $StandbyDirectory = $DestinationSqlInstance.BackupDirectory - Write-Message -Message "Stand-by directory was not set. Setting it to $StandbyDirectory" -Level Verbose - } - else { - Stop-Function -Message "Please set the parameter -StandbyDirectory when using -Standby" -Target $SourceSqlInstance - return - } - } - } # begin + } process { if (Test-FunctionInterrupt) { return } - # Loop through each of the databases - foreach ($db in $DatabaseCollection) { + foreach($destInstance in $DestinationSqlInstance){ - # Check the status of the database - if ($db.RecoveryModel -ne 'Full') { - Stop-Function -Message "Database $db is not in FULL recovery mode" -Target $SourceSqlInstance -Continue - } + $setupResult = "Success" + $comment = "" - # Set the intital destination database - $SecondaryDatabase = $db.Name - - # Set the database prefix - if ($SecondaryDatabasePrefix) { - $SecondaryDatabase = "$SecondaryDatabasePrefix$($db.Name)" + # Try connecting to the instance + Write-Message -Message "Connecting to destination Sql Server $destInstance.." -Level Verbose + try { + $DestinationServer = Connect-SqlInstance -SqlInstance $destInstance -SqlCredential $DestinationSqlCredential } - - # Set the database suffix - if ($SecondaryDatabaseSuffix) { - $SecondaryDatabase += $SecondaryDatabaseSuffix + catch { + Stop-Function -Message "Could not connect to Sql Server instance $destInstance" -ErrorRecord $_ -Target $destInstance + return } - # Check is the database is already initialized an check if the database exists on the secondary instance - if ($NoInitialization -and ($DestinationServer.Databases.Name -notcontains $SecondaryDatabase)) { - Stop-Function -Message "Database $SecondaryDatabase needs to be initialized before log shipping setting can continue." -Target $SourceSqlInstance -Continue - } + $DestinationServerName, $DestinationInstanceName = $destInstance.Split("\") - # Check the local backup path - if ($BackupLocalPath) { - if ($BackupLocalPath.EndsWith("\")) { - $DatabaseBackupLocalPath = "$BackupLocalPath$($db.Name)" - } - else { - $DatabaseBackupLocalPath = "$BackupLocalPath\$($db.Name)" - } + if ($null -eq $DestinationInstanceName) { + $DestinationInstanceName = "MSSQLSERVER" } - else { - $BackupLocalPath = $BackupNetworkPath - if ($BackupLocalPath.EndsWith("\")) { - $DatabaseBackupLocalPath = "$BackupLocalPath$($db.Name)" - } - else { - $DatabaseBackupLocalPath = "$BackupLocalPath\$($db.Name)" - } - } - Write-Message -Message "Backup local path set to $DatabaseBackupLocalPath." -Level Verbose + $IsDestinationLocal = $false - # Setting the backup network path for the database - if ($BackupNetworkPath.EndsWith("\")) { - $DatabaseBackupNetworkPath = "$BackupNetworkPath$($db.Name)" + # Check if it's local or remote + if ($DestinationServerName -in ".", "localhost", $env:ServerName, "127.0.0.1") { + $IsDestinationLocal = $true } - else { - $DatabaseBackupNetworkPath = "$BackupNetworkPath\$($db.Name)" - } - Write-Message -Message "Backup network path set to $DatabaseBackupNetworkPath." -Level Verbose - - # Checking if the database network path exists - Write-Message -Message "Testing database backup network path $DatabaseBackupNetworkPath" -Level Verbose - if ((Test-DbaPath -Path $DatabaseBackupNetworkPath -SqlInstance $SourceSqlInstance -SqlCredential $SourceCredential) -ne $true) { - # To to create the backup directory for the database - try { - Write-Message -Message "Database backup network path $DatabaseBackupNetworkPath not found. Trying to create it.." -Level Verbose - - Invoke-Command2 -Credential $SourceCredential -ScriptBlock { - Write-Message -Message "Creating backup folder $DatabaseBackupNetworkPath" -Level Verbose - New-Item -Path $DatabaseBackupNetworkPath -ItemType Directory -Credential $SourceCredential -Force:$Force | Out-Null - } - } - catch { - Stop-Function -Message "Something went wrong creating the directory" -ErrorRecord $_ -Target $SourceSqlInstance -Continue - } + # Check the instance names and the database settings + if (($SourceSqlInstance -eq $destInstance) -and (-not $SecondaryDatabasePrefix -or $SecondaryDatabaseSuffix)) { + $setupResult = "Failed" + $comment = "The destination database is the same as the source" + Stop-Function -Message "The destination database is the same as the source`nPlease enter a prefix or suffix using -SecondaryDatabasePrefix or -SecondaryDatabaseSuffix." -Target $SourceSqlInstance + return } - # Check if the backup job name is set - if ($BackupJob) { - $DatabaseBackupJob = "$BackupJob_$($db.Name)" - } - else { - $DatabaseBackupJob = "LSBackup_$($db.Name)" + if ($DestinationServer.ConnectionContext.StatementTimeout -ne 0) { + $DestinationServer.ConnectionContext.StatementTimeout = 0 + Write-Message -Message "Connection timeout of $DestinationServer is set to 0" -Level Verbose } - Write-Message -Message "Backup job name set to $DatabaseBackupJob" -Level Verbose - # Check if the backup job schedule name is set - if ($BackupSchedule) { - $DatabaseBackupSchedule = "$BackupSchedule_$($db.Name)" - } - else { - $DatabaseBackupSchedule = "LSBackupSchedule_$($db.Name)" - } - Write-Message -Message "Backup job schedule name set to $DatabaseBackupSchedule" -Level Verbose - - # Check if secondary database is present on secondary instance - if (-not $Force -and -not $NoInitialization -and ($DestinationServer.Databases[$SecondaryDatabase].Status -ne 'Restoring') -and ($DestinationServer.Databases.Name -contains $SecondaryDatabase)) { - Stop-Function -Message "Secondary database already exists on instance $DestinationSqlInstance." -ErrorRecord $_ -Target $DestinationSqlInstance -Continue - } + # Check the copy destination + if (-not $CopyDestinationFolder) { + # Make a default copy destination by retrieving the backup folder and adding a directory + $CopyDestinationFolder = "$($DestinationServer.Settings.BackupDirectory)\Logshipping" - # Check if the secondary database needs tobe initialized - if (-not $NoInitialization) { - # Check if the secondary database exists on the secondary instance - if ($DestiationServer.Databases.Name -notcontains $SecondaryDatabase) { - # Check if force is being used and no option to generate the full backup is set - if ($Force -and -not ($GenerateFullBackup -or $UseExistingFullBackup)) { - # Set the option to generate a full backup - Write-Message -Message "Set option to initialize secondary database with full backup" -Level Verbose - $GenerateFullBackup = $true - } - elseif (-not $Force -and -not $GenerateFullBackup -and -not $UseExistingFullBackup -and -not $UseBackupFolder) { + # Check to see if the path already exists + Write-Message -Message "Testing copy destination path $CopyDestinationFolder" -Level Verbose + if (Test-DbaPath -Path $CopyDestinationFolder -SqlInstance $destInstance -SqlCredential $DestinationCredential) { + Write-Message -Message "Copy destination $CopyDestinationFolder already exists" -Level Verbose + } + else { + # Check if force is being used + if (-not $Force) { # Set up the confirm part - $message = "The database $SecondaryDatabase does not exist on instance $DestinationSqlInstance. `nDo you want to initialize it by generating a full backup?" + $message = "The copy destination is missing. Do you want to use the default $($CopyDestinationFolder)?" $choiceYes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Answer Yes." $choiceNo = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Answer No." $options = [System.Management.Automation.Host.ChoiceDescription[]]($choiceYes, $choiceNo) @@ -54155,507 +54015,804 @@ function Invoke-DbaLogShipping { switch ($result) { # If yes 0 { - # Set the option to generate a full backup - Write-Message -Message "Set option to initialize secondary database with full backup." -Level Verbose - $GenerateFullBackup = $true + # Try to create the new directory + try { + # If the destination server is remote and the credential is set + 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 + } + } + # 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 + } + } + # 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 + } + Write-Message -Message "Copy destination $CopyDestinationFolder created." -Level Verbose + } + catch { + $setupResult = "Failed" + $comment = "Something went wrong creating the copy destination folder" + Stop-Function -Message "Something went wrong creating the copy destination folder $CopyDestinationFolder. `n$_" -Target $destInstance -ErrorRecord $_ + return + } } 1 { - Stop-Function -Message "The database is not initialized on the secondary instance. `nPlease initialize the database on the secondary instance, use -GenerateFullbackup or use -Force." -Target $DestinationSqlInstance + $setupResult = "Failed" + $comment = "Copy destination is a mandatory parameter" + Stop-Function -Message "Copy destination is a mandatory parameter. Please make sure the value is entered." -Target $destInstance return } } # switch + } # if not force + else { + # 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 + Write-Message -Message "Copy destination $CopyDestinationFolder created." -Level Verbose + } + catch { + $setupResult = "Failed" + $comment = "Something went wrong creating the copy destination folder" + Stop-Function -Message "Something went wrong creating the copy destination folder $CopyDestinationFolder. `n$_" -Target $destInstance -ErrorRecord $_ + return + } + } # else not force + } # if test path copy destination + } # if not copy destination + + Write-Message -Message "Testing copy destination path $CopyDestinationFolder" -Level Verbose + if ((Test-DbaPath -Path $CopyDestinationFolder -SqlInstance $destInstance -SqlCredential $DestinationCredential) -ne $true) { + $setupResult = "Failed" + $comment = "Copy destination folder $CopyDestinationFolder is not valid or can't be reached" + Stop-Function -Message "Copy destination folder $CopyDestinationFolder is not valid or can't be reached." -Target $destInstance + return + } + elseif ($CopyDestinationFolder.StartsWith("\\") -and $CopyDestinationFolder -notmatch $RegexUnc) { + $setupResult = "Failed" + $comment = "Copy destination folder $CopyDestinationFolder has to be in the form of \\server\share" + Stop-Function -Message "Copy destination folder $CopyDestinationFolder has to be in the form of \\server\share." -Target $destInstance + return + } + + if (-not ($SecondaryDatabasePrefix -or $SecondaryDatabaseSuffix) -and ($SourceServer.Name -eq $DestinationServer.Name) -and ($SourceServer.InstanceName -eq $DestinationServer.InstanceName)) { + if ($Force) { + $SecondaryDatabaseSuffix = "_LS" + } + else { + $setupResult = "Failed" + $comment = "Destination database is the same as source database" + Stop-Function -Message "Destination database is the same as source database.`nPlease check the secondary server, database prefix or suffix or use -Force to set the secondary databse using a suffix." -Target $SourceSqlInstance + return + } + } + + # Check if standby is being used + if ($Standby) { + # Check the stand-by directory + if ($StandbyDirectory) { + # Check if the path is reachable for the destination server + if ((Test-DbaPath -Path $StandbyDirectory -SqlInstance $destInstance -SqlCredential $DestinationCredential) -ne $true) { + $setupResult = "Failed" + $comment = "The directory $StandbyDirectory cannot be reached by the destination instance" + Stop-Function -Message "The directory $StandbyDirectory cannot be reached by the destination instance. Please check the permission and credentials." -Target $destInstance + return } } + elseif (-not $StandbyDirectory -and $Force) { + $StandbyDirectory = $destInstance.BackupDirectory + Write-Message -Message "Stand-by directory was not set. Setting it to $StandbyDirectory" -Level Verbose + } + else { + $setupResult = "Failed" + $comment = "Please set the parameter -StandbyDirectory when using -Standby" + Stop-Function -Message "Please set the parameter -StandbyDirectory when using -Standby" -Target $SourceSqlInstance + return + } } + # Loop through each of the databases + foreach ($db in $DatabaseCollection) { + + # Check the status of the database + if ($db.RecoveryModel -ne 'Full') { + $setupResult = "Failed" + $comment = "Database $db is not in FULL recovery mode" + + Stop-Function -Message "Database $db is not in FULL recovery mode" -Target $SourceSqlInstance -Continue + } + + # Set the intital destination database + $SecondaryDatabase = $db.Name - # Check the parameters for initialization of the secondary database - if (-not $NoInitialization -and ($GenerateFullBackup -or $UseExistingFullBackup -or $UseBackupFolder)) { - # Check if the restore data and log folder are set - if (-not $RestoreDataFolder -or -not $RestoreLogFolder) { - Write-Message -Message "Restore data folder or restore log folder are not set. Using server defaults" -Level Verbose + # Set the database prefix + if ($SecondaryDatabasePrefix) { + $SecondaryDatabase = "$SecondaryDatabasePrefix$($db.Name)" + } + + # Set the database suffix + if ($SecondaryDatabaseSuffix) { + $SecondaryDatabase += $SecondaryDatabaseSuffix + } - # Get the default data folder - if (-not $RestoreDataFolder) { - $DatabaseRestoreDataFolder = $DestinationServer.DefaultFile + # Check is the database is already initialized an check if the database exists on the secondary instance + if ($NoInitialization -and ($DestinationServer.Databases.Name -notcontains $SecondaryDatabase)) { + $setupResult = "Failed" + $comment = "Database $SecondaryDatabase needs to be initialized before log shipping setting can continue" + + Stop-Function -Message "Database $SecondaryDatabase needs to be initialized before log shipping setting can continue." -Target $SourceSqlInstance -Continue + } + + # Check the local backup path + if ($BackupLocalPath) { + if ($BackupLocalPath.EndsWith("\")) { + $DatabaseBackupLocalPath = "$BackupLocalPath$($db.Name)" + } + else { + $DatabaseBackupLocalPath = "$BackupLocalPath\$($db.Name)" + } + } + else { + $BackupLocalPath = $BackupNetworkPath + + if ($BackupLocalPath.EndsWith("\")) { + $DatabaseBackupLocalPath = "$BackupLocalPath$($db.Name)" } else { - # Set the restore data folder - if ($RestoreDataFolder.EndsWith("\")) { - $DatabaseRestoreDataFolder = "$RestoreDataFolder$($db.Name)" + $DatabaseBackupLocalPath = "$BackupLocalPath\$($db.Name)" + } + } + Write-Message -Message "Backup local path set to $DatabaseBackupLocalPath." -Level Verbose + + # Setting the backup network path for the database + if ($BackupNetworkPath.EndsWith("\")) { + $DatabaseBackupNetworkPath = "$BackupNetworkPath$($db.Name)" + } + else { + $DatabaseBackupNetworkPath = "$BackupNetworkPath\$($db.Name)" + } + Write-Message -Message "Backup network path set to $DatabaseBackupNetworkPath." -Level Verbose + + + # Checking if the database network path exists + if($setupResult -ne 'Failed'){ + Write-Message -Message "Testing database backup network path $DatabaseBackupNetworkPath" -Level Verbose + if ((Test-DbaPath -Path $DatabaseBackupNetworkPath -SqlInstance $SourceSqlInstance -SqlCredential $SourceCredential) -ne $true) { + # To to create the backup directory for the database + try { + Write-Message -Message "Database backup network path $DatabaseBackupNetworkPath not found. Trying to create it.." -Level Verbose + + Invoke-Command2 -Credential $SourceCredential -ScriptBlock { + Write-Message -Message "Creating backup folder $DatabaseBackupNetworkPath" -Level Verbose + $null = New-Item -Path $DatabaseBackupNetworkPath -ItemType Directory -Credential $SourceCredential -Force:$Force + } } - else { - $DatabaseRestoreDataFolder = "$RestoreDataFolder\$($db.Name)" + catch { + $setupResult = "Failed" + $comment = "Something went wrong creating the backup directory" + + Stop-Function -Message "Something went wrong creating the backup directory" -ErrorRecord $_ -Target $SourceSqlInstance -Continue } } + } - Write-Message -Message "Restore data folder set to $DatabaseRestoreDataFolder" -Level Verbose + # Check if the backup job name is set + if ($BackupJob) { + $DatabaseBackupJob = "$BackupJob_$($db.Name)" + } + else { + $DatabaseBackupJob = "LSBackup_$($db.Name)" + } + Write-Message -Message "Backup job name set to $DatabaseBackupJob" -Level Verbose - # Get the default log folder - if (-not $RestoreLogFolder) { - $DatabaseRestoreLogFolder = $DestinationServer.DefaultLog - } + # Check if the backup job schedule name is set + if ($BackupSchedule) { + $DatabaseBackupSchedule = "$BackupSchedule_$($db.Name)" + } + else { + $DatabaseBackupSchedule = "LSBackupSchedule_$($db.Name)" + } + Write-Message -Message "Backup job schedule name set to $DatabaseBackupSchedule" -Level Verbose - Write-Message -Message "Restore log folder set to $DatabaseRestoreLogFolder" -Level Verbose + # Check if secondary database is present on secondary instance + if (-not $Force -and -not $NoInitialization -and ($DestinationServer.Databases[$SecondaryDatabase].Status -ne 'Restoring') -and ($DestinationServer.Databases.Name -contains $SecondaryDatabase)) { + $setupResult = "Failed" + $comment = "Secondary database already exists on instance" - # Check if the restore data folder exists - Write-Message -Message "Testing database restore data path $DatabaseRestoreDataFolder" -Level Verbose - if ((Test-DbaPath -Path $DatabaseRestoreDataFolder -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationCredential) -ne $true) { - if ($PSCmdlet.ShouldProcess($DestinationServerName, "Creating database restore data folder $DatabaseRestoreDataFolder on $DestinationServerName")) { - # Try creating the data folder - try { - Invoke-Command2 -Credential $DestinationCredential -ScriptBlock { - Write-Message -Message "Creating data folder $DatabaseRestoreDataFolder" -Level Verbose - New-Item -Path $DatabaseRestoreDataFolder -ItemType Directory -Credential $DestinationCredential -Force:$Force | Out-Null - } + Stop-Function -Message "Secondary database already exists on instance $destInstance." -ErrorRecord $_ -Target $destInstance -Continue + } + + # Check if the secondary database needs tobe initialized + if($setupResult -ne 'Failed'){ + if (-not $NoInitialization) { + # Check if the secondary database exists on the secondary instance + if ($DestiationServer.Databases.Name -notcontains $SecondaryDatabase) { + # Check if force is being used and no option to generate the full backup is set + if ($Force -and -not ($GenerateFullBackup -or $UseExistingFullBackup)) { + # Set the option to generate a full backup + Write-Message -Message "Set option to initialize secondary database with full backup" -Level Verbose + $GenerateFullBackup = $true } - catch { - Stop-Function -Message "Something went wrong creating the restore data directory" -ErrorRecord $_ -Target $SourceSqlInstance -Continue + elseif (-not $Force -and -not $GenerateFullBackup -and -not $UseExistingFullBackup -and -not $UseBackupFolder) { + # Set up the confirm part + $message = "The database $SecondaryDatabase does not exist on instance $destInstance. `nDo you want to initialize it by generating a full backup?" + $choiceYes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Answer Yes." + $choiceNo = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Answer No." + $options = [System.Management.Automation.Host.ChoiceDescription[]]($choiceYes, $choiceNo) + $result = $host.ui.PromptForChoice($title, $message, $options, 0) + + # Check the result from the confirm + switch ($result) { + # If yes + 0 { + # Set the option to generate a full backup + Write-Message -Message "Set option to initialize secondary database with full backup." -Level Verbose + $GenerateFullBackup = $true + } + 1 { + $setupResult = "Failed" + $comment = "The database is not initialized on the secondary instance" + + Stop-Function -Message "The database is not initialized on the secondary instance. `nPlease initialize the database on the secondary instance, use -GenerateFullbackup or use -Force." -Target $destInstance + return + } + } # switch } } } + } - # Check if the restore log folder exists - Write-Message -Message "Testing database restore log path $DatabaseRestoreLogFolder" -Level Verbose - if ((Test-DbaPath -Path $DatabaseRestoreLogFolder -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationCredential) -ne $true) { - if ($PSCmdlet.ShouldProcess($DestinationServerName, "Creating database restore log folder $DatabaseRestoreLogFolder on $DestinationServerName")) { - # Try creating the log folder - try { - Write-Message -Message "Restore log folder $DatabaseRestoreLogFolder not found. Trying to create it.." -Level Verbose - Invoke-Command2 -Credential $DestinationCredential -ScriptBlock { - Write-Message -Message "Restore log folder $DatabaseRestoreLogFolder not found. Trying to create it.." -Level Verbose - New-Item -Path $DatabaseRestoreLogFolder -ItemType Directory -Credential $DestinationCredential -Force:$Force | Out-Null + # Check the parameters for initialization of the secondary database + if (-not $NoInitialization -and ($GenerateFullBackup -or $UseExistingFullBackup -or $UseBackupFolder)) { + # Check if the restore data and log folder are set + if($setupResult -ne 'Failed'){ + if (-not $RestoreDataFolder -or -not $RestoreLogFolder) { + Write-Message -Message "Restore data folder or restore log folder are not set. Using server defaults" -Level Verbose + + # Get the default data folder + if (-not $RestoreDataFolder) { + $DatabaseRestoreDataFolder = $DestinationServer.DefaultFile + } + else { + # Set the restore data folder + if ($RestoreDataFolder.EndsWith("\")) { + $DatabaseRestoreDataFolder = "$RestoreDataFolder$($db.Name)" + } + else { + $DatabaseRestoreDataFolder = "$RestoreDataFolder\$($db.Name)" } } - catch { - Stop-Function -Message "Something went wrong creating the restore log directory" -ErrorRecord $_ -Target $SourceSqlInstance -Continue + + Write-Message -Message "Restore data folder set to $DatabaseRestoreDataFolder" -Level Verbose + + # Get the default log folder + if (-not $RestoreLogFolder) { + $DatabaseRestoreLogFolder = $DestinationServer.DefaultLog } - } - } - } - # Chech if the full backup patk can be reached - if ($FullBackupPath) { - Write-Message -Message "Testing full backup path $FullBackupPath" -Level Verbose - if ((Test-DbaPath -Path $FullBackupPath -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationCredential) -ne $true) { - Stop-Function -Message ("The path to the full backup could not be reached. Check the path and/or the crdential") -ErrorRecord $_ -Target $DestinationSqlInstance -Continue - } - } - elseif ($UseBackupFolder.Length -ge 1) { - Write-Message -Message "Testing backup folder $UseBackupFolder" -Level Verbose - if ((Test-DbaPath -Path $UseBackupFolder -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationCredential) -ne $true) { - Stop-Function -Message ("The path to the backup folder could not be reached. Check the path and/or the crdential") -ErrorRecord $_ -Target $DestinationSqlInstance -Continue - } + Write-Message -Message "Restore log folder set to $DatabaseRestoreLogFolder" -Level Verbose - $BackupPath = $UseBackupFolder - } - elseif ($UseExistingFullBackup) { - Write-Message -Message "No path to the full backup is set. Trying to retrieve the last full backup for $db from $SourceSqlInstance" -Level Verbose + # Check if the restore data folder exists + Write-Message -Message "Testing database restore data path $DatabaseRestoreDataFolder" -Level Verbose + if ((Test-DbaPath -Path $DatabaseRestoreDataFolder -SqlInstance $destInstance -SqlCredential $DestinationCredential) -ne $true) { + if ($PSCmdlet.ShouldProcess($DestinationServerName, "Creating database restore data folder $DatabaseRestoreDataFolder on $DestinationServerName")) { + # Try creating the data folder + 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 + } + } + catch { + $setupResult = "Failed" + $comment = "Something went wrong creating the restore data directory" + Stop-Function -Message "Something went wrong creating the restore data directory" -ErrorRecord $_ -Target $SourceSqlInstance -Continue + } + } + } - # Get the last full backup - $LastBackup = Get-DbaBackupHistory -SqlServer $SourceSqlInstance -Databases $($db.Name) -LastFull -Credential $SourceSqlCredential + # Check if the restore log folder exists + Write-Message -Message "Testing database restore log path $DatabaseRestoreLogFolder" -Level Verbose + if ((Test-DbaPath -Path $DatabaseRestoreLogFolder -SqlInstance $destInstance -SqlCredential $DestinationCredential) -ne $true) { + if ($PSCmdlet.ShouldProcess($DestinationServerName, "Creating database restore log folder $DatabaseRestoreLogFolder on $DestinationServerName")) { + # Try creating the log folder + try { + Write-Message -Message "Restore log folder $DatabaseRestoreLogFolder not found. Trying to create it.." -Level Verbose - # Check if there was a last backup - if ($LastBackup -ne $null) { - # Test the path to the backup - Write-Message -Message "Testing last backup path $(($LastBackup[-1]).Path[-1])" -Level Verbose - if ((Test-DbaPath -Path ($LastBackup[-1]).Path[-1] -SqlInstance $SourceSqlInstance -SqlCredential $SourceCredential) -ne $true) { - Stop-Function -Message "The full backup could not be found on $($LastBackup.Path). Check path and/or credentials" -ErrorRecord $_ -Target $DestinationSqlInstance -Continue + 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 + } + } + catch { + $setupResult = "Failed" + $comment = "Something went wrong creating the restore log directory" + Stop-Function -Message "Something went wrong creating the restore log directory" -ErrorRecord $_ -Target $SourceSqlInstance -Continue + } + } + } } - # Check if the source for the last full backup is remote and the backup is on a shared location - elseif (($LastBackup.Computername -ne $SourceServerName) -and (($LastBackup[-1]).Path[-1].StartsWith('\\') -eq $false)) { - Stop-Function -Message "The last full backup is not located on shared location. `n$($_.Exception.Message)" -ErrorRecord $_ -Target $DestinationSqlInstance -Continue + } + + # Check if the full backup path can be reached + if($setupResult -ne 'Failed'){ + if ($FullBackupPath) { + Write-Message -Message "Testing full backup path $FullBackupPath" -Level Verbose + if ((Test-DbaPath -Path $FullBackupPath -SqlInstance $destInstance -SqlCredential $DestinationCredential) -ne $true) { + $setupResult = "Failed" + $comment = "The path to the full backup could not be reached" + Stop-Function -Message ("The path to the full backup could not be reached. Check the path and/or the crdential") -ErrorRecord $_ -Target $destInstance -Continue + } } - else { - #$FullBackupPath = $LastBackup.Path - $BackupPath = $LastBackup.Path - Write-Message -Message "Full backup found for $db. Path $BackupPath" -Level Verbose + elseif ($UseBackupFolder.Length -ge 1) { + Write-Message -Message "Testing backup folder $UseBackupFolder" -Level Verbose + if ((Test-DbaPath -Path $UseBackupFolder -SqlInstance $destInstance -SqlCredential $DestinationCredential) -ne $true) { + $setupResult = "Failed" + $comment = "The path to the backup folder could not be reached" + Stop-Function -Message ("The path to the backup folder could not be reached. Check the path and/or the crdential") -ErrorRecord $_ -Target $destInstance -Continue + } + + $BackupPath = $UseBackupFolder + } + elseif ($UseExistingFullBackup) { + Write-Message -Message "No path to the full backup is set. Trying to retrieve the last full backup for $db from $SourceSqlInstance" -Level Verbose + + # Get the last full backup + $LastBackup = Get-DbaBackupHistory -SqlServer $SourceSqlInstance -Databases $($db.Name) -LastFull -Credential $SourceSqlCredential + + # Check if there was a last backup + if ($null -eq $LastBackup) { + # Test the path to the backup + Write-Message -Message "Testing last backup path $(($LastBackup[-1]).Path[-1])" -Level Verbose + if ((Test-DbaPath -Path ($LastBackup[-1]).Path[-1] -SqlInstance $SourceSqlInstance -SqlCredential $SourceCredential) -ne $true) { + $setupResult = "Failed" + $comment = "The full backup could not be found" + Stop-Function -Message "The full backup could not be found on $($LastBackup.Path). Check path and/or credentials" -ErrorRecord $_ -Target $destInstance -Continue + } + # Check if the source for the last full backup is remote and the backup is on a shared location + elseif (($LastBackup.Computername -ne $SourceServerName) -and (($LastBackup[-1]).Path[-1].StartsWith('\\') -eq $false)) { + $setupResult = "Failed" + $comment = "The last full backup is not located on shared location" + Stop-Function -Message "The last full backup is not located on shared location. `n$($_.Exception.Message)" -ErrorRecord $_ -Target $destInstance -Continue + } + else { + #$FullBackupPath = $LastBackup.Path + $BackupPath = $LastBackup.Path + Write-Message -Message "Full backup found for $db. Path $BackupPath" -Level Verbose + } + } + else { + Write-Message -Message "No Full backup found for $db." -Level Verbose + } } - } - else { - Write-Message -Message "No Full backup found for $db." -Level Output } } - } - # Set the copy destination folder to include the database name - if ($CopyDestinationFolder.EndsWith("\")) { - $DatabaseCopyDestinationFolder = "$CopyDestinationFolder$($db.Name)" - } - else { - $DatabaseCopyDestinationFolder = "$CopyDestinationFolder\$($db.Name)" - } - Write-Message -Message "Copy destination folder set to $DatabaseCopyDestinationFolder." -Level Verbose + # Set the copy destination folder to include the database name + if ($CopyDestinationFolder.EndsWith("\")) { + $DatabaseCopyDestinationFolder = "$CopyDestinationFolder$($db.Name)" + } + else { + $DatabaseCopyDestinationFolder = "$CopyDestinationFolder\$($db.Name)" + } + Write-Message -Message "Copy destination folder set to $DatabaseCopyDestinationFolder." -Level Verbose - # Check if the copy job name is set - if ($CopyJob) { - $DatabaseCopyJob = "$CopyJob_$SourceServerName_$($db.Name)" - } - else { - $DatabaseCopyJob = "LSCopy_$SourceServerName_$($db.Name)" - } - Write-Message -Message "Copy job name set to $DatabaseCopyJob" -Level Verbose + # Check if the copy job name is set + if ($CopyJob) { + $DatabaseCopyJob = "$CopyJob_$SourceServerName_$($db.Name)" + } + else { + $DatabaseCopyJob = "LSCopy_$SourceServerName_$($db.Name)" + } + Write-Message -Message "Copy job name set to $DatabaseCopyJob" -Level Verbose - # Check if the copy job schedule name is set - if ($CopySchedule) { - $DatabaseCopySchedule = "$CopySchedule_$($db.Name)" - } - else { - $DatabaseCopySchedule = "LSCopySchedule_$($db.Name)" - Write-Message -Message "Copy job schedule name set to $DatabaseCopySchedule" -Level Verbose - } + # Check if the copy job schedule name is set + if ($CopySchedule) { + $DatabaseCopySchedule = "$CopySchedule_$($db.Name)" + } + else { + $DatabaseCopySchedule = "LSCopySchedule_$($db.Name)" + Write-Message -Message "Copy job schedule name set to $DatabaseCopySchedule" -Level Verbose + } - # Check if the copy destination folder exists - Write-Message -Message "Testing database copy destination path $DatabaseCopyDestinationFolder" -Level Verbose - if ((Test-DbaPath -Path $DatabaseCopyDestinationFolder -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationCredential) -ne $true) { - if ($PSCmdlet.ShouldProcess($DestinationServerName, "Creating copy destination folder on $DestinationServerName")) { - try { - Invoke-Command2 -Credential $DestinationCredential -ScriptBlock { - Write-Message -Message "Copy destination folder $DatabaseCopyDestinationFolder not found. Trying to create it.. ." -Level Verbose - New-Item -Path $DatabaseCopyDestinationFolder -ItemType Directory -Credential $DestinationCredential -Force:$Force | Out-Null + # Check if the copy destination folder exists + if($setupResult -ne 'Failed'){ + Write-Message -Message "Testing database copy destination path $DatabaseCopyDestinationFolder" -Level Verbose + if ((Test-DbaPath -Path $DatabaseCopyDestinationFolder -SqlInstance $destInstance -SqlCredential $DestinationCredential) -ne $true) { + if ($PSCmdlet.ShouldProcess($DestinationServerName, "Creating copy destination folder on $DestinationServerName")) { + 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 + } + } + catch { + $setupResult = "Failed" + $comment = "Something went wrong creating the database copy destination folder" + Stop-Function -Message "Something went wrong creating the database copy destination folder. `n$($_.Exception.Message)" -ErrorRecord $_ -Target $DestinationServerName -Continue + } } } - catch { - Stop-Function -Message "Something went wrong creating the database copy destination folder. `n$($_.Exception.Message)" -ErrorRecord $_ -Target $DestinationServerName -Continue - } } - } - # Check if the restore job name is set - if ($RestoreJob) { - $DatabaseRestoreJob = "$RestoreJob_$SourceServerName_$($db.Name)" - } - else { - $DatabaseRestoreJob = "LSRestore_$DestinationServerName_$($db.Name)" - } - Write-Message -Message "Restore job name set to $DatabaseRestoreJob" -Level Verbose + # Check if the restore job name is set + if ($RestoreJob) { + $DatabaseRestoreJob = "$RestoreJob_$SourceServerName_$($db.Name)" + } + else { + $DatabaseRestoreJob = "LSRestore_$DestinationServerName_$($db.Name)" + } + Write-Message -Message "Restore job name set to $DatabaseRestoreJob" -Level Verbose - # Check if the restore job schedule name is set - if ($RestoreSchedule) { - $DatabaseRestoreSchedule = "$RestoreSchedule_$($db.Name)" - } - else { - $DatabaseRestoreSchedule = "LSRestoreSchedule_$($db.Name)" - } - Write-Message -Message "Restore job schedule name set to $DatabaseRestoreSchedule" -Level Verbose + # Check if the restore job schedule name is set + if ($RestoreSchedule) { + $DatabaseRestoreSchedule = "$RestoreSchedule_$($db.Name)" + } + else { + $DatabaseRestoreSchedule = "LSRestoreSchedule_$($db.Name)" + } + Write-Message -Message "Restore job schedule name set to $DatabaseRestoreSchedule" -Level Verbose - # If the database needs to be backed up first - if ($GenerateFullBackup) { - if ($PSCmdlet.ShouldProcess($SourceSqlInstance, "Backing up database $db")) { + # If the database needs to be backed up first + if($setupResult -ne 'Failed'){ + if ($GenerateFullBackup) { + if ($PSCmdlet.ShouldProcess($SourceSqlInstance, "Backing up database $db")) { - Write-Message -Message "Generating full backup." -Level Output - Write-Message -Message "Backing up database $db to $DatabaseBackupNetworkPath" -Level Output + Write-Message -Message "Generating full backup." -Level Verbose + Write-Message -Message "Backing up database $db to $DatabaseBackupNetworkPath" -Level Verbose - try { - $Timestamp = Get-Date -format "yyyyMMddHHmmss" + try { + $Timestamp = Get-Date -format "yyyyMMddHHmmss" - $LastBackup = Backup-DbaDatabase -SqlInstance $SourceSqlInstance ` - -SqlCredential $SourceSqlCredential ` - -BackupDirectory $DatabaseBackupNetworkPath ` - -BackupFileName "FullBackup_$($db.Name)_PreLogShipping_$Timestamp.bak" ` - -Databases $($db.Name) ` - -Type Full + $LastBackup = Backup-DbaDatabase -SqlInstance $SourceSqlInstance ` + -SqlCredential $SourceSqlCredential ` + -BackupDirectory $DatabaseBackupNetworkPath ` + -BackupFileName "FullBackup_$($db.Name)_PreLogShipping_$Timestamp.bak" ` + -Databases $($db.Name) ` + -Type Full - Write-Message -Message "Backup completed." -Level Output + Write-Message -Message "Backup completed." -Level Verbose - # Get the last full backup path - #$FullBackupPath = $LastBackup.BackupPath - $BackupPath = $LastBackup.BackupPath + # Get the last full backup path + #$FullBackupPath = $LastBackup.BackupPath + $BackupPath = $LastBackup.BackupPath - Write-Message -Message "Backup is located at $BackupPath" -Level Verbose + Write-Message -Message "Backup is located at $BackupPath" -Level Verbose + } + catch { + $setupResult = "Failed" + $comment = "Something went wrong generating the full backup" + Stop-Function -Message "Something went wrong generating the full backup" -ErrorRecord $_ -Target $DestinationServerName -Continue + } + } } - catch { - Stop-Function -Message "Something went wrong generating the full backup" -ErrorRecord $_ -Target $DestinationServerName -Continue + } + + # Check of the MonitorServerSecurityMode value is of type string and set the integer value + if ($PrimaryMonitorServerSecurityMode -notin 0, 1) { + $PrimaryMonitorServerSecurityMode = switch ($PrimaryMonitorServerSecurityMode) { + "SQLSERVER" { 0 } "WINDOWS" { 1 } default { 1 } } } - } - # Check of the MonitorServerSecurityMode value is of type string and set the integer value - if ($PrimaryMonitorServerSecurityMode -notin 0, 1) { - $PrimaryMonitorServerSecurityMode = switch ($PrimaryMonitorServerSecurityMode) { - "SQLSERVER" { 0 } "WINDOWS" { 1 } default { 1 } + # Check the primary monitor server + if ($Force -and (-not$PrimaryMonitorServer -or [string]$PrimaryMonitorServer -eq '' -or $PrimaryMonitorServer -eq $null)) { + Write-Message -Message "Setting monitor server for primary server to $SourceSqlInstance." -Level Verbose + $PrimaryMonitorServer = $SourceSqlInstance } - } - # Check the primary monitor server - if ($Force -and (-not$PrimaryMonitorServer -or [string]$PrimaryMonitorServer -eq '' -or $PrimaryMonitorServer -eq $null)) { - Write-Message -Message "Setting monitor server for primary server to $SourceSqlInstance." -Level Output - $PrimaryMonitorServer = $SourceSqlInstance - } + # Check the PrimaryMonitorServerSecurityMode if it's SQL Server authentication + if ($PrimaryMonitorServerSecurityMode -eq 0) { + if ($PrimaryMonitorServerLogin) { + $setupResult = "Failed" + $comment = "The PrimaryMonitorServerLogin cannot be empty" + Stop-Function -Message "The PrimaryMonitorServerLogin cannot be empty when using SQL Server authentication." -Target $SourceSqlInstance -Continue + } - # Check the PrimaryMonitorServerSecurityMode if it's SQL Server authentication - if ($PrimaryMonitorServerSecurityMode -eq 0) { - if ($PrimaryMonitorServerLogin) { - Stop-Function -Message "The PrimaryMonitorServerLogin cannot be empty when using SQL Server authentication." -Target $SourceSqlInstance -Continue + if ($PrimaryMonitorServerPassword) { + $setupResult = "Failed" + $comment = "The PrimaryMonitorServerPassword cannot be empty" + Stop-Function -Message "The PrimaryMonitorServerPassword cannot be empty when using SQL Server authentication." -Target $ -Continue + } } - if ($PrimaryMonitorServerPassword) { - Stop-Function -Message "The PrimaryMonitorServerPassword cannot be empty when using SQL Server authentication." -Target $ -Continue + # Check of the SecondaryMonitorServerSecurityMode value is of type string and set the integer value + if ($SecondaryMonitorServerSecurityMode -notin 0, 1) { + $SecondaryMonitorServerSecurityMode = switch ($SecondaryMonitorServerSecurityMode) { + "SQLSERVER" { 0 } "WINDOWS" { 1 } default { 1 } + } } - } - # Check of the SecondaryMonitorServerSecurityMode value is of type string and set the integer value - if ($SecondaryMonitorServerSecurityMode -notin 0, 1) { - $SecondaryMonitorServerSecurityMode = switch ($SecondaryMonitorServerSecurityMode) { - "SQLSERVER" { 0 } "WINDOWS" { 1 } default { 1 } + # Check the secondary monitor server + if ($Force -and (-not $SecondaryMonitorServer -or [string]$SecondaryMonitorServer -eq '' -or $SecondaryMonitorServer -eq $null)) { + Write-Message -Message "Setting secondary monitor server for $destInstance to $SourceSqlInstance." -Level Verbose + $SecondaryMonitorServer = $SourceSqlInstance } - } - # Check the secondary monitor server - if ($Force -and (-not $SecondaryMonitorServer -or [string]$SecondaryMonitorServer -eq '' -or $SecondaryMonitorServer -eq $null)) { - Write-Message -Message "Setting secondary monitor server for $DestinationSqlInstance to $SourceSqlInstance." -Level Verbose - $SecondaryMonitorServer = $SourceSqlInstance - } + # Check the MonitorServerSecurityMode if it's SQL Server authentication + if ($SecondaryMonitorServerSecurityMode -eq 0) { + if ($SecondaryMonitorServerLogin) { + $setupResult = "Failed" + $comment = "The SecondaryMonitorServerLogin cannot be empty" + Stop-Function -Message "The SecondaryMonitorServerLogin cannot be empty when using SQL Server authentication." -Target $SourceSqlInstance -Continue + } - # Check the MonitorServerSecurityMode if it's SQL Server authentication - if ($SecondaryMonitorServerSecurityMode -eq 0) { - if ($SecondaryMonitorServerLogin) { - Stop-Function -Message "The SecondaryMonitorServerLogin cannot be empty when using SQL Server authentication." -Target $SourceSqlInstance -Continue + if ($SecondaryMonitorServerPassword) { + $setupResult = "Failed" + $comment = "The SecondaryMonitorServerPassword cannot be empty" + Stop-Function -Message "The SecondaryMonitorServerPassword cannot be empty when using SQL Server authentication." -Target $SourceSqlInstance -Continue + } } - if ($SecondaryMonitorServerPassword) { - Stop-Function -Message "The SecondaryMonitorServerPassword cannot be empty when using SQL Server authentication." -Target $SourceSqlInstance -Continue - } - } + # Now that all the checks have been done we can start with the fun stuff ! - # Now that all the checks have been done we can start with the fun stuff ! + # Restore the full backup + if($setupResult -ne 'Failed'){ + if ($PSCmdlet.ShouldProcess($destInstance, "Restoring database $db to $SecondaryDatabase on $destInstance")) { + if ($GenerateFullBackup -or $UseExistingFullBackup -or $UseBackupFolder) { + try { + Write-Message -Message "Start database restore" -Level Verbose + if ($NoRecovery -or (-not $Standby)) { + if ($Force) { + $null = Restore-DbaDatabase -SqlServer $destInstance ` + -SqlCredential $DestinationSqlCredential ` + -Path $BackupPath ` + -DestinationFilePrefix $SecondaryDatabasePrefix ` + -DestinationFileSuffix $SecondaryDatabaseSuffix ` + -DestinationDataDirectory $DatabaseRestoreDataFolder ` + -DestinationLogDirectory $DatabaseRestoreLogFolder ` + -DatabaseName $SecondaryDatabase ` + -DirectoryRecurse ` + -NoRecovery ` + -WithReplace + } + else { + $null = Restore-DbaDatabase -SqlServer $destInstance ` + -SqlCredential $DestinationSqlCredential ` + -Path $BackupPath ` + -DestinationFilePrefix $SecondaryDatabasePrefix ` + -DestinationFileSuffix $SecondaryDatabaseSuffix ` + -DestinationDataDirectory $DatabaseRestoreDataFolder ` + -DestinationLogDirectory $DatabaseRestoreLogFolder ` + -DatabaseName $SecondaryDatabase ` + -DirectoryRecurse ` + -NoRecovery + } + } - # Restore the full backup - if ($PSCmdlet.ShouldProcess($DestinationSqlInstance, "Restoring database $db to $SecondaryDatabase on $DestinationSqlInstance")) { - if ($GenerateFullBackup -or $UseExistingFullBackup -or $UseBackupFolder) { - try { - Write-Message -Message "Start database restore" -Level Output - if ($NoRecovery -or (-not $Standby)) { - if ($Force) { - Restore-DbaDatabase -SqlServer $DestinationSqlInstance ` - -SqlCredential $DestinationSqlCredential ` - -Path $BackupPath ` - -DestinationFilePrefix $SecondaryDatabasePrefix ` - -DestinationFileSuffix $SecondaryDatabaseSuffix ` - -DestinationDataDirectory $DatabaseRestoreDataFolder ` - -DestinationLogDirectory $DatabaseRestoreLogFolder ` - -DatabaseName $SecondaryDatabase ` - -DirectoryRecurse ` - -NoRecovery ` - -WithReplace | Out-Null + # If the database needs to be in standby + if ($Standby) { + # Setup the path to the standby file + $StandbyDirectory = "$DatabaseCopyDestinationFolder" + + # Check if credentials need to be used + if ($DestinationSqlCredential) { + $null = Restore-DbaDatabase -ServerInstance $destInstance ` + -SqlCredential $DestinationSqlCredential ` + -Path $BackupPath ` + -DestinationFilePrefix $SecondaryDatabasePrefix ` + -DestinationFileSuffix $SecondaryDatabaseSuffix ` + -DestinationDataDirectory $DatabaseRestoreDataFolder ` + -DestinationLogDirectory $DatabaseRestoreLogFolder ` + -DatabaseName $SecondaryDatabase ` + -DirectoryRecurse ` + -StandbyDirectory $StandbyDirectory + } + else { + $null = Restore-DbaDatabase -ServerInstance $destInstance ` + -Path $BackupPath ` + -DestinationFilePrefix $SecondaryDatabasePrefix ` + -DestinationFileSuffix $SecondaryDatabaseSuffix ` + -DestinationDataDirectory $DatabaseRestoreDataFolder ` + -DestinationLogDirectory $DatabaseRestoreLogFolder ` + -DatabaseName $SecondaryDatabase ` + -DirectoryRecurse ` + -StandbyDirectory $StandbyDirectory + } + } } - else { - Restore-DbaDatabase -SqlServer $DestinationSqlInstance ` - -SqlCredential $DestinationSqlCredential ` - -Path $BackupPath ` - -DestinationFilePrefix $SecondaryDatabasePrefix ` - -DestinationFileSuffix $SecondaryDatabaseSuffix ` - -DestinationDataDirectory $DatabaseRestoreDataFolder ` - -DestinationLogDirectory $DatabaseRestoreLogFolder ` - -DatabaseName $SecondaryDatabase ` - -DirectoryRecurse ` - -NoRecovery | Out-Null + catch { + $setupResult = "Failed" + $comment = "Something went wrong restoring the secondary database" + Stop-Function -Message "Something went wrong restoring the secondary database" -ErrorRecord $_ -Target $SourceSqlInstance -Continue } + + Write-Message -Message "Restore completed." -Level Verbose } + } + } - # If the database needs to be in standby - if ($Standby) { - # Setup the path to the standby file - $StandbyDirectory = "$DatabaseCopyDestinationFolder" - - # Check if credentials need to be used - if ($DestinationSqlCredential) { - Restore-DbaDatabase -ServerInstance $DestinationSqlInstance ` - -SqlCredential $DestinationSqlCredential ` - -Path $BackupPath ` - -DestinationFilePrefix $SecondaryDatabasePrefix ` - -DestinationFileSuffix $SecondaryDatabaseSuffix ` - -DestinationDataDirectory $DatabaseRestoreDataFolder ` - -DestinationLogDirectory $DatabaseRestoreLogFolder ` - -DatabaseName $SecondaryDatabase ` - -DirectoryRecurse ` - -StandbyDirectory $StandbyDirectory + #region Set up log shipping on the primary instance + # Set up log shipping on the primary instance + if($setupResult -ne 'Failed'){ + if ($PSCmdlet.ShouldProcess($SourceSqlInstance, "Configuring logshipping for primary database $db on $SourceSqlInstance")) { + try { + + Write-Message -Message "Configuring logshipping for primary database" -Level Verbose + + New-DbaLogShippingPrimaryDatabase -SqlInstance $SourceSqlInstance ` + -SqlCredential $SourceSqlCredential ` + -Database $($db.Name) ` + -BackupDirectory $DatabaseBackupLocalPath ` + -BackupJob $DatabaseBackupJob ` + -BackupRetention $BackupRetention ` + -BackupShare $DatabaseBackupNetworkPath ` + -BackupThreshold $BackupThreshold ` + -CompressBackup:$BackupCompression ` + -HistoryRetention $HistoryRetention ` + -MonitorServer $PrimaryMonitorServer ` + -MonitorServerSecurityMode $PrimaryMonitorServerSecurityMode ` + -MonitorCredential $PrimaryMonitorCredential ` + -ThresholdAlertEnabled:$PrimaryThresholdAlertEnabled ` + -Force:$Force + + # Check if the backup job needs to be enabled or disabled + if ($BackupScheduleDisabled) { + $null = Set-DbaAgentJob -SqlInstance $SourceSqlInstance -SqlCredential $SourceSqlCredential -Job $DatabaseBackupJob -Disabled + Write-Message -Message "Disabling backup job $DatabaseBackupJob" -Level Verbose } else { - Restore-DbaDatabase -ServerInstance $DestinationSqlInstance ` - -Path $BackupPath ` - -DestinationFilePrefix $SecondaryDatabasePrefix ` - -DestinationFileSuffix $SecondaryDatabaseSuffix ` - -DestinationDataDirectory $DatabaseRestoreDataFolder ` - -DestinationLogDirectory $DatabaseRestoreLogFolder ` - -DatabaseName $SecondaryDatabase ` - -DirectoryRecurse ` - -StandbyDirectory $StandbyDirectory + $null = Set-DbaAgentJob -SqlInstance $SourceSqlInstance -SqlCredential $SourceSqlCredential -Job $DatabaseBackupJob -Enabled + Write-Message -Message "Enabling backup job $DatabaseBackupJob" -Level Verbose } + + Write-Message -Message "Create backup job schedule $DatabaseBackupSchedule" -Level Verbose + + $BackupJobSchedule = New-DbaAgentSchedule -SqlInstance $SourceSqlInstance ` + -SqlCredential $SourceSqlCredential ` + -Job $DatabaseBackupJob ` + -Schedule $DatabaseBackupSchedule ` + -FrequencyType $BackupScheduleFrequencyType ` + -FrequencyInterval $BackupScheduleFrequencyInterval ` + -FrequencySubdayType $BackupScheduleFrequencySubdayType ` + -FrequencySubdayInterval $BackupScheduleFrequencySubdayInterval ` + -FrequencyRelativeInterval $BackupScheduleFrequencyRelativeInterval ` + -FrequencyRecurrenceFactor $BackupScheduleFrequencyRecurrenceFactor ` + -StartDate $BackupScheduleStartDate ` + -EndDate $BackupScheduleEndDate ` + -StartTime $BackupScheduleStartTime ` + -EndTime $BackupScheduleEndTime ` + -Force:$Force + + Write-Message -Message "Configuring logshipping from primary to secondary database." -Level Verbose + + New-DbaLogShippingPrimarySecondary -SqlInstance $SourceSqlInstance ` + -SqlCredential $SourceSqlCredential ` + -PrimaryDatabase $($db.Name) ` + -SecondaryDatabase $SecondaryDatabase ` + -SecondaryServer $destInstance ` + -SecondarySqlCredential $DestinationSqlCredential + } + catch { + $setupResult = "Failed" + $comment = "Something went wrong setting up log shipping for primary instance" + Stop-Function -Message "Something went wrong setting up log shipping for primary instance" -ErrorRecord $_ -Target $SourceSqlInstance -Continue } } - catch { - Stop-Function -Message "Something went wrong restoring the secondary database" -ErrorRecord $_ -Target $SourceSqlInstance -Continue - } - - Write-Message -Message "Restore completed." -Level Output } - } + #endregion Set up log shipping on the primary instance - #region Set up log shipping on the primary instance - # Set up log shipping on the primary instance - if ($PSCmdlet.ShouldProcess($SourceSqlInstance, "Configuring logshipping for primary database $db on $SourceSqlInstance")) { - try { + #region Set up log shipping on the secondary instance + # Set up log shipping on the secondary instance + if($setupResult -ne 'Failed'){ + if ($PSCmdlet.ShouldProcess($destInstance, "Configuring logshipping for secondary database $SecondaryDatabase on $destInstance")) { + try { - Write-Message -Message "Configuring logshipping for primary database" -Level Output - - New-DbaLogShippingPrimaryDatabase -SqlInstance $SourceSqlInstance ` - -SqlCredential $SourceSqlCredential ` - -Database $($db.Name) ` - -BackupDirectory $DatabaseBackupLocalPath ` - -BackupJob $DatabaseBackupJob ` - -BackupRetention $BackupRetention ` - -BackupShare $DatabaseBackupNetworkPath ` - -BackupThreshold $BackupThreshold ` - -CompressBackup:$BackupCompression ` - -HistoryRetention $HistoryRetention ` - -MonitorServer $PrimaryMonitorServer ` - -MonitorServerSecurityMode $PrimaryMonitorServerSecurityMode ` - -MonitorCredential $PrimaryMonitorCredential ` - -ThresholdAlertEnabled:$PrimaryThresholdAlertEnabled ` - -Force:$Force - - # Check if the backup job needs to be enabled or disabled - if ($BackupScheduleDisabled) { - Set-DbaAgentJob -SqlInstance $SourceSqlInstance -SqlCredential $SourceSqlCredential -Job $DatabaseBackupJob -Disabled - Write-Message -Message "Disabling backup job $DatabaseBackupJob" -Level Output - } - else { - Set-DbaAgentJob -SqlInstance $SourceSqlInstance -SqlCredential $SourceSqlCredential -Job $DatabaseBackupJob -Enabled - Write-Message -Message "Enabling backup job $DatabaseBackupJob" -Level Output - } - - Write-Message -Message "Create backup job schedule $DatabaseBackupSchedule" -Level Output - - $BackupJobSchedule = New-DbaAgentSchedule -SqlInstance $SourceSqlInstance ` - -SqlCredential $SourceSqlCredential ` - -Job $DatabaseBackupJob ` - -Schedule $DatabaseBackupSchedule ` - -FrequencyType $BackupScheduleFrequencyType ` - -FrequencyInterval $BackupScheduleFrequencyInterval ` - -FrequencySubdayType $BackupScheduleFrequencySubdayType ` - -FrequencySubdayInterval $BackupScheduleFrequencySubdayInterval ` - -FrequencyRelativeInterval $BackupScheduleFrequencyRelativeInterval ` - -FrequencyRecurrenceFactor $BackupScheduleFrequencyRecurrenceFactor ` - -StartDate $BackupScheduleStartDate ` - -EndDate $BackupScheduleEndDate ` - -StartTime $BackupScheduleStartTime ` - -EndTime $BackupScheduleEndTime ` - -Force:$Force - - Write-Message -Message "Configuring logshipping from primary to secondary database." -Level Output - - New-DbaLogShippingPrimarySecondary -SqlInstance $SourceSqlInstance ` - -SqlCredential $SourceSqlCredential ` - -PrimaryDatabase $($db.Name) ` - -SecondaryDatabase $SecondaryDatabase ` - -SecondaryServer $DestinationSqlInstance ` - -SecondarySqlCredential $DestinationSqlCredential - } - catch { - Stop-Function -Message "Something went wrong setting up log shipping for primary instance" -ErrorRecord $_ -Target $SourceSqlInstance -Continue - } - } - #endregion Set up log shipping on the primary instance + Write-Message -Message "Configuring logshipping from secondary database $SecondaryDatabase to primary database $db." -Level Verbose + + New-DbaLogShippingSecondaryPrimary -SqlInstance $destInstance ` + -SqlCredential $DestinationSqlCredential ` + -BackupSourceDirectory $DatabaseBackupNetworkPath ` + -BackupDestinationDirectory $DatabaseCopyDestinationFolder ` + -CopyJob $DatabaseCopyJob ` + -FileRetentionPeriod $BackupRetention ` + -MonitorServer $SecondaryMonitorServer ` + -MonitorServerSecurityMode $SecondaryMonitorServerSecurityMode ` + -MonitorCredential $SecondaryMonitorCredential ` + -PrimaryServer $SourceSqlInstance ` + -PrimaryDatabase $($db.Name) ` + -RestoreJob $DatabaseRestoreJob ` + -Force:$Force + + Write-Message -Message "Create copy job schedule $DatabaseCopySchedule" -Level Verbose + + $CopyJobSchedule = New-DbaAgentSchedule -SqlInstance $destInstance ` + -SqlCredential $DestinationSqlCredential ` + -Job $DatabaseCopyJob ` + -Schedule $DatabaseCopySchedule ` + -FrequencyType $CopyScheduleFrequencyType ` + -FrequencyInterval $CopyScheduleFrequencyInterval ` + -FrequencySubdayType $CopyScheduleFrequencySubdayType ` + -FrequencySubdayInterval $CopyScheduleFrequencySubdayInterval ` + -FrequencyRelativeInterval $CopyScheduleFrequencyRelativeInterval ` + -FrequencyRecurrenceFactor $CopyScheduleFrequencyRecurrenceFactor ` + -StartDate $CopyScheduleStartDate ` + -EndDate $CopyScheduleEndDate ` + -StartTime $CopyScheduleStartTime ` + -EndTime $CopyScheduleEndTime ` + -Force:$Force + + Write-Message -Message "Create restore job schedule $DatabaseRestoreSchedule" -Level Verbose + + $RestoreJobSchedule = New-DbaAgentSchedule -SqlInstance $destInstance ` + -SqlCredential $DestinationSqlCredential ` + -Job $DatabaseRestoreJob ` + -Schedule $DatabaseRestoreSchedule ` + -FrequencyType $RestoreScheduleFrequencyType ` + -FrequencyInterval $RestoreScheduleFrequencyInterval ` + -FrequencySubdayType $RestoreScheduleFrequencySubdayType ` + -FrequencySubdayInterval $RestoreScheduleFrequencySubdayInterval ` + -FrequencyRelativeInterval $RestoreScheduleFrequencyRelativeInterval ` + -FrequencyRecurrenceFactor $RestoreScheduleFrequencyRecurrenceFactor ` + -StartDate $RestoreScheduleStartDate ` + -EndDate $RestoreScheduleEndDate ` + -StartTime $RestoreScheduleStartTime ` + -EndTime $RestoreScheduleEndTime ` + -Force:$Force + + Write-Message -Message "Configuring logshipping for secondary database." -Level Verbose + + New-DbaLogShippingSecondaryDatabase -SqlInstance $destInstance ` + -SqlCredential $DestinationSqlCredential ` + -SecondaryDatabase $SecondaryDatabase ` + -PrimaryServer $SourceSqlInstance ` + -PrimaryDatabase $($db.Name) ` + -RestoreDelay $RestoreDelay ` + -RestoreMode $DatabaseStatus ` + -DisconnectUsers:$DisconnectUsers ` + -RestoreThreshold $RestoreThreshold ` + -ThresholdAlertEnabled:$SecondaryThresholdAlertEnabled ` + -HistoryRetention $HistoryRetention + + # Check if the copy job needs to be enabled or disabled + if ($CopyScheduleDisabled) { + $null = Set-DbaAgentJob -SqlInstance $destInstance -SqlCredential $DestinationSqlCredential -Job $DatabaseCopyJob -Disabled + } + else { + $null = Set-DbaAgentJob -SqlInstance $destInstance -SqlCredential $DestinationSqlCredential -Job $DatabaseCopyJob -Enabled + } - #region Set up log shipping on the secondary instance - # Set up log shipping on the secondary instance - if ($PSCmdlet.ShouldProcess($DestinationSqlInstance, "Configuring logshipping for secondary database $SecondaryDatabase on $DestinationSqlInstance")) { - try { + # Check if the restore job needs to be enabled or disabled + if ($RestoreScheduleDisabled) { + $null = Set-DbaAgentJob -SqlInstance $destInstance -SqlCredential $DestinationSqlCredential -Job $DatabaseRestoreJob -Disabled + } + else { + $null = Set-DbaAgentJob -SqlInstance $destInstance -SqlCredential $DestinationSqlCredential -Job $DatabaseRestoreJob -Enabled + } - Write-Message -Message "Configuring logshipping from secondary database $SecondaryDatabase to primary database $db." -Level Output - - New-DbaLogShippingSecondaryPrimary -SqlInstance $DestinationSqlInstance ` - -SqlCredential $DestinationSqlCredential ` - -BackupSourceDirectory $DatabaseBackupNetworkPath ` - -BackupDestinationDirectory $DatabaseCopyDestinationFolder ` - -CopyJob $DatabaseCopyJob ` - -FileRetentionPeriod $BackupRetention ` - -MonitorServer $SecondaryMonitorServer ` - -MonitorServerSecurityMode $SecondaryMonitorServerSecurityMode ` - -MonitorCredential $SecondaryMonitorCredential ` - -PrimaryServer $SourceSqlInstance ` - -PrimaryDatabase $($db.Name) ` - -RestoreJob $DatabaseRestoreJob ` - -Force:$Force - - Write-Message -Message "Create copy job schedule $DatabaseCopySchedule" -Level Output - - $CopyJobSchedule = New-DbaAgentSchedule -SqlInstance $DestinationSqlInstance ` - -SqlCredential $DestinationSqlCredential ` - -Job $DatabaseCopyJob ` - -Schedule $DatabaseCopySchedule ` - -FrequencyType $CopyScheduleFrequencyType ` - -FrequencyInterval $CopyScheduleFrequencyInterval ` - -FrequencySubdayType $CopyScheduleFrequencySubdayType ` - -FrequencySubdayInterval $CopyScheduleFrequencySubdayInterval ` - -FrequencyRelativeInterval $CopyScheduleFrequencyRelativeInterval ` - -FrequencyRecurrenceFactor $CopyScheduleFrequencyRecurrenceFactor ` - -StartDate $CopyScheduleStartDate ` - -EndDate $CopyScheduleEndDate ` - -StartTime $CopyScheduleStartTime ` - -EndTime $CopyScheduleEndTime ` - -Force:$Force - - Write-Message -Message "Create restore job schedule $DatabaseRestoreSchedule" -Level Output - - $RestoreJobSchedule = New-DbaAgentSchedule -SqlInstance $DestinationSqlInstance ` - -SqlCredential $DestinationSqlCredential ` - -Job $DatabaseRestoreJob ` - -Schedule $DatabaseRestoreSchedule ` - -FrequencyType $RestoreScheduleFrequencyType ` - -FrequencyInterval $RestoreScheduleFrequencyInterval ` - -FrequencySubdayType $RestoreScheduleFrequencySubdayType ` - -FrequencySubdayInterval $RestoreScheduleFrequencySubdayInterval ` - -FrequencyRelativeInterval $RestoreScheduleFrequencyRelativeInterval ` - -FrequencyRecurrenceFactor $RestoreScheduleFrequencyRecurrenceFactor ` - -StartDate $RestoreScheduleStartDate ` - -EndDate $RestoreScheduleEndDate ` - -StartTime $RestoreScheduleStartTime ` - -EndTime $RestoreScheduleEndTime ` - -Force:$Force - - Write-Message -Message "Configuring logshipping for secondary database." -Level Output - - New-DbaLogShippingSecondaryDatabase -SqlInstance $DestinationSqlInstance ` - -SqlCredential $DestinationSqlCredential ` - -SecondaryDatabase $SecondaryDatabase ` - -PrimaryServer $SourceSqlInstance ` - -PrimaryDatabase $($db.Name) ` - -RestoreDelay $RestoreDelay ` - -RestoreMode $DatabaseStatus ` - -DisconnectUsers:$DisconnectUsers ` - -RestoreThreshold $RestoreThreshold ` - -ThresholdAlertEnabled:$SecondaryThresholdAlertEnabled ` - -HistoryRetention $HistoryRetention - - # Check if the copy job needs to be enabled or disabled - if ($CopyScheduleDisabled) { - Set-DbaAgentJob -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationSqlCredential -Job $DatabaseCopyJob -Disabled - } - else { - Set-DbaAgentJob -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationSqlCredential -Job $DatabaseCopyJob -Enabled + } + catch { + $setupResult = "Failed" + $comment = "Something went wrong setting up log shipping for secondary instance" + Stop-Function -Message "Something went wrong setting up log shipping for secondary instance.`n$($_.Exception.Message)" -ErrorRecord $_ -Target $destInstance -Continue + } } + } + #endregion Set up log shipping on the secondary instance - # Check if the restore job needs to be enabled or disabled - if ($RestoreScheduleDisabled) { - Set-DbaAgentJob -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationSqlCredential -Job $DatabaseRestoreJob -Disabled - } - else { - Set-DbaAgentJob -SqlInstance $DestinationSqlInstance -SqlCredential $DestinationSqlCredential -Job $DatabaseRestoreJob -Enabled - } + Write-Message -Message "Completed configuring log shipping for database $db" -Level Verbose + [PSCustomObject]@{ + PrimaryInstance = $SourceServer.DomainInstanceName + SecondaryInstance = $DestinationServer.DomainInstanceName + PrimaryDatabase = $($db.Name) + SecondaryDatabase = $SecondaryDatabase + Result = $setupResult + Comment = $comment } - catch { - Stop-Function -Message "Something went wrong setting up log shipping for secondary instance.`n$($_.Exception.Message)" -ErrorRecord $_ -Target $DestinationSqlInstance -Continue - } - } - #endregion Set up log shipping on the secondary instance - Write-Message -Message "Completed configuring log shipping for database $db" -Level Output - - } # for each database + } # for each database + } # end for each destination server } # end process end { @@ -54696,6 +54853,9 @@ function Invoke-DbaLogShippingRecovery { Allows you to choose to not restore the database to a functional state (Normal) in the final steps of the process. By default the database is restored to a functional state (Normal). + .PARAMETER InputObject + Allows piped input from Get-DbaDatabase + .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. @@ -54750,146 +54910,74 @@ function Invoke-DbaLogShippingRecovery { Shows what would happen if the command were executed. #> - [CmdletBinding(SupportsShouldProcess = $true)] + [CmdletBinding(SupportsShouldProcess)] param ( - [Parameter(Mandatory)] [Alias("ServerInstance", "SqlServer")] - [object]$SqlInstance, - [Parameter(ValueFromPipeline)] - [object[]]$Database, + [DbaInstanceParameter[]]$SqlInstance, + [string[]]$Database, [PSCredential]$SqlCredential, [switch]$NoRecovery, [Alias('Silent')] [switch]$EnableException, [switch]$Force, + [Parameter(ValueFromPipeline)] + [Microsoft.SqlServer.Management.Smo.Database[]]$InputObject, [int]$Delay = 5 ) - begin { - if (!$sqlinstance -and $database.Count -lt 1) { - # You can prolly do this with - Stop-Function -Message "You must pipe an SMO database object or specify SqlInstance" - return - } - - if ($sqlinstance) { - # Check the instance if it is a named instance - $servername, $instancename = $sqlinstance.Split("\") - - if ($null -eq $instancename) { - $instancename = "MSSQLSERVER" - } - - Write-Message -Message "Connecting to Sql Server" -Level Output - try { - $server = Connect-SqlInstance -SqlInstance $sqlinstance -SqlCredential $SqlCredential - } - catch { - Stop-Function -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $instance - } - - if ($Force -and (!$database -or $database.Count -lt 1)) { - $database = $server.databases - } - elseif (-not $Force -and (!$database -or $database.Count -lt 1)) { - Stop-Function -Message "Please enter one or more databases to recover from log shipping" -Target $instance - } - else { - $databases = $server.databases | Where-Object Name -in $database - } - } + $totalSteps = 4 + $stepCounter = 0 } - process { - # Try to get the agent service details - try { - # Start the service - $agentservice = Get-DbaService -ComputerName $servername | Where-Object {($_.ComputerName -eq $servername) -and ($_.DisplayName -eq "SQL Server Agent ($instancename)")} - } - catch { - # Stop the function when the service was unable to start - Stop-Function -Message "Unable to start SQL Server Agent Service" -ErrorRecord $_ -Target $sqlinstance - return - } - - # Check if the service is running - if ($agentservice.State -ne 'Running') { - - if ($Force) { - try { - Start-DbaService -ComputerName $servername -InstanceName $instancename -Type Agent -Credential $SqlCredential - } - catch { - # Stop the function when the service was unable to start - Stop-Function -Message "Unable to start SQL Server Agent Service" -ErrorRecord $_ -Target $sqlinstance - return - } + foreach ($instance in $SqlInstance) { + if (-not $Force -and -not $Database) { + Stop-Function -Message "You must specify a -Database or -Force for all databases" -Target $server.name + return } - # If the force switch and the silent switch are not set - elseif (!$Force -and !$EnableException) { - # Set up the parts for the user choice - $Title = "SQL Server Agent is not running" - $Info = "Do you want to start the SQL Server Agent service?" - - $Options = [System.Management.Automation.Host.ChoiceDescription[]] @("&Start", "&Quit") - [int]$Defaultchoice = 0 - $choice = $host.UI.PromptForChoice($Title, $Info, $Options, $Defaultchoice) - - # Check the given option - if ($choice -eq 0) { - try { - # Start the service - Start-DbaService -ComputerName $servername -InstanceName $instancename -Type Agent -Credential $SqlCredential - } - catch { - # Stop the function when the service was unable to start - Stop-Function -Message "Unable to start SQL Server Agent Service" -ErrorRecord $_ -Target $sqlinstance - return - } - } - else { - Stop-Function -Message "The SQL Server Agent service needs to be started to be able to recover the databases" -ErrorRecord $_ -Target $sqlinstance + $InputObject += Get-DbaDatabase -SqlInstance $instance -SqlCredential $SqlCredential -Database $Database + } + + # Loop through all the databases + foreach ($db in $InputObject) { + $server = $db.Parent + $instance = $server.Name + $activity = "Performing log shipping recovery for $($db.Name) on $($server.Name)" + # Try to get the agent service details + try { + # Get the service details + $agentStatus = $server.Query("SELECT COUNT(*) as AgentCount FROM master.dbo.sysprocesses WITH (nolock) WHERE Program_Name LIKE 'SQLAgent%'") + + if ($agentStatus.AgentCount -lt 1) { + Stop-Function -Message "The agent service is not in a running state. Please start the service." -ErrorRecord $_ -Target $server.name return } } - # If the force switch it not set and the silent switch is set - elseif (!$Force -and $EnableException) { - Stop-Function -Message "The SQL Server Agent service needs to be started to be able to recover the databases" -ErrorRecord $_ -Target $sqlinstance - return - } - # If nothing else matches and the agent service is not started - else { - Stop-Function -Message "The SQL Server Agent service needs to be started to be able to recover the databases" -ErrorRecord $_ -Target $sqlinstance + catch { + Stop-Function -Message "Unable to get SQL Server Agent Service status" -ErrorRecord $_ -Target $server.name return } - - } - - Write-Message -Message "Started Log Shipping Recovery" -Level Output - - # Loop through all the databases - foreach ($db in $databases) { # Query for retrieving the log shipping information $query = "SELECT lss.primary_server, lss.primary_database, lsd.secondary_database, lss.backup_source_directory, - lss.backup_destination_directory, lss.last_copied_file, lss.last_copied_date, - lsd.last_restored_file, sj1.name AS 'copyjob', sj2.name AS 'restorejob' - FROM msdb.dbo.log_shipping_secondary AS lss - INNER JOIN msdb.dbo.log_shipping_secondary_databases AS lsd ON lsd.secondary_id = lss.secondary_id - INNER JOIN msdb.dbo.sysjobs AS sj1 ON sj1.job_id = lss.copy_job_id - INNER JOIN msdb.dbo.sysjobs AS sj2 ON sj2.job_id = lss.restore_job_id - WHERE lsd.secondary_database = '$($db.Name)'" - + lss.backup_destination_directory, lss.last_copied_file, lss.last_copied_date, + lsd.last_restored_file, sj1.name AS 'copyjob', sj2.name AS 'restorejob' + FROM msdb.dbo.log_shipping_secondary AS lss + INNER JOIN msdb.dbo.log_shipping_secondary_databases AS lsd ON lsd.secondary_id = lss.secondary_id + INNER JOIN msdb.dbo.sysjobs AS sj1 ON sj1.job_id = lss.copy_job_id + INNER JOIN msdb.dbo.sysjobs AS sj2 ON sj2.job_id = lss.restore_job_id + WHERE lsd.secondary_database = '$($db.Name)'" + # Retrieve the log shipping information from the secondary instance try { Write-Message -Message "Retrieving log shipping information from the secondary instance" -Level Verbose + Write-ProgressHelper -TotalSteps $totalSteps -Activity $activity -StepNumber ($stepCounter++) -Message "Retrieving log shipping information from the secondary instance" $logshipping_details = $server.Query($query) } catch { - Stop-Function -Message "Error retrieving the log shipping details: $($_.Exception.Message)" -ErrorRecord $_ -Target $sqlinstance + Stop-Function -Message "Error retrieving the log shipping details: $($_.Exception.Message)" -ErrorRecord $_ -Target $server.name return } - + # Check if there are any databases to recover if ($null -eq $logshipping_details) { Stop-Function -Message "The database $db is not configured as a secondary database for log shipping." -Continue @@ -54898,163 +54986,175 @@ function Invoke-DbaLogShippingRecovery { # Loop through each of the log shipped databases foreach ($ls in $logshipping_details) { $secondarydb = $ls.secondary_database - + + $recoverResult = "Success" + $comment = "" + $jobOutputs = @() + # Check if the database is in the right state if ($server.Databases[$secondarydb].Status -notin ('Normal, Standby', 'Standby', 'Restoring')) { Stop-Function -Message "The database $db doesn't have the right status to be recovered" -Continue } else { Write-Message -Message "Started Recovery for $secondarydb" -Level Verbose - - # Get the last file from the backup source directory - <# !!!! set credentials !!! #> - $latestBackupSource = Get-ChildItem -Path $ls.backup_source_directory -filter ("*" + $ls.primary_database + "*") | Where-Object { ($_.Extension -eq '.trn') } | Sort-Object LastWriteTime -Descending | Select-Object -First 1 - - # Get al the backup files from the destination directory - <# !!!! set credentials !!! #> - $latestBackupDest = Get-ChildItem -Path $ls.backup_destination_directory -filter ("*" + $ls.primary_database + "*") | Where-Object { ($_.Extension -eq '.trn') } | Sort-Object LastWriteTime -Descending | Select-Object -First 1 - - # Check if source and destination directory are in sync - if ($latestBackupSource.Name -ne $latestBackupDest.Name) { - # Check if the backup source directory can be reached - if (Test-DbaPath -SqlInstance $SqlInstance -Path $ls.backup_source_directory -SqlCredential $SqlCredential) { - - # Check if the latest file is also the latest copied file - if ($latestBackupSource.Name -ne ([string]$ls.last_copied_file).Split('\')[-1]) { - Write-Message -Message "Backup destination is not up-to-date" -Level Verbose - - # Start the job to get the latest files - if ($PSCmdlet.ShouldProcess($sqlinstance, ("Starting copy job $($ls.copyjob)"))) { - Write-Message -Message "Starting copy job $($ls.copyjob)" -Level Verbose - try { - $server.JobServer.Jobs[$ls.copyjob].Start() - } - catch { - Stop-Function -Message "Something went wrong starting the restore job.`n$($_)" -ErrorRecord $_ -Target $sqlinstance - } - - Write-Message -Message "Copying files to $($ls.backup_destination_directory)" -Level Verbose - - # Check if the file has been copied - $query = "SELECT last_copied_file FROM msdb.dbo.log_shipping_secondary WHERE primary_database = '$($ls.primary_database)' AND last_copied_file IS NOT NULL " - $latestcopy = $server.Query($query) - - Write-Message -Message "Waiting for the copy action to complete.." -Level Verbose - - while (($latestBackupSource.Name -ne ([string]$latestcopy.last_copied_file).Split('\')[-1])) { - # Sleep for while to let the files be copied - Start-Sleep -Seconds $Delay - - # Again get the latest file to check if the process can continue - $latestcopy = $server.Query($query) - } - - # Again get the latest file to check if the process can continue - $latestcopy = $server.Query($query) - - # Check the lat outcome of the job - if ($server.JobServer.Jobs[$ls.copyjob].LastRunOutcome -eq 'Failed') { - Stop-Function -Message "The copy job for database $db failed. Please check the error log." -Continue - } - - Write-Message -Message "Copying of backup files finished" -Level Verbose - } # if should process - } # if latest file name - } # if backup directory test - else { - Stop-Function -Message "Couldn't reach the backup source directory. Continuing..." -Continue - } - } # check latest backup file is already in directory - - - # Disable the log shipping copy job on the secondary instance - if ($PSCmdlet.ShouldProcess($sqlinstance, "Disabling copy job $($ls.copyjob)")) { + + # Start the job to get the latest files + if ($PSCmdlet.ShouldProcess($server.name, ("Starting copy job $($ls.copyjob)"))) { + Write-Message -Message "Starting copy job $($ls.copyjob)" -Level Verbose + + Write-ProgressHelper -TotalSteps $totalSteps -Activity $activity -StepNumber ($stepCounter++) -Message "Starting copy job" try { - Write-Message -Message "Disabling copy job $($ls.copyjob)" -Level Verbose - $server.JobServer.Jobs[$ls.copyjob].IsEnabled = $false - $server.JobServer.Jobs[$ls.copyjob].Alter() + $null = Start-DbaAgentJob -SqlInstance $instance -SqlCredential $sqlcredential -Job $ls.copyjob } catch { - Stop-Function -Message "Something went wrong disabling the copy job.`n$($_)" -ErrorRecord $_ -Target $sqlinstance + $recoverResult = "Failed" + $comment = "Something went wrong starting the copy job $($ls.copyjob)" + Stop-Function -Message "Something went wrong starting the copy job.`n$($_)" -ErrorRecord $_ -Target $server.name + } + + if ($recoverResult -ne 'Failed') { + Write-Message -Message "Copying files to $($ls.backup_destination_directory)" -Level Verbose + + Write-Message -Message "Waiting for the copy action to complete.." -Level Verbose + + # Get the job status + $jobStatus = Get-DbaAgentJob -SqlInstance $instance -SqlCredential $sqlcredential -Job $ls.copyjob + + while ($jobStatus.CurrentRunStatus -ne 'Idle') { + # Sleep for while to let the files be copied + Start-Sleep -Seconds $Delay + + # Get the job status + $jobStatus = Get-DbaAgentJob -SqlInstance $instance -SqlCredential $sqlcredential -Job $ls.copyjob + } + + # Check the lat outcome of the job + if ($jobStatus.LastRunOutcome -eq 'Failed') { + $recoverResult = "Failed" + $comment = "The copy job for database $db failed. Please check the error log." + Stop-Function -Message "The copy job for database $db failed. Please check the error log." + } + + $jobOutputs += $jobStatus + + Write-Message -Message "Copying of backup files finished" -Level Verbose + } + } # if should process + + # Disable the log shipping copy job on the secondary instance + if ($recoverResult -ne 'Failed') { + Write-ProgressHelper -TotalSteps $totalSteps -Activity $activity -StepNumber ($stepCounter++) -Message "Disabling copy job" + + if ($PSCmdlet.ShouldProcess($server.name, "Disabling copy job $($ls.copyjob)")) { + try { + Write-Message -Message "Disabling copy job $($ls.copyjob)" -Level Verbose + $null = Set-DbaAgentJob -SqlInstance $instance -SqlCredential $sqlcredential -Job $ls.copyjob -Disabled + } + catch { + $recoverResult = "Failed" + $comment = "Something went wrong disabling the copy job." + Stop-Function -Message "Something went wrong disabling the copy job.`n$($_)" -ErrorRecord $_ -Target $server.name + } } } - - # Check if the file has been copied - $query = "SELECT last_restored_file FROM msdb.dbo.log_shipping_secondary_databases WHERE secondary_database = '$secondarydb' AND last_restored_file IS NOT NULL" - $latestrestore = $server.Query($query) - - # Check if the last copied file is newer than the last restored file - if ((([string]$latestcopy.last_copied_file).Split('\')[-1] -ne ([string]$latestrestore.last_restored_file).Split('\')[-1]) -or ($null -eq ([string]$latestcopy.last_copied_file).Split('\')[-1])) { - Write-Message -Message "Restore is not up-to-date" -Level Verbose - + + if ($recoverResult -ne 'Failed') { # Start the restore job - if ($PSCmdlet.ShouldProcess($sqlinstance, ("Starting restore job " + $ls.restorejob))) { + Write-ProgressHelper -TotalSteps $totalSteps -Activity $activity -StepNumber ($stepCounter++) -Message "Starting restore job" + + if ($PSCmdlet.ShouldProcess($server.name, ("Starting restore job " + $ls.restorejob))) { Write-Message -Message "Starting restore job $($ls.restorejob)" -Level Verbose try { - $server.JobServer.Jobs[$ls.restorejob].Start() + $null = Start-DbaAgentJob -SqlInstance $instance -SqlCredential $sqlcredential -Job $ls.restorejob } catch { - Stop-Function -Message "Something went wrong starting the restore job.`n$($_)" -ErrorRecord $_ -Target $sqlinstance + $comment = "Something went wrong starting the restore job." + Stop-Function -Message "Something went wrong starting the restore job.`n$($_)" -ErrorRecord $_ -Target $server.name } - + Write-Message -Message "Waiting for the restore action to complete.." -Level Verbose - - while ($latestBackupSource.Name -ne [string]($latestrestore.last_restored_file).Split('\')[-1]) { + + # Get the job status + $jobStatus = Get-DbaAgentJob -SqlInstance $instance -SqlCredential $sqlcredential -Job $ls.restorejob + + while ($jobStatus.CurrentRunStatus -ne 'Idle') { # Sleep for while to let the files be copied Start-Sleep -Seconds $Delay - - # Again get the latest file to check if the process can continue - $latestrestore = $server.Query($query) + + # Get the job status + $jobStatus = Get-DbaAgentJob -SqlInstance $instance -SqlCredential $sqlcredential -Job $ls.restorejob } - - # Again get the latest file to check if the process can continue - $latestrestore = $server.Query($query) - + # Check the lat outcome of the job - if ($server.JobServer.Jobs[$ls.restorejob].LastRunOutcome -eq 'Failed') { - Stop-Function -Message "The restore job for database $db failed. Please check the error log." -Continue + if ($jobStatus.LastRunOutcome -eq 'Failed') { + $recoverResult = "Failed" + $comment = "The restore job for database $db failed. Please check the error log." + Stop-Function -Message "The restore job for database $db failed. Please check the error log." } + + $jobOutputs += $jobStatus } } - - # Disable the log shipping restore job on the secondary instance - if ($PSCmdlet.ShouldProcess($sqlinstance, "Disabling restore job $($ls.restorejob)")) { - try { - Write-Message -Message ("Disabling restore job " + $ls.restorejob) -Level Verbose - $server.JobServer.Jobs[$ls.restorejob].IsEnabled = $false - $server.JobServer.Jobs[$ls.restorejob].Alter() - } - catch { - Stop-Function -Message "Something went wrong disabling the restore job.`n$($_)" -ErrorRecord $_ -Target $sqlinstance + + if ($recoverResult -ne 'Failed') { + # Disable the log shipping restore job on the secondary instance + if ($PSCmdlet.ShouldProcess($server.name, "Disabling restore job $($ls.restorejob)")) { + try { + Write-Message -Message ("Disabling restore job " + $ls.restorejob) -Level Verbose + $null = Set-DbaAgentJob -SqlInstance $instance -SqlCredential $sqlcredential -Job $ls.restorejob -Disabled + } + catch { + $recoverResult = "Failed" + $comment = "Something went wrong disabling the restore job." + Stop-Function -Message "Something went wrong disabling the restore job.`n$($_)" -ErrorRecord $_ -Target $server.name + } } - } - - # Check for the last time if everything is up-to-date - if ($latestBackupSource.Name -eq [string]($latestrestore.last_restored_file).Split('\')[-1]) { + + if ($recoverResult -ne 'Failed') { # Check if the database needs to recovered to its normal state if ($NoRecovery -eq $false) { if ($PSCmdlet.ShouldProcess($secondarydb, "Restoring database with recovery")) { Write-Message -Message "Restoring the database to it's normal state" -Level Verbose - $query = "RESTORE DATABASE [$secondarydb] WITH RECOVERY" - $server.Query($query) + try { + $query = "RESTORE DATABASE [$secondarydb] WITH RECOVERY" + $server.Query($query) + + } + catch { + $recoverResult = "Failed" + $comment = "Something went wrong restoring the database to a normal state." + Stop-Function -Message "Something went wrong restoring the database to a normal state.`n$($_)" -ErrorRecord $_ -Target $secondarydb + } } } else { - Write-Message -Message "Skipping restore with recovery" -Level Output + $comment = "Skipping restore with recovery." + Write-Message -Message "Skipping restore with recovery" -Level Verbose } + + Write-Message -Message ("Finished Recovery for $secondarydb") -Level Verbose } - - Write-Message -Message ("Finished Recovery for $secondarydb") -Level Output - + # Reset the log ship details $logshipping_details = $null - - } # database in restorable mode - } # foreach ls details - } # ls details are not null - } # foreach database - } # process + + [PSCustomObject]@{ + ComputerName = $server.ComputerName + InstanceName = $server.InstanceName + SqlInstance = $server.DomainInstanceName + Database = $secondarydb + RecoverResult = $recoverResult + Comment = $comment + } + + } + } + } + Write-Progress -Activity $activity -Completed + $stepCounter = 0 + } + } } function Invoke-DbaPfRelog { <# @@ -55130,6 +55230,7 @@ function Invoke-DbaPfRelog { .NOTES Tags: Performance, DataCollector, PerfCounter, Relog + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -55879,6 +55980,7 @@ function Invoke-DbatoolsRenameHelper { Prompts you for confirmation before executing any changing operations within the command .NOTES + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -56090,8 +56192,9 @@ function Invoke-DbaWhoIsActive { .NOTES Tags: AdamMechanic, WhoIsActive, SpWhoIsActive - dbatools PowerShell module (https://dbatools.io) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -56307,6 +56410,7 @@ function Invoke-DbaXeReplay { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -57024,6 +57128,7 @@ function Measure-DbaBackupThroughput { .NOTES Tags: Backup, Database + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -57499,6 +57604,7 @@ function Mount-DbaDatabase { .NOTES Tags: Database + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -57655,9 +57761,8 @@ function Move-DbaRegisteredServer { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Author: Chrissy LeMaire (@cl) Tags: RegisteredServer, CMS - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -57781,9 +57886,8 @@ function Move-DbaRegisteredServerGroup { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Author: Chrissy LeMaire (@cl) Tags: RegisteredServer, CMS - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -59703,7 +59807,7 @@ function New-DbaClientAlias { .NOTES Tags: Alias - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -60054,7 +60158,7 @@ function New-DbaComputerCertificate { .NOTES Tags: Certificate - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -60478,6 +60582,7 @@ function New-DbaConnectionString { .NOTES Tags: Connection, Connect, ConnectionString + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -60677,9 +60782,10 @@ function New-DbaConnectionStringBuilder { .NOTES Author: zippy1981 Tags: SqlBuild, ConnectionString, Connection - - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2017 Chrissy LeMaire + Tags: RegisteredServer, CMS + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -60806,7 +60912,7 @@ Prompts you for confirmation before executing any changing operations within the .NOTES Tags: Certificate - +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -61110,7 +61216,7 @@ Prompts you for confirmation before executing any changing operations within the .NOTES Tags: Certificate - +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -61249,7 +61355,7 @@ Prompts you for confirmation before executing any changing operations within the .NOTES Tags: Certificate - +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -62498,7 +62604,7 @@ function New-DbaScriptingOption { .NOTES Tags: Migration, Backup, DR - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -62548,7 +62654,7 @@ Prompts you for confirmation before executing any changing operations within the .NOTES Tags: Certificate - +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -62918,6 +63024,7 @@ function New-DbaXESession { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -62998,6 +63105,7 @@ function New-DbaXESmartCsvWriter { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -63115,6 +63223,7 @@ function New-DbaXESmartEmail { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -63239,9 +63348,11 @@ function New-DbaXESmartQueryExec { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT + SmartTarget: by Gianluca Sartori (@spaghettidba) .LINK https://dbatools.io/New-DbaXESmartQueryExec @@ -63350,6 +63461,7 @@ function New-DbaXESmartReplay { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -63487,6 +63599,7 @@ function New-DbaXESmartTableWriter { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -63859,6 +63972,7 @@ function Read-DbaAuditFile { .NOTES Tags: ExtendedEvent, Audit + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -64012,8 +64126,9 @@ function Read-DbaBackupHeader { .NOTES Tags: DisasterRecovery, Backup, Restore - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -64392,6 +64507,7 @@ function Read-DbaTraceFile { .NOTES Tags: Security, Trace + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -64674,6 +64790,7 @@ function Read-DbaXEFile { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -65758,7 +65875,7 @@ function Remove-DbaClientAlias { .NOTES Tags: Alias - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -65963,7 +66080,7 @@ function Remove-DbaComputerCertificate { .NOTES Tags: Certificate - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -66064,7 +66181,7 @@ Prompts you for confirmation before executing any changing operations within the .NOTES Tags: Delete, Databases - +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -66935,6 +67052,7 @@ Piped certificate objects .NOTES Tags: Certificate +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -67095,7 +67213,7 @@ function Remove-DbaDbMasterKey { .NOTES Tags: Certificate - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -67689,8 +67807,8 @@ Prompts you for confirmation before executing any changing operations within the Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES -Tags: Delete, Logins - +Tags: Delete, Login +Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -67824,7 +67942,7 @@ function Remove-DbaNetworkCertificate { .NOTES Tags: Certificate - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -68293,6 +68411,7 @@ function Remove-DbaPfDataCollectorCounter { .NOTES Tags: PerfMon + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -68424,6 +68543,7 @@ function Remove-DbaPfDataCollectorSet { .NOTES Tags: PerfMon + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -68565,9 +68685,8 @@ function Remove-DbaRegisteredServer { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Author: Chrissy LeMaire (@cl) Tags: RegisteredServer, CMS - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -68671,9 +68790,8 @@ function Remove-DbaRegisteredServerGroup { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Author: Chrissy LeMaire (@cl) Tags: RegisteredServer, CMS - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -68947,6 +69065,7 @@ function Remove-DbaTrace { .NOTES Tags: Security, Trace + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -69055,6 +69174,7 @@ function Remove-DbaXESession { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -69180,6 +69300,7 @@ function Remove-DbaXESmartTarget { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -70534,8 +70655,9 @@ function Repair-DbaServerName { .NOTES Tags: SPN - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -70833,6 +70955,9 @@ function Reset-DbaAdmin { .NOTES Tags: WSMan Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com + License: MIT https://opensource.org/licenses/MIT Requires: Admin access to server (not SQL Services), Remoting must be enabled and accessible if $SqlInstance is not local @@ -77499,8 +77624,9 @@ function Set-DbaMaxMemory { .NOTES Tags: MaxMemory, Memory - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -77657,7 +77783,7 @@ function Set-DbaNetworkCertificate { .NOTES Tags: Certificate - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -77855,9 +77981,9 @@ function Set-DbaPowerPlan { .NOTES Tags: PowerPlan, OS, Configure Requires: WMI access to servers - - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -79620,7 +79746,8 @@ function Show-DbaDbList { Specify a database to have selected when the window appears. .NOTES - Tags: Database + Tags: Database, FileSystem + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -79814,7 +79941,8 @@ function Show-DbaServerFileSystem { If this switch is enabled, you will be prompted for confirmation before executing any operations that change state. .NOTES - Tags: Storage + Tags: Storage, FileSystem + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -80047,6 +80175,7 @@ function Start-DbaAgentJob { .NOTES Tags: Job, Agent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -80352,11 +80481,7 @@ function Start-DbaMigration { .NOTES Tags: Migration - Author: Chrissy LeMaire - Limitations: Doesn't cover what it doesn't cover (certificates, etc) - SQL Server 2000 login migrations have some limitations (server perms aren't migrated) - SQL Server 2000 databases cannot be directly migrated to SQL Server 2012 and above. - Logins within SQL Server 2012 and above logins cannot be migrated to SQL Server 2008 R2 and below. + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -80663,6 +80788,7 @@ function Start-DbaPfDataCollectorSet { .NOTES Tags: PerfMon + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -80960,6 +81086,7 @@ function Start-DbaTrace { .NOTES Tags: Security, Trace + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -81225,6 +81352,7 @@ function Start-DbaXESmartTarget { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -81436,6 +81564,7 @@ function Stop-DbaAgentJob { .NOTES Tags: Job, Agent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -81561,6 +81690,7 @@ function Stop-DbaPfDataCollectorSet { .NOTES Tags: PerfMon + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -81700,6 +81830,7 @@ function Stop-DbaProcess { .NOTES Tags: Processes + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -81967,6 +82098,7 @@ function Stop-DbaTrace { .NOTES Tags: Security, Trace + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -82205,6 +82337,7 @@ function Stop-DbaXESmartTarget { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -82284,9 +82417,6 @@ function Sync-DbaLoginPermission { .NOTES Tags: Migration, Login Author: Chrissy LeMaire (@cl), netnerds.net - Requires: sysadmin access on SQL Servers - Limitations: Does not support Application Roles yet - Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -83262,8 +83392,7 @@ function Test-DbaConnection { .NOTES Tags: CIM, Test, Connection - Author: Chrissy LeMaire - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -83441,8 +83570,9 @@ function Test-DbaConnectionAuthScheme { .NOTES Tags: SPN, Kerberos - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -83563,6 +83693,7 @@ function Test-DbaDbCollation { .NOTES Tags: Database, Collation + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -83675,6 +83806,7 @@ function Test-DbaDbCompatibility { .NOTES Tags: Database, Compatibility + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -84415,7 +84547,7 @@ function Test-DbaDbVirtualLogFile { .NOTES Tags: VLF, Database - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -84899,10 +85031,9 @@ function Test-DbaDiskAllocation { .NOTES Tags: CIM, Storage - Requires: Windows sysadmin access on SQL Servers - - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -85121,9 +85252,8 @@ function Test-DbaDiskSpeed { Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. .NOTES - Author: Chrissy LeMaire Tags: Performance - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -85669,7 +85799,7 @@ function Test-DbaLastBackup { .NOTES Tags: DisasterRecovery, Backup, Restore - + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -86943,8 +87073,9 @@ function Test-DbaMaxMemory { .NOTES Tags: MaxMemory, Memory - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -87385,6 +87516,7 @@ function Test-DbaNetworkLatency { .NOTES Tags: Performance, Network + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -87590,11 +87722,8 @@ function Test-DbaPath { .NOTES Tags: Path, ServiceAccount Author: Chrissy LeMaire (@cl), netnerds.net - Requires: Admin access to server (not SQL Services), - Remoting must be enabled and accessible if $SqlInstance is not local - - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -87708,10 +87837,9 @@ function Test-DbaPowerPlan { .NOTES Tags: PowerPlan - Requires: WMI access to servers - - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -88253,9 +88381,9 @@ function Test-DbaServerName { .NOTES Tags: SPN, ServerName - - dbatools PowerShell module (https://dbatools.io, clemaire@gmail.com) - Copyright (C) 2016 Chrissy LeMaire + Author: Chrissy LeMaire (@cl), netnerds.net + Website: https://dbatools.io + Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT .LINK @@ -89270,6 +89398,7 @@ function Uninstall-DbaWatchUpdate { .NOTES Tags: JustForFun, Module + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -89702,6 +89831,7 @@ function Update-Dbatools { .NOTES Tags: Module + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -89778,11 +89908,10 @@ function Watch-DbaDbLogin { .NOTES Tags: Login Author: Chrissy LeMaire (@cl), netnerds.net - Requires: sysadmin access on all SQL Servers for the most accurate results - Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT + Requires: sysadmin access on all SQL Servers for the most accurate results .LINK https://dbatools.io/Watch-DbaDbLogin @@ -89921,6 +90050,7 @@ function Watch-DbaUpdate { .NOTES Tags: JustForFun, Module + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -90019,6 +90149,7 @@ function Watch-DbaXESession { .NOTES Tags: ExtendedEvent, XE, XEvent + Author: Chrissy LeMaire (@cl), netnerds.net Website: https://dbatools.io Copyright: (C) Chrissy LeMaire, clemaire@gmail.com License: MIT https://opensource.org/licenses/MIT @@ -95877,9 +96008,9 @@ function New-DbaLogShippingPrimaryDatabase { } # Check the MonitorServer - if ($Force -and -not $MonitorServer) { + if (-not $MonitorServer -and $Force) { + Write-Message -Message "Setting monitor server to $SqlInstance." -Level Verbose $MonitorServer = $SqlInstance - Write-Message -Message "Setting monitor server to $MonitorServer." -Level Verbose } # Check the MonitorServerSecurityMode if it's SQL Server authentication @@ -95958,7 +96089,7 @@ function New-DbaLogShippingPrimaryDatabase { # Execute the query to add the log shipping primary if ($PSCmdlet.ShouldProcess($SqlServer, ("Configuring logshipping for primary database $Database on $SqlInstance"))) { try { - Write-Message -Message "Configuring logshipping for primary database $Database." -Level Output + Write-Message -Message "Configuring logshipping for primary database $Database." -Level Verbose Write-Message -Message "Executing query:`n$Query" -Level Verbose $server.Query($Query) } @@ -95968,7 +96099,7 @@ function New-DbaLogShippingPrimaryDatabase { } } - Write-Message -Message "Finished adding the primary database $Database to log shipping." -Level Output + Write-Message -Message "Finished adding the primary database $Database to log shipping." -Level Verbose } function New-DbaLogShippingPrimarySecondary { @@ -96099,7 +96230,7 @@ function New-DbaLogShippingPrimarySecondary { # Execute the query to add the log shipping primary if ($PSCmdlet.ShouldProcess($SqlInstance, ("Configuring logshipping connecting the primary database $PrimaryDatabase to secondary database $SecondaryDatabase on $SqlInstance"))) { try { - Write-Message -Message "Configuring logshipping connecting the primary database $PrimaryDatabase to secondary database $SecondaryDatabase on $SqlInstance." -Level Output + Write-Message -Message "Configuring logshipping connecting the primary database $PrimaryDatabase to secondary database $SecondaryDatabase on $SqlInstance." -Level Verbose Write-Message -Message "Executing query:`n$Query" -Level Verbose $ServerPrimary.Query($Query) } @@ -96109,7 +96240,7 @@ function New-DbaLogShippingPrimarySecondary { } } - Write-Message -Message "Finished configuring of primary database $PrimaryDatabase to secondary database $SecondaryDatabase." -Level Output + Write-Message -Message "Finished configuring of primary database $PrimaryDatabase to secondary database $SecondaryDatabase." -Level Verbose } function New-DbaLogShippingSecondaryDatabase { @@ -96341,7 +96472,7 @@ function New-DbaLogShippingSecondaryDatabase { # Execute the query to add the log shipping primary if ($PSCmdlet.ShouldProcess($SqlServer, ("Configuring logshipping for secondary database $SecondaryDatabase on $SqlInstance"))) { try { - Write-Message -Message "Configuring logshipping for secondary database $SecondaryDatabase on $SqlInstance." -Level Output + Write-Message -Message "Configuring logshipping for secondary database $SecondaryDatabase on $SqlInstance." -Level Verbose Write-Message -Message "Executing query:`n$Query" -Level Verbose $ServerSecondary.Query($Query) } @@ -96351,7 +96482,7 @@ function New-DbaLogShippingSecondaryDatabase { } } - Write-Message -Message "Finished adding the secondary database $SecondaryDatabase to log shipping." -Level Output + Write-Message -Message "Finished adding the secondary database $SecondaryDatabase to log shipping." -Level Verbose } function New-DbaLogShippingSecondaryPrimary { @@ -96500,7 +96631,7 @@ function New-DbaLogShippingSecondaryPrimary { } # Check the MonitorServer - if ($Force -and -not $MonitorServer) { + if (-not $MonitorServer -and $Force) { $MonitorServer = $SqlInstance Write-Message -Message "Setting monitor server to $MonitorServer." -Level Verbose } @@ -96573,7 +96704,7 @@ function New-DbaLogShippingSecondaryPrimary { # Execute the query to add the log shipping primary if ($PSCmdlet.ShouldProcess($SqlServer, ("Configuring logshipping making settings for the primary database to secondary database on $SqlInstance"))) { try { - Write-Message -Message "Configuring logshipping making settings for the primary database." -Level Output + Write-Message -Message "Configuring logshipping making settings for the primary database." -Level Verbose Write-Message -Message "Executing query:`n$Query" -Level Verbose $ServerSecondary.Query($Query) } @@ -96583,7 +96714,7 @@ function New-DbaLogShippingSecondaryPrimary { } } - Write-Message -Message "Finished configuring of secondary database to primary database $PrimaryDatabase." -Level Output + Write-Message -Message "Finished configuring of secondary database to primary database $PrimaryDatabase." -Level Verbose } function New-DbaMessageLevelModifier { <# @@ -99861,12 +99992,23 @@ function Write-HostColor { } } } +function Write-ProgressHelper { + # thanks adam! + # https://www.adamtheautomator.com/building-progress-bar-powershell-scripts/ + param ( + [int]$StepNumber, + [string]$Activity, + [string]$Message, + [int]$TotalSteps = 3 + ) + Write-Progress -Activity $Activity -Status $Message -PercentComplete (($StepNumber / $TotalSteps) * 100) +} # SIG # Begin signature block # MIIcYgYJKoZIhvcNAQcCoIIcUzCCHE8CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUJNnDHuxm9LVi4Nxbi1VRTySC -# 5HGggheRMIIFGjCCBAKgAwIBAgIQAsF1KHTVwoQxhSrYoGRpyjANBgkqhkiG9w0B +# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUovlNvMwRRS7eqILstpQ+GUHI +# nYeggheRMIIFGjCCBAKgAwIBAgIQAsF1KHTVwoQxhSrYoGRpyjANBgkqhkiG9w0B # AQsFADByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD # VQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFz # c3VyZWQgSUQgQ29kZSBTaWduaW5nIENBMB4XDTE3MDUwOTAwMDAwMFoXDTIwMDUx @@ -99997,22 +100139,22 @@ function Write-HostColor { # c3N1cmVkIElEIENvZGUgU2lnbmluZyBDQQIQAsF1KHTVwoQxhSrYoGRpyjAJBgUr # DgMCGgUAoHgwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKAADAZBgkqhkiG9w0BCQMx # DAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkq -# hkiG9w0BCQQxFgQU6Dyf+zokEmRQLWbOzvcE1uaEpvcwDQYJKoZIhvcNAQEBBQAE -# ggEARG+jfDoA/oCTgdWTq2de9sllKaVhUAYPafr8+dTmucLOKMLii67WrIinb296 -# xl30NYGPbRDpL2kJxPkR8pcsoT+0TWs4KZRXDnBnX7LfzPNOuUQlCvz2WRDHXakP -# kwheIaEHoFO0fc6IeA2kngWgikC8MDDCtJ2gTt529uIeHifSPmM4yui66mtMrqZ5 -# Ear9hhh8hzuMMKfCNrsCKby/80L99HB3kYGnoVx1qRLgzMTw5ySdUPc7xZGcD1+B -# m2pHLmuBwpFCSZx1vD7vRIRggTohGFTyUQqnvxKBJ9Kodg8kfQqS3BOkF/Hio8ub -# xRntINAdX/freIcu8T3fnA2EM6GCAg8wggILBgkqhkiG9w0BCQYxggH8MIIB+AIB +# hkiG9w0BCQQxFgQUIXf8FqFJTFKTkpTmapkzUgDTcAcwDQYJKoZIhvcNAQEBBQAE +# ggEATQQj5KqGP6Ef9qGnSPFVaNe1dY0E6sqtfgUHxRz9/W9yfWpeUsS3jjSWQ445 +# yAFHcZ6Sa/iuJzHHxcHG6oCutetM+C9vCOE/qbqntQcB0/9WDb4/zocr/H9jl3bg +# DVS5DFqMtd1eIWn3HwgADsXUjM28xBBiWxiQliv5tom9exvjlE9FBWRUn/placjm +# kmQKC1aFxuINMvMIXiqF/hLkmkCTTAijPjQIEGdRXwMKOhCKmwGy5AnB9dlxyn8B +# OGGdv+FbGY5pdZO0CjAr8yc5vrvBNp3xv2FzefaNjhmQJ6PIEk4Nx3eo5JluJqZo +# TdE5fXllmKuIOAhEWTNmZg5pp6GCAg8wggILBgkqhkiG9w0BCQYxggH8MIIB+AIB # ATB2MGIxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNV # BAsTEHd3dy5kaWdpY2VydC5jb20xITAfBgNVBAMTGERpZ2lDZXJ0IEFzc3VyZWQg # SUQgQ0EtMQIQAwGaAjr/WLFr1tXq5hfwZjAJBgUrDgMCGgUAoF0wGAYJKoZIhvcN -# AQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTgwOTA5MTYxNDUwWjAj -# BgkqhkiG9w0BCQQxFgQUC4fp+UKrwhi7T7+jHr1BaIliT7wwDQYJKoZIhvcNAQEB -# BQAEggEAUKk9cMS/PdF9HSxPg67F2gwypPDQ9IsNkfgzf7nfGn2udRsajT2mIpgw -# CjeSVbnisEVavRFhwJCdtz5oE96O4y6+dpBJTglLEKiLdi5KdwRsorTPDkxRrqsb -# DUTRz9zj0G929z7Bn4nd/aV5KpIeJXLZOQKy5VZwmR1dQytfisA18TF+jhUOMSuR -# rqCoIgxHDufFdc2Vi67LMHsxiKrsLevE2X1OHcaRR/ObT9jz21UnhUjXb2J6P54j -# 5kHA4MI/CTMSZk1HrfgfVVGuZNKud7ZfXAydkhk9G57eLDEkfW7LWVQ5iuGvu4pk -# 5ZZPUd3Y29jQnzi47Z4+2dNevQ/Uug== +# AQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTgwOTExMTQ0MDE2WjAj +# BgkqhkiG9w0BCQQxFgQUT7KhZvc2MQYbxivp/3EDrP1Tp3UwDQYJKoZIhvcNAQEB +# BQAEggEAJwKCX1MwfWSg5WiBZlQpe2YIsVRmHveGbei8oOAYcCIujcJay+7i4K8/ +# 4N9+eU//yDEg984lT7vQ+3n9qBp/j2qvQp6nv2hOCp6OfUi9mKnN1KMsmoV6SXHl +# 92aEAagLLusrIczITTVaoCpgIw+0zhmBAPgcpz1Na/y03Neitkt0IxE+JP8WR0hu +# j/yVwZSFY1IRtgfF/IrXl+HcDM7NCT0XX8EhjvKyPKO641gWg6vjaSzhlw2IsEaY +# dReoTiq562PuHo1cSadJNttIWv8fXSGmSxVgUffRFil1KcP7JEswhwTiw7eVnWUV +# Tll/uh7jdIxqrnENQZb5WQLFW48Eaw== # SIG # End signature block diff --git a/bin/dbatools-index.json b/bin/dbatools-index.json index 66511235bf..7048a867f4 100644 --- a/bin/dbatools-index.json +++ b/bin/dbatools-index.json @@ -743,7 +743,7 @@ }, { "CommandName": "Export-DbaExecutionPlan", - "Description": "Exports execution plans to disk. Can pipe from Export-DbaExecutionPlan\n\nThanks to\n https://www.simple-talk.com/sql/t-sql-programming/dmvs-for-query-plan-metadata/\n and\n http://www.scarydba.com/2017/02/13/export-plans-cache-sqlplan-file/\nfor the idea and query.", + "Description": "Exports execution plans to disk. Can pipe from Get-DbaExecutionPlan\n\nThanks to\n https://www.simple-talk.com/sql/t-sql-programming/dmvs-for-query-plan-metadata/\n and\n http://www.scarydba.com/2017/02/13/export-plans-cache-sqlplan-file/\nfor the idea and query.", "Tags": [ "Performance", "ExecutionPlan" @@ -753,7 +753,7 @@ "Synopsis": "Exports execution plans to disk.", "Name": "Export-DbaExecutionPlan", "Links": "https://dbatools.io/Export-DbaExecutionPlan", - "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaExecutionPlan -SqlInstance sqlserver2014a\r\n\r\nExports all execution plans for sqlserver2014a.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaExecutionPlan -SqlInstance sqlserver2014a -Database db1, db2 -SinceLastExecution \u00277/1/2016 10:47:00\u0027\r\n\r\nExports all execution plans for databases db1 and db2 on sqlserver2014a since July 1, 2016 at 10:47 AM.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaExecutionPlan -SqlInstance sqlserver2014a -Path C:\\Temp\r\n\r\nExports all execution plans for sqlserver2014a. Files saved in to C:\\Temp\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaExecutionPlan -SqlInstance sqlserver2014a -Database db1, db2 -SinceLastExecution \u00272016-07-01 10:47:00\u0027 \r\n-Path C:\\Temp\r\n\r\nExports all execution plans for databases db1 and db2 on sqlserver2014a since July 1, 2016 at 10:47 AM. Files saved in \r\nto C:\\Temp\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaExecutionPlan -SqlInstance sqlserver2014a | Export-DbaExecutionPlan -Path C:\\Temp\r\n\r\nGets all execution plans for sqlserver2014a. Using Pipeline exports them all to C:\\Temp\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaExecutionPlan -SqlInstance sqlserver2014a | Export-DbaExecutionPlan -Path C:\\Temp -WhatIf\r\n\r\nGets all execution plans for sqlserver2014a. Then shows what would happen if the results where piped to \r\nExport-DbaExecutionPlan\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Export-DbaInstance", @@ -856,12 +856,12 @@ "User", "Export" ], - "Syntax": "\r\nExport-DbaUser [-SqlInstance] \u003cDbaInstanceParameter\u003e [[-SqlCredential] \u003cPSCredential\u003e] [[-Database] \u003cObject[]\u003e] \r\n[[-ExcludeDatabase] \u003cObject[]\u003e] [[-User] \u003cObject[]\u003e] [[-DestinationVersion] \u003cString\u003e] [[-FilePath] \u003cString\u003e] \r\n[-NoClobber] [-Append] [-EnableException] [[-ScriptingOptionsObject] \u003cScriptingOptions\u003e] [-ExcludeGoBatchSeparator] \r\n[\u003cCommonParameters\u003e]\r\n\r\n\r\n\r\n\r\n", + "Syntax": "\r\nExport-DbaUser [-SqlInstance] \u003cDbaInstanceParameter\u003e [[-SqlCredential] \u003cPSCredential\u003e] [[-Database] \u003cObject[]\u003e] \r\n[[-ExcludeDatabase] \u003cObject[]\u003e] [[-User] \u003cObject[]\u003e] [[-DestinationVersion] \u003cString\u003e] [[-Path] \u003cString\u003e] [-NoClobber] \r\n[-Append] [-EnableException] [[-ScriptingOptionsObject] \u003cScriptingOptions\u003e] [-ExcludeGoBatchSeparator] \r\n[\u003cCommonParameters\u003e]\r\n\r\n\r\n\r\n\r\n", "Author": "Claudio Silva (@ClaudioESSilva)", "Synopsis": "Exports users creation and its permissions to a T-SQL file or host.", "Name": "Export-DbaUser", "Links": "https://dbatools.io/Export-DbaUser", - "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sql2005 -FilePath C:\\temp\\sql2005-users.sql\r\n\r\nExports SQL for the users in server \"sql2005\" and writes them to the file \"C:\\temp\\sql2005-users.sql\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2014a $scred -FilePath C:\\temp\\users.sql -Append\r\n\r\nAuthenticates to sqlserver2014a using SQL Authentication. Exports all users to C:\\temp\\users.sql, and appends to the \r\nfile if it exists. If not, the file will be created.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2014a -User User1, User2 -FilePath C:\\temp\\users.sql\r\n\r\nExports ONLY users User1 and User2 from sqlsever2014a to the file C:\\temp\\users.sql\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2008 -User User1 -FilePath C:\\temp\\users.sql -DestinationVersion \r\nSQLServer2016\r\n\r\nExports user User1 from sqlsever2008 to the file C:\\temp\\users.sql with syntax to run on SQL Server 2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -FilePath C:\\temp\\users.sql\r\n\r\nExports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\\temp\\users.sql file.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e$options = New-DbaScriptingOption\r\n\r\n$options.ScriptDrops = $false\r\n$options.WithDependencies = $true\r\n\r\nExport-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -FilePath C:\\temp\\users.sql -ScriptingOptionsObject $options\r\n\r\nExports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\\temp\\users.sql file.\r\nIt will not script drops but will script dependencies.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -FilePath C:\\temp\\users.sql -ExcludeGoBatchSeparator\r\n\r\nExports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\\temp\\users.sql file without the \u0027GO\u0027 \r\nbatch separator.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sql2005 -Path C:\\temp\\sql2005-users.sql\r\n\r\nExports SQL for the users in server \"sql2005\" and writes them to the file \"C:\\temp\\sql2005-users.sql\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2014a $scred -Path C:\\temp\\users.sql -Append\r\n\r\nAuthenticates to sqlserver2014a using SQL Authentication. Exports all users to C:\\temp\\users.sql, and appends to the \r\nfile if it exists. If not, the file will be created.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2014a -User User1, User2 -Path C:\\temp\\users.sql\r\n\r\nExports ONLY users User1 and User2 from sqlsever2014a to the file C:\\temp\\users.sql\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2008 -User User1 -Path C:\\temp\\users.sql -DestinationVersion SQLServer2016\r\n\r\nExports user User1 from sqlsever2008 to the file C:\\temp\\users.sql with syntax to run on SQL Server 2016\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -Path C:\\temp\\users.sql\r\n\r\nExports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\\temp\\users.sql file.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e$options = New-DbaScriptingOption\r\n\r\n$options.ScriptDrops = $false\r\n$options.WithDependencies = $true\r\n\r\nExport-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -Path C:\\temp\\users.sql -ScriptingOptionsObject $options\r\n\r\nExports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\\temp\\users.sql file.\r\nIt will not script drops but will script dependencies.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaUser -SqlInstance sqlserver2008 -Database db1,db2 -Path C:\\temp\\users.sql -ExcludeGoBatchSeparator\r\n\r\nExports ONLY users from db1 and db2 database on sqlserver2008 server, to the C:\\temp\\users.sql file without the \u0027GO\u0027 \r\nbatch separator.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Export-DbaXECsv", @@ -880,7 +880,7 @@ }, { "CommandName": "Export-DbaXESessionTemplate", - "Description": "Exports an XESession XML Template either from the dbatools repository or a file you specify. Exports to \"$home\\Documents\\SQL Server Management Studio\\Templates\\XEventTemplates\" by default", + "Description": "Exports an XESession XML Template either from the Target SQL Server or XE Session(s) output by Get-DbaXESession. Exports to \"$home\\Documents\\SQL Server Management Studio\\Templates\\XEventTemplates\" by default", "Tags": [ "ExtendedEvent", "XE", @@ -888,10 +888,10 @@ ], "Syntax": "\r\nExport-DbaXESessionTemplate [[-SqlInstance] \u003cDbaInstanceParameter[]\u003e] [[-SqlCredential] \u003cPSCredential\u003e] [[-Session] \r\n\u003cObject[]\u003e] [[-Path] \u003cString\u003e] [[-InputObject] \u003cSession[]\u003e] [-EnableException] [\u003cCommonParameters\u003e]\r\n\r\n\r\n\r\n\r\n", "Author": "Chrissy LeMaire (@cl), netnerds.net", - "Synopsis": "Exports an XESession XML Template.", + "Synopsis": "Exports an XESession XML Template using XE Session(s) output by Get-DbaXESession", "Name": "Export-DbaXESessionTemplate", "Links": "https://dbatools.io/Export-DbaXESessionTemplate", - "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaXESessionTemplate -SqlInstance sql2017 -Path C:\\temp\\xe\r\n\r\nExports XE Session Template to the C:\\temp\\xe folder.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaXESession -SqlInstance sql2017 -Session session_health | Export-DbaXESessionTemplate -Path C:\\temp\r\n\r\nReturns a new XE Session object from sql2017 then adds an event, an action then creates it.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eExport-DbaXESessionTemplate -SqlInstance sql2017 -Path C:\\temp\\xe\r\n\r\nExports an XESession XML Template for all Extended Event Sessions on sql2017 to the C:\\temp\\xe folder.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaXESession -SqlInstance sql2017 -Session system_health | Export-DbaXESessionTemplate -Path C:\\temp\\xe\r\n\r\nGets the system_health Extended Events Session from sql2017 and then exports as an XESession XML Template to C:\\temp\\xe\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaAgentJob", @@ -905,7 +905,7 @@ "Synopsis": "Find-DbaAgentJob finds agent job/s that fit certain search filters.", "Name": "Find-DbaAgentJob", "Links": "https://dbatools.io/Find-DbaAgentJob", - "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -JobName backup*\r\n\r\nReturns all agent job(s) that have backup in the name\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01, Dev02 -JobName Mybackup\r\n\r\nReturns all agent job(s) that are named exactly Mybackup\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -LastUsed 10\r\n\r\nReturns all agent job(s) that have not ran in 10 days\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -IsDisabled -IsNoEmailNotification -IsNotScheduled\r\n\r\nReturns all agent job(s) that are either disabled, have no email notification or don\u0027t have a schedule. returned with \r\ndetail\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$servers | Find-DbaAgentJob -IsFailed | Start-DbaAgentJob\r\n\r\nFinds all failed job then starts them. Consider using a -WhatIf at the end of Start-DbaAgentJob to see what it\u0027ll do \r\nfirst\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -LastUsed 10 -Exclude \"Yearly - RollUp Workload\", \"SMS - Notification\"\r\n\r\nReturns all agent jobs that havent ran in the last 10 ignoring jobs \"Yearly - RollUp Workload\" and \"SMS - Notification\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -Category \"REPL-Distribution\", \"REPL-Snapshot\" -Detailed | Format-Table \r\n-AutoSize -Wrap\r\n\r\nReturns all job/s on Dev01 that are in either category \"REPL-Distribution\" or \"REPL-Snapshot\" with detailed output\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01, Dev02 -IsFailed -Since \u00277/1/2016 10:47:00\u0027\r\n\r\nReturns all agent job(s) that have failed since July of 2016 (and still have history in msdb)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 9 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance CMSServer -Group Production | Find-DbaAgentJob -Disabled -IsNotScheduled | \r\nFormat-Table -AutoSize -Wrap\r\n\r\nQueries CMS server to return all SQL instances in the Production folder and then list out all agent jobs that have \r\neither been disabled or have no schedule.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -JobName *backup*\r\n\r\nReturns all agent job(s) that have backup in the name\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01, Dev02 -JobName Mybackup\r\n\r\nReturns all agent job(s) that are named exactly Mybackup\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -LastUsed 10\r\n\r\nReturns all agent job(s) that have not ran in 10 days\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -IsDisabled -IsNoEmailNotification -IsNotScheduled\r\n\r\nReturns all agent job(s) that are either disabled, have no email notification or don\u0027t have a schedule. returned with \r\ndetail\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$servers | Find-DbaAgentJob -IsFailed | Start-DbaAgentJob\r\n\r\nFinds all failed job then starts them. Consider using a -WhatIf at the end of Start-DbaAgentJob to see what it\u0027ll do \r\nfirst\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -LastUsed 10 -Exclude \"Yearly - RollUp Workload\", \"SMS - Notification\"\r\n\r\nReturns all agent jobs that havent ran in the last 10 days ignoring jobs \"Yearly - RollUp Workload\" and \"SMS - \r\nNotification\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01 -Category \"REPL-Distribution\", \"REPL-Snapshot\" -Detailed | Format-Table \r\n-AutoSize -Wrap\r\n\r\nReturns all job/s on Dev01 that are in either category \"REPL-Distribution\" or \"REPL-Snapshot\" with detailed output\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaAgentJob -SqlInstance Dev01, Dev02 -IsFailed -Since \u00272016-07-01 10:47:00\u0027\r\n\r\nReturns all agent job(s) on Dev01 and Dev02 that have failed since July of 2016 (and still have history in msdb)\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 9 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance CMSServer -Group Production | Find-DbaAgentJob -Disabled -IsNotScheduled | \r\nFormat-Table -AutoSize -Wrap\r\n\r\nQueries CMS server to return all SQL instances in the Production folder and then list out all agent jobs that have \r\neither been disabled or have no schedule.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaBackup", @@ -1068,12 +1068,12 @@ "CommandName": "Find-DbaUnusedIndex", "Description": "This command will help you to find Unused indexes on a database or a list of databases\n\nAlso tells how much space you can save by dropping the index.\nWe show the type of compression so you can make a more considered decision.\nFor now only supported for CLUSTERED and NONCLUSTERED indexes\n\nYou can select the indexes you want to drop on the gridview and by clicking OK the drop statement will be generated.", "Tags": "Index", - "Syntax": "\r\nFind-DbaUnusedIndex [-SqlInstance] \u003cDbaInstanceParameter[]\u003e [[-SqlCredential] \u003cPSCredential\u003e] [[-Database] \u003cObject[]\u003e] \r\n[[-ExcludeDatabase] \u003cObject[]\u003e] [[-FilePath] \u003cString\u003e] [-NoClobber] [-Append] [-IgnoreUptime] [-EnableException] \r\n[-WhatIf] [-Confirm] [\u003cCommonParameters\u003e]\r\n\r\n\r\n\r\n\r\n", + "Syntax": "\r\nFind-DbaUnusedIndex [-SqlInstance] \u003cDbaInstanceParameter[]\u003e [[-SqlCredential] \u003cPSCredential\u003e] [[-Database] \u003cObject[]\u003e] \r\n[[-ExcludeDatabase] \u003cObject[]\u003e] [[-Path] \u003cString\u003e] [-NoClobber] [-Append] [-IgnoreUptime] [-EnableException] [-WhatIf] \r\n[-Confirm] [\u003cCommonParameters\u003e]\r\n\r\n\r\n\r\n\r\n", "Author": "Aaron Nelson (@SQLvariant), SQLvariant.com", "Synopsis": "Find Unused indexes", "Name": "Find-DbaUnusedIndex", "Links": "https://dbatools.io/Find-DbaUnusedIndex", - "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sql2005 -FilePath C:\\temp\\sql2005-UnusedIndexes.sql\r\n\r\nGenerates the SQL statements to drop the selected unused indexes on server \"sql2005\". The statements are written to the \r\nfile \"C:\\temp\\sql2005-UnusedIndexes.sql\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sql2005 -FilePath C:\\temp\\sql2005-UnusedIndexes.sql -Append\r\n\r\nGenerates the SQL statements to drop the selected unused indexes on server \"sql2005\". The statements are written to the \r\nfile \"C:\\temp\\sql2005-UnusedIndexes.sql\", appending if the file already exists.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sqlserver2016 -SqlCredential $cred\r\n\r\nGenerates the SQL statements to drop the selected unused indexes on server \"sqlserver2016\", using SQL Authentication to \r\nconnect to the database.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sqlserver2016 -Database db1, db2\r\n\r\nGenerates the SQL Statement to to drop selected indexes in databases db1 \u0026 db2 on server \"sqlserver2016\".\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sqlserver2016\r\n\r\nGenerates the SQL statements to drop selected indexes on all user databases.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eFine-DbaUnusedIndex -SqlInstance sqlserver2016 -IgnoreUptime\r\n\r\nGenerates the SQL statements to drop selected indexes on all user databases even if the instance has been online for \r\nless than 7 days.\r\nNote that results may not have enough detail for all indexes, so care should be taken when using them or the generated \r\nscripts. Best practice is to allow a full week to capture the mmajority of index use cases\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sql2005 -Path C:\\temp\\sql2005-UnusedIndexes.sql\r\n\r\nGenerates the SQL statements to drop the selected unused indexes on server \"sql2005\". The statements are written to the \r\nfile \"C:\\temp\\sql2005-UnusedIndexes.sql\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sql2005 -Path C:\\temp\\sql2005-UnusedIndexes.sql -Append\r\n\r\nGenerates the SQL statements to drop the selected unused indexes on server \"sql2005\". The statements are written to the \r\nfile \"C:\\temp\\sql2005-UnusedIndexes.sql\", appending if the file already exists.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sqlserver2016 -SqlCredential $cred\r\n\r\nGenerates the SQL statements to drop the selected unused indexes on server \"sqlserver2016\", using SQL Authentication to \r\nconnect to the database.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sqlserver2016 -Database db1, db2\r\n\r\nGenerates the SQL Statement to drop the selected unused indexes in databases db1 \u0026 db2 on server \"sqlserver2016\".\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eFind-DbaUnusedIndex -SqlInstance sqlserver2016\r\n\r\nGenerates the SQL statements to drop the selected unused indexes on all user databases.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eFine-DbaUnusedIndex -SqlInstance sqlserver2016 -IgnoreUptime\r\n\r\nGenerates the SQL statements to drop the selected unused indexes on all user databases even if the instance has been \r\nonline for less than 7 days.\r\nNote that results may not have enough detail for all indexes, so care should be taken when using them or the generated \r\nscripts. Best practice is to allow a full week to capture the majority of index use cases\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Find-DbaUserObject", @@ -1154,7 +1154,7 @@ "Synopsis": "Gets SQL Agent Job information for each instance(s) of SQL Server.", "Name": "Get-DbaAgentJob", "Links": "https://dbatools.io/Get-DbaAgentJob", - "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost\r\n\r\nReturns all SQL Agent Jobs on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost, sql2016\r\n\r\nReturns all SQl Agent Jobs for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost -Job BackupData, BackupDiff\r\n\r\nReturns all SQL Agent Jobs named BackupData and BackupDiff from the local SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost -ExcludeJob BackupDiff\r\n\r\nReturns all SQl Agent Jobs for the local SQL Server instances, except the BackupDiff Job.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost -NoDisabledJobs\r\n\r\nReturns all SQl Agent Jobs for the local SQL Server instances, excluding the disabled jobs.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e$servers | Get-DbaAgentJob | Out-GridView -Passthru | Start-DbaAgentJob -WhatIf\r\n\r\nFind all of your Jobs from servers in the $server collection, select the jobs you want to start then see jobs would \r\nstart if you ran Start-DbaAgentJob\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost\r\n\r\nReturns all SQL Agent Jobs on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost, sql2016\r\n\r\nReturns all SQl Agent Jobs for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost -Job BackupData, BackupDiff\r\n\r\nReturns all SQL Agent Jobs named BackupData and BackupDiff from the local SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost -ExcludeJob BackupDiff\r\n\r\nReturns all SQl Agent Jobs for the local SQL Server instances, except the BackupDiff Job.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJob -SqlInstance localhost -NoDisabledJobs\r\n\r\nReturns all SQl Agent Jobs for the local SQL Server instances, excluding the disabled jobs.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e$servers | Get-DbaAgentJob | Out-GridView -Passthru | Start-DbaAgentJob -WhatIf\r\n\r\nFind all of your Jobs from SQL Server instances in the $servers collection, select the jobs you want to start then see \r\njobs would start if you ran Start-DbaAgentJob\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgentJobCategory", @@ -1211,7 +1211,7 @@ "Synopsis": "Gets SQL Agent Job Step information for each instance(s) of SQL Server.", "Name": "Get-DbaAgentJobStep", "Links": "https://dbatools.io/Get-DbaAgentJobStep", - "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobStep -SqlInstance localhost\r\n\r\nReturns all SQL Agent Job Steps on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobStep -SqlInstance localhost, sql2016\r\n\r\nReturns all SQl Agent Job Steps for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobStep -SqlInstance localhost -Job BackupData, BackupDiff\r\n\r\nReturns all SQL Agent Job Steps for the jobs named BackupData and BackupDiff from the local SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobStep -SqlInstance localhost -ExcludeJob BackupDiff\r\n\r\nReturns all SQl Agent Job Steps for the local SQL Server instances, except for the BackupDiff Job.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobStep -SqlInstance localhost -NoDisabledJobs\r\n\r\nReturns all SQl Agent Job Steps for the local SQL Server instances, excluding the disabled jobs.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e$servers | Get-DbaAgentJobStep\r\n\r\nFind all of your Job Steps from servers in the $server collection\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobStep -SqlInstance localhost\r\n\r\nReturns all SQL Agent Job Steps on the local default SQL Server instance\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobStep -SqlInstance localhost, sql2016\r\n\r\nReturns all SQL Agent Job Steps for the local and sql2016 SQL Server instances\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobStep -SqlInstance localhost -Job BackupData, BackupDiff\r\n\r\nReturns all SQL Agent Job Steps for the jobs named BackupData and BackupDiff from the local SQL Server instance.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobStep -SqlInstance localhost -ExcludeJob BackupDiff\r\n\r\nReturns all SQL Agent Job Steps for the local SQL Server instances, except for the BackupDiff Job.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaAgentJobStep -SqlInstance localhost -NoDisabledJobs\r\n\r\nReturns all SQL Agent Job Steps for the local SQL Server instances, excluding the disabled jobs.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e$servers | Get-DbaAgentJobStep\r\n\r\nFind all of your Job Steps from SQL Server instances in the $servers collection\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaAgentLog", @@ -1362,7 +1362,7 @@ "Synopsis": "Returns backup history details for databases on a SQL Server.", "Name": "Get-DbaBackupHistory", "Links": "https://dbatools.io/Get-DbaBackupHistory", - "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance SqlInstance2014a\r\n\r\nReturns server name, database, username, backup type, date for all backups databases on SqlInstance2014a. This may \r\nreturn many rows; consider using filters that are included in other examples.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$cred = Get-Credential sqladmin\r\n\r\nGet-DbaBackupHistory -SqlInstance SqlInstance2014a -SqlCredential $cred\r\n\r\nDoes the same as above but logs in as SQL user \"sqladmin\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance SqlInstance2014a -Database db1, db2 -Since \u00277/1/2016 10:47:00\u0027\r\n\r\nReturns backup information only for databases db1 and db2 on SqlInstance2014a since July 1, 2016 at 10:47 AM.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014, pubs -Force | Format-Table\r\n\r\nReturns information only for AdventureWorks2014 and pubs and formats the results as a table.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last\r\n\r\nReturns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last -DeviceType Disk\r\n\r\nReturns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014, but \r\nonly for backups to disk.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last -DeviceType 148,107\r\n\r\nReturns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014, but \r\nonly for backups with device_type 148 and 107.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -LastFull\r\n\r\nReturns information about the most recent full backup for AdventureWorks2014 on sql2014.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 9 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Type Full\r\n\r\nReturns information about all Full backups for AdventureWorks2014 on sql2014.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 10 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sql2016 | Get-DbaBackupHistory\r\n\r\nReturns database backup information for every database on every server listed in the Central Management Server on \r\nsql2016.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 11 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance SqlInstance2014a, sql2016 -Force\r\n\r\nReturns detailed backup history for all databases on SqlInstance2014a and sql2016.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance SqlInstance2014a\r\n\r\nReturns server name, database, username, backup type, date for all database backups still in msdb history on \r\nSqlInstance2014a. This may return many rows; consider using filters that are included in other examples.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003e$cred = Get-Credential sqladmin\r\n\r\nGet-DbaBackupHistory -SqlInstance SqlInstance2014a -SqlCredential $cred\r\n\r\nDoes the same as above but connect to SqlInstance2014a as SQL user \"sqladmin\"\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance SqlInstance2014a -Database db1, db2 -Since \u00272016-07-01 10:47:00\u0027\r\n\r\nReturns backup information only for databases db1 and db2 on SqlInstance2014a since July 1, 2016 at 10:47 AM.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014, pubs -Force | Format-Table\r\n\r\nReturns information only for AdventureWorks2014 and pubs and formats the results as a table.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last\r\n\r\nReturns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last -DeviceType Disk\r\n\r\nReturns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014, but \r\nonly for backups to disk.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Last -DeviceType 148,107\r\n\r\nReturns information about the most recent full, differential and log backups for AdventureWorks2014 on sql2014, but \r\nonly for backups with device_type 148 and 107.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 8 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -LastFull\r\n\r\nReturns information about the most recent full backup for AdventureWorks2014 on sql2014.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 9 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance sql2014 -Database AdventureWorks2014 -Type Full\r\n\r\nReturns information about all Full backups for AdventureWorks2014 on sql2014.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 10 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaRegisteredServer -SqlInstance sql2016 | Get-DbaBackupHistory\r\n\r\nReturns database backup information for every database on every server listed in the Central Management Server on \r\nsql2016.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 11 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupHistory -SqlInstance SqlInstance2014a, sql2016 -Force\r\n\r\nReturns detailed backup history for all databases on SqlInstance2014a and sql2016.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaBackupInformation", @@ -1376,7 +1376,7 @@ "Synopsis": "Scan backup files and creates a set, compatible with Restore-DbaDatabase", "Name": "Get-DbaBackupInformation", "Links": "https://dbatools.io/Get-DbaBackupInformation", - "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupInformation -SqlInstance Server1 -Path c:\\backups\\ -DirectoryRecurse\r\n\r\nWill use the Server1 instance to recursively read all backup files under c:\\backups, and return a dbatools \r\nBackupHistory object\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupInformation -SqlInstance Server1 -Path c:\\backups\\ -DirectoryRecurse -ExportPath \r\nc:\\store\\BackupHistory.xml\r\n\r\n#Copy the file c:\\store\\BackupHistory.xml to another machine via preferred technique, and the on 2nd machine:\r\n\r\nGet-DbaBackupInformation -Import -Path c:\\store\\BackupHistory.xml | Restore-DbaDatabase -SqlInstance Server2 \r\n-TrustDbBackupHistory\r\n\r\nThis allows you to move backup history across servers, or to preserve backup history even after the original server has \r\nbeen purged\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupInformation -SqlInstance Server1 -Path c:\\backups\\ -DirectoryRecurse -ExportPath \r\nc:\\store\\BackupHistory.xml -PassThru |\r\n\r\nRestore-DbaDatabase -SqlInstance Server2 -TrustDbBackupHistory\r\n\r\nIn this example we gather backup information, export it to an xml file, and then pass it on through to \r\nRestore-DbaDatabase\r\nThis allows us to repeat the restore without having to scan all the backup files again\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-ChildItem c:\\backups\\ -recurse -files |\r\n\r\nWhere {$_.extension -in (\u0027.bak\u0027,\u0027.trn\u0027) -and $_.LastWriteTime -gt (get-date).AddMonths(-1)} |\r\n Get-DbaBackupInformation -SqlInstance Server1 -ExportPath c:\\backupHistory.xml\r\n\r\nThis lets you keep a record of all backup history from the last month on hand to speed up refreshes\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\\\network\\backups\r\n\r\n$Backups += Get-DbaBackupInformation -SqlInstance Server2 -NoXpDirTree -Path c:\\backups\r\n\r\nScan the unc folder \\\\network\\backups with Server1, and then scan the C:\\backups folder on\r\nServer2 not using xp_dirtree, adding the results to the first set.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e$Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\\\network\\backups -MaintenanceSolution\r\n\r\nWhen MaintenanceSolution is indicated we know we are dealing with the output from Ola Hallengren\u0027s backup scripts. So \r\nwe make sure that a FULL folder exists in the first level of Path, if not we shortcut scanning all the files as we have \r\nnothing to work with\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003e$Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\\\network\\backups -MaintenanceSolution \r\n-IgnoreLogBackup\r\n\r\nAs we know we are dealing with an Ola Hallengren style backup folder from the MaintenanceSolution switch, when \r\nIgnoreLogBackup is also included we can ignore the LOG folder to skip any scanning of log backups. Note this also means \r\nthen WON\u0027T be restored\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupInformation -SqlInstance Server1 -Path c:\\backups\\ -DirectoryRecurse\r\n\r\nWill use the Server1 instance to recursively read all backup files under c:\\backups, and return a dbatools \r\nBackupHistory object\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupInformation -SqlInstance Server1 -Path c:\\backups\\ -DirectoryRecurse -ExportPath \r\nc:\\store\\BackupHistory.xml\r\n\r\n#Copy the file c:\\store\\BackupHistory.xml to another machine via preferred technique, and the on 2nd machine:\r\n\r\nGet-DbaBackupInformation -Import -Path c:\\store\\BackupHistory.xml | Restore-DbaDatabase -SqlInstance Server2 \r\n-TrustDbBackupHistory\r\n\r\nThis allows you to move backup history across servers, or to preserve backup history even after the original server has \r\nbeen purged\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaBackupInformation -SqlInstance Server1 -Path c:\\backups\\ -DirectoryRecurse -ExportPath \r\nc:\\store\\BackupHistory.xml -PassThru |\r\n\r\nRestore-DbaDatabase -SqlInstance Server2 -TrustDbBackupHistory\r\n\r\nIn this example we gather backup information, export it to an xml file, and then pass it on through to \r\nRestore-DbaDatabase\r\nThis allows us to repeat the restore without having to scan all the backup files again\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 4 --------------------------\r\n\r\nPS C:\\\u003eGet-ChildItem c:\\backups\\ -recurse -files |\r\n\r\nWhere {$_.extension -in (\u0027.bak\u0027,\u0027.trn\u0027) -and $_.LastWriteTime -gt (get-date).AddMonths(-1)} |\r\n Get-DbaBackupInformation -SqlInstance Server1 -ExportPath c:\\backupHistory.xml\r\n\r\nThis lets you keep a record of all backup history from the last month on hand to speed up refreshes\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 5 --------------------------\r\n\r\nPS C:\\\u003e$Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\\\network\\backups\r\n\r\n$Backups += Get-DbaBackupInformation -SqlInstance Server2 -NoXpDirTree -Path c:\\backups\r\n\r\nScan the unc folder \\\\network\\backups with Server1, and then scan the C:\\backups folder on\r\nServer2 not using xp_dirtree, adding the results to the first set.\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 6 --------------------------\r\n\r\nPS C:\\\u003e$Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\\\network\\backups -MaintenanceSolution\r\n\r\nWhen MaintenanceSolution is indicated we know we are dealing with the output from Ola Hallengren\u0027s backup scripts. So \r\nwe make sure that a FULL folder exists in the first level of Path, if not we shortcut scanning all the files as we have \r\nnothing to work with\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 7 --------------------------\r\n\r\nPS C:\\\u003e$Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \\\\network\\backups -MaintenanceSolution \r\n-IgnoreLogBackup\r\n\r\nAs we know we are dealing with an Ola Hallengren style backup folder from the MaintenanceSolution switch, when \r\nIgnoreLogBackup is also included we can ignore the LOG folder to skip any scanning of log backups. Note this also means \r\nthey WON\u0027T be restored\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaBuildReference", @@ -1391,14 +1391,14 @@ }, { "CommandName": "Get-DbaClientAlias", - "Description": "Creates/updates a SQL Server alias by altering HKLM:\\SOFTWARE\\Microsoft\\MSSQLServer\\Client", + "Description": "Gets SQL Server alias by reading HKLM:\\SOFTWARE\\Microsoft\\MSSQLServer\\Client", "Tags": "Alias", "Syntax": "\r\nGet-DbaClientAlias [[-ComputerName] \u003cDbaInstanceParameter[]\u003e] [[-Credential] \u003cPSCredential\u003e] [-EnableException] \r\n[\u003cCommonParameters\u003e]\r\n\r\n\r\n\r\n\r\n", "Author": "Chrissy LeMaire (@cl), netnerds.net", - "Synopsis": "Creates/updates a sql alias for the specified server - mimics cliconfg.exe", + "Synopsis": "Gets any SQL Server alias for the specified server(s)", "Name": "Get-DbaClientAlias", "Links": "https://dbatools.io/Get-DbaClientAlias", - "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaClientAlias\r\n\r\nGets all SQL Server client aliases on the local computer\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaClientAlias -ComputerName workstationx\r\n\r\nGets all SQL Server client aliases on Workstationx\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" + "Examples": "\r\n-------------------------- EXAMPLE 1 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaClientAlias\r\n\r\nGets all SQL Server client aliases on the local computer\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 2 --------------------------\r\n\r\nPS C:\\\u003eGet-DbaClientAlias -ComputerName workstationx\r\n\r\nGets all SQL Server client aliases on Workstationx\r\n\r\n\r\n\r\n\r\n-------------------------- EXAMPLE 3 --------------------------\r\n\r\nPS C:\\\u003e\u0027Server1\u0027, \u0027Server2\u0027 | Get-DbaClientAlias\r\n\r\nGets all SQL Server client aliases on Server1 and Server2\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n" }, { "CommandName": "Get-DbaClientProtocol", @@ -2093,7 +2093,7 @@ }, { "CommandName": "Get-DbaExecutionPlan", - "Description": "Gets execution plans and metadata. Can pipe to Export-DbaExecutionPlan :D\n\nThanks to\n https://www.simple-talk.com/sql/t-sql-programming/dmvs-for-query-plan-metadata/\n and\n http://www.scarydba.com/2017/02/13/export-plans-cache-sqlplan-file/\nfor the idea and query.", + "Description": "Gets execution plans and metadata. Can pipe to Export-DbaExecutionPlan\n\nThanks to\n https://www.simple-talk.com/sql/t-sql-programming/dmvs-for-query-plan-metadata/\n and\n http://www.scarydba.com/2017/02/13/export-plans-cache-sqlplan-file/\nfor the idea and query.", "Tags": "Performance", "Syntax": "\r\nGet-DbaExecutionPlan [-SqlInstance] \u003cDbaInstanceParameter[]\u003e [[-SqlCredential] \u003cPSCredential\u003e] [[-Database] \u003cObject[]\u003e] \r\n[[-ExcludeDatabase] \u003cObject[]\u003e] [[-SinceCreation] \u003cDateTime\u003e] [[-SinceLastExecution] \u003cDateTime\u003e] \r\n[-ExcludeEmptyQueryPlan] [-Force] [-EnableException] [\u003cCommonParameters\u003e]\r\n\r\n\r\n\r\n\r\n", "Author": "Chrissy LeMaire (@cl), netnerds.net", @@ -3542,7 +3542,7 @@ "CommandName": "Invoke-DbaLogShipping", "Description": "Invoke-DbaLogShipping helps to easily set up log shipping for one or more databases.\n\nThis function will make a lot of decisions for you assuming you want default values like a daily interval for the schedules with a 15 minute interval on the day.\nThere are some settings that cannot be made by the function and they need to be prepared before the function is executed.\n\nThe following settings need to be made before log shipping can be initiated:\n- Backup destination (the folder and the privileges)\n- Copy destination (the folder and the privileges)\n\n* Privileges\nMake sure your agent service on both the primary and the secondary instance is an Active Directory account.\nAlso have the credentials ready to set the folder permissions\n\n** Network share\nThe backup destination needs to be shared and have the share privileges of FULL CONTROL to Everyone.\n\n** NTFS permissions\nThe backup destination must have at least read/write permissions for the primary instance agent account.\nThe backup destination must have at least read permissions for the secondary instance agent account.\nThe copy destination must have at least read/write permission for the secondary instance agent acount.", "Tags": "LogShipping", - "Syntax": "\r\nInvoke-DbaLogShipping [-SourceSqlInstance] \u003cObject\u003e [-DestinationSqlInstance] \u003cObject\u003e [[-SourceSqlCredential] \r\n\u003cPSCredential\u003e] [[-SourceCredential] \u003cPSCredential\u003e] [[-DestinationSqlCredential] \u003cPSCredential\u003e] \r\n[[-DestinationCredential] \u003cPSCredential\u003e] [-Database] \u003cObject[]\u003e [-BackupNetworkPath] \u003cString\u003e [[-BackupLocalPath] \r\n\u003cString\u003e] [[-BackupJob] \u003cString\u003e] [[-BackupRetention] \u003cInt32\u003e] [[-BackupSchedule] \u003cString\u003e] [-BackupScheduleDisabled] \r\n[[-BackupScheduleFrequencyType] \u003cObject\u003e] [[-BackupScheduleFrequencyInterval] \u003cObject[]\u003e] \r\n[[-BackupScheduleFrequencySubdayType] \u003cObject\u003e] [[-BackupScheduleFrequencySubdayInterval] \u003cInt32\u003e] \r\n[[-BackupScheduleFrequencyRelativeInterval] \u003cObject\u003e] [[-BackupScheduleFrequencyRecurrenceFactor] \u003cInt32\u003e] \r\n[[-BackupScheduleStartDate] \u003cString\u003e] [[-BackupScheduleEndDate] \u003cString\u003e] [[-BackupScheduleStartTime] \u003cString\u003e] \r\n[[-BackupScheduleEndTime] \u003cString\u003e] [[-BackupThreshold] \u003cInt32\u003e] [-CompressBackup] [[-CopyDestinationFolder] \u003cString\u003e] \r\n[[-CopyJob] \u003cString\u003e] [[-CopyRetention] \u003cInt32\u003e] [[-CopySchedule] \u003cString\u003e] [-CopyScheduleDisabled] \r\n[[-CopyScheduleFrequencyType] \u003cObject\u003e] [[-CopyScheduleFrequencyInterval] \u003cObject[]\u003e] \r\n[[-CopyScheduleFrequencySubdayType] \u003cObject\u003e] [[-CopyScheduleFrequencySubdayInterval] \u003cInt32\u003e] \r\n[[-CopyScheduleFrequencyRelativeInterval] \u003cObject\u003e] [[-CopyScheduleFrequencyRecurrenceFactor] \u003cInt32\u003e] \r\n[[-CopyScheduleStartDate] \u003cString\u003e] [[-CopyScheduleEndDate] \u003cString\u003e] [[-CopyScheduleStartTime] \u003cString\u003e] \r\n[[-CopyScheduleEndTime] \u003cString\u003e] [-DisconnectUsers] [[-FullBackupPath] \u003cString\u003e] [-GenerateFullBackup] \r\n[[-HistoryRetention] \u003cInt32\u003e] [-NoRecovery] [-NoInitialization] [[-PrimaryMonitorServer] \u003cString\u003e] \r\n[[-PrimaryMonitorCredential] \u003cPSCredential\u003e] [[-PrimaryMonitorServerSecurityMode] \u003cObject\u003e] \r\n[-PrimaryThresholdAlertEnabled] [[-RestoreDataFolder] \u003cString\u003e] [[-RestoreLogFolder] \u003cString\u003e] [[-RestoreDelay] \r\n\u003cInt32\u003e] [[-RestoreAlertThreshold] \u003cInt32\u003e] [[-RestoreJob] \u003cString\u003e] [[-RestoreRetention] \u003cInt32\u003e] [[-RestoreSchedule] \r\n\u003cString\u003e] [-RestoreScheduleDisabled] [[-RestoreScheduleFrequencyType] \u003cObject\u003e] [[-RestoreScheduleFrequencyInterval] \r\n\u003cObject[]\u003e] [[-RestoreScheduleFrequencySubdayType] \u003cObject\u003e] [[-RestoreScheduleFrequencySubdayInterval] \u003cInt32\u003e] \r\n[[-RestoreScheduleFrequencyRelativeInterval] \u003cObject\u003e] [[-RestoreScheduleFrequencyRecurrenceFactor] \u003cInt32\u003e] \r\n[[-RestoreScheduleStartDate] \u003cString\u003e] [[-RestoreScheduleEndDate] \u003cString\u003e] [[-RestoreScheduleStartTime] \u003cString\u003e] \r\n[[-RestoreScheduleEndTime] \u003cString\u003e] [[-RestoreThreshold] \u003cInt32\u003e] [[-SecondaryDatabasePrefix] \u003cString\u003e] \r\n[[-SecondaryDatabaseSuffix] \u003cString\u003e] [[-SecondaryMonitorServer] \u003cString\u003e] [[-SecondaryMonitorCredential] \r\n\u003cPSCredential\u003e] [[-SecondaryMonitorServerSecurityMode] \u003cObject\u003e] [-SecondaryThresholdAlertEnabled] [-Standby] \r\n[[-StandbyDirectory] \u003cString\u003e] [-UseExistingFullBackup] [[-UseBackupFolder] \u003cString\u003e] [-Force] [-EnableException] \r\n[-WhatIf] [-Confirm] [\u003cCommonParameters\u003e]\r\n\r\n\r\n\r\n\r\n", + "Syntax": "\r\nInvoke-DbaLogShipping [-SourceSqlInstance] \u003cObject\u003e [-DestinationSqlInstance] \u003cObject[]\u003e [[-SourceSqlCredential] \r\n\u003cPSCredential\u003e] [[-SourceCredential] \u003cPSCredential\u003e] [[-DestinationSqlCredential] \u003cPSCredential\u003e] \r\n[[-DestinationCredential] \u003cPSCredential\u003e] [-Database] \u003cObject[]\u003e [-BackupNetworkPath] \u003cString\u003e [[-BackupLocalPath] \r\n\u003cString\u003e] [[-BackupJob] \u003cString\u003e] [[-BackupRetention] \u003cInt32\u003e] [[-BackupSchedule] \u003cString\u003e] [-BackupScheduleDisabled] \r\n[[-BackupScheduleFrequencyType] \u003cObject\u003e] [[-BackupScheduleFrequencyInterval] \u003cObject[]\u003e] \r\n[[-BackupScheduleFrequencySubdayType] \u003cObject\u003e] [[-BackupScheduleFrequencySubdayInterval] \u003cInt32\u003e] \r\n[[-BackupScheduleFrequencyRelativeInterval] \u003cObject\u003e] [[-BackupScheduleFrequencyRecurrenceFactor] \u003cInt32\u003e] \r\n[[-BackupScheduleStartDate] \u003cString\u003e] [[-BackupScheduleEndDate] \u003cString\u003e] [[-BackupScheduleStartTime] \u003cString\u003e] \r\n[[-BackupScheduleEndTime] \u003cString\u003e] [[-BackupThreshold] \u003cInt32\u003e] [-CompressBackup] [[-CopyDestinationFolder] \u003cString\u003e] \r\n[[-CopyJob] \u003cString\u003e] [[-CopyRetention] \u003cInt32\u003e] [[-CopySchedule] \u003cString\u003e] [-CopyScheduleDisabled] \r\n[[-CopyScheduleFrequencyType] \u003cObject\u003e] [[-CopyScheduleFrequencyInterval] \u003cObject[]\u003e] \r\n[[-CopyScheduleFrequencySubdayType] \u003cObject\u003e] [[-CopyScheduleFrequencySubdayInterval] \u003cInt32\u003e] \r\n[[-CopyScheduleFrequencyRelativeInterval] \u003cObject\u003e] [[-CopyScheduleFrequencyRecurrenceFactor] \u003cInt32\u003e] \r\n[[-CopyScheduleStartDate] \u003cString\u003e] [[-CopyScheduleEndDate] \u003cString\u003e] [[-CopyScheduleStartTime] \u003cString\u003e] \r\n[[-CopyScheduleEndTime] \u003cString\u003e] [-DisconnectUsers] [[-FullBackupPath] \u003cString\u003e] [-GenerateFullBackup] \r\n[[-HistoryRetention] \u003cInt32\u003e] [-NoRecovery] [-NoInitialization] [[-PrimaryMonitorServer] \u003cString\u003e] \r\n[[-PrimaryMonitorCredential] \u003cPSCredential\u003e] [[-PrimaryMonitorServerSecurityMode] \u003cObject\u003e] \r\n[-PrimaryThresholdAlertEnabled] [[-RestoreDataFolder] \u003cString\u003e] [[-RestoreLogFolder] \u003cString\u003e] [[-RestoreDelay] \r\n\u003cInt32\u003e] [[-RestoreAlertThreshold] \u003cInt32\u003e] [[-RestoreJob] \u003cString\u003e] [[-RestoreRetention] \u003cInt32\u003e] [[-RestoreSchedule] \r\n\u003cString\u003e] [-RestoreScheduleDisabled] [[-RestoreScheduleFrequencyType] \u003cObject\u003e] [[-RestoreScheduleFrequencyInterval] \r\n\u003cObject[]\u003e] [[-RestoreScheduleFrequencySubdayType] \u003cObject\u003e] [[-RestoreScheduleFrequencySubdayInterval] \u003cInt32\u003e] \r\n[[-RestoreScheduleFrequencyRelativeInterval] \u003cObject\u003e] [[-RestoreScheduleFrequencyRecurrenceFactor] \u003cInt32\u003e] \r\n[[-RestoreScheduleStartDate] \u003cString\u003e] [[-RestoreScheduleEndDate] \u003cString\u003e] [[-RestoreScheduleStartTime] \u003cString\u003e] \r\n[[-RestoreScheduleEndTime] \u003cString\u003e] [[-RestoreThreshold] \u003cInt32\u003e] [[-SecondaryDatabasePrefix] \u003cString\u003e] \r\n[[-SecondaryDatabaseSuffix] \u003cString\u003e] [[-SecondaryMonitorServer] \u003cString\u003e] [[-SecondaryMonitorCredential] \r\n\u003cPSCredential\u003e] [[-SecondaryMonitorServerSecurityMode] \u003cObject\u003e] [-SecondaryThresholdAlertEnabled] [-Standby] \r\n[[-StandbyDirectory] \u003cString\u003e] [-UseExistingFullBackup] [[-UseBackupFolder] \u003cString\u003e] [-Force] [-EnableException] \r\n[-WhatIf] [-Confirm] [\u003cCommonParameters\u003e]\r\n\r\n\r\n\r\n\r\n", "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "Invoke-DbaLogShipping sets up log shipping for one or more databases", "Name": "Invoke-DbaLogShipping", @@ -3553,7 +3553,7 @@ "CommandName": "Invoke-DbaLogShippingRecovery", "Description": "By default all the databases for a particular instance are recovered.\nIf the database is in the right state, either standby or recovering, the process will try to recover the database.\n\nAt first the function will check if the backup source directory can still be reached.\nIf so it will look up the last transaction log backup for the database. If that backup file is not the last copied file the log shipping copy job will be started.\nIf the directory cannot be reached for the function will continue to the restoring process.\nAfter the copy job check is performed the job is disabled to prevent the job to run.\n\nFor the restore the log shipping status is checked in the msdb database.\nIf the last restored file is not the same as the last file name found, the log shipping restore job will be executed.\nAfter the restore job check is performed the job is disabled to prevent the job to run\n\nThe last part is to set the database online by restoring the databases with recovery", "Tags": "LogShipping", - "Syntax": "\r\nInvoke-DbaLogShippingRecovery [-SqlInstance] \u003cObject\u003e [[-Database] \u003cObject[]\u003e] [[-SqlCredential] \u003cPSCredential\u003e] \r\n[-NoRecovery] [-EnableException] [-Force] [[-Delay] \u003cInt32\u003e] [-WhatIf] [-Confirm] [\u003cCommonParameters\u003e]\r\n\r\n\r\n\r\n\r\n", + "Syntax": "\r\nInvoke-DbaLogShippingRecovery [[-SqlInstance] \u003cDbaInstanceParameter[]\u003e] [[-Database] \u003cString[]\u003e] [[-SqlCredential] \r\n\u003cPSCredential\u003e] [-NoRecovery] [-EnableException] [-Force] [[-InputObject] \u003cDatabase[]\u003e] [[-Delay] \u003cInt32\u003e] [-WhatIf] \r\n[-Confirm] [\u003cCommonParameters\u003e]\r\n\r\n\r\n\r\n\r\n", "Author": "Sander Stad (@sqlstad, sqlstad.nl)", "Synopsis": "Invoke-DbaLogShippingRecovery recovers log shipped databases to a normal state to act upon a migration or disaster.", "Name": "Invoke-DbaLogShippingRecovery", diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2012_201807.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2012_201807.sql index e0395d976f..8bc398ea49 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2012_201807.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2012_201807.sql @@ -1,7 +1,7 @@ -- SQL Server 2012 Diagnostic Information Queries -- Glenn Berry --- Last Modified: September 5, 2018 +-- Last Modified: September 11, 2018 -- https://www.sqlskills.com/blogs/glenn/ -- http://sqlserverperformance.wordpress.com/ -- Twitter: GlennAlanBerry diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2014_201807.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2014_201807.sql index 6b9da63259..a4cf6ab71d 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2014_201807.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2014_201807.sql @@ -1,7 +1,7 @@ -- SQL Server 2014 Diagnostic Information Queries -- Glenn Berry --- Last Modified: September 5, 2018 +-- Last Modified: September 11, 2018 -- https://www.sqlskills.com/blogs/glenn/ -- http://sqlserverperformance.wordpress.com/ -- Twitter: GlennAlanBerry diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2_201807.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2_201807.sql index 1ea2b60a48..a73ac95e54 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2_201807.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2_201807.sql @@ -1,7 +1,7 @@ -- SQL Server 2016 SP2 Diagnostic Information Queries -- Glenn Berry --- Last Modified: Sepetember 5, 2018 +-- Last Modified: Sepetember 11, 2018 -- https://www.sqlskills.com/blogs/glenn/ -- http://sqlserverperformance.wordpress.com/ -- Twitter: GlennAlanBerry diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016_201807.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016_201807.sql index 6e16fcbfcb..7c84455809 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2016_201807.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2016_201807.sql @@ -1,7 +1,7 @@ -- SQL Server 2016 Diagnostic Information Queries -- Glenn Berry --- Last Modified: September 5, 2018 +-- Last Modified: September 11, 2018 -- https://www.sqlskills.com/blogs/glenn/ -- http://sqlserverperformance.wordpress.com/ -- Twitter: GlennAlanBerry diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_2017_201807.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_2017_201807.sql index 6b0ba41501..eb303158db 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_2017_201807.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_2017_201807.sql @@ -1,7 +1,7 @@ -- SQL Server 2017 Diagnostic Information Queries -- Glenn Berry --- Last Modified: September 5, 2018 +-- Last Modified: September 11, 2018 -- https://www.sqlskills.com/blogs/glenn/ -- http://sqlserverperformance.wordpress.com/ -- Twitter: GlennAlanBerry diff --git a/bin/diagnosticquery/SQLServerDiagnosticQueries_AzureSQLDatabase_201807.sql b/bin/diagnosticquery/SQLServerDiagnosticQueries_AzureSQLDatabase_201807.sql index d9467d67b8..7f34010cdf 100644 --- a/bin/diagnosticquery/SQLServerDiagnosticQueries_AzureSQLDatabase_201807.sql +++ b/bin/diagnosticquery/SQLServerDiagnosticQueries_AzureSQLDatabase_201807.sql @@ -1,7 +1,7 @@ -- Azure SQL Database Diagnostic Information Queries -- Glenn Berry --- Last Modified: July 26, 2018 +-- Last Modified: JSeptember 11, 2018 -- https://www.sqlskills.com/blogs/glenn/ -- http://sqlserverperformance.wordpress.com/ -- Twitter: GlennAlanBerry diff --git a/dbatools.psd1 b/dbatools.psd1 index a996fdc172..c3158120af 100644 --- a/dbatools.psd1 +++ b/dbatools.psd1 @@ -11,7 +11,7 @@ RootModule = 'dbatools.psm1' # Version number of this module. - ModuleVersion = '0.9.417' + ModuleVersion = '0.9.418' # ID used to uniquely identify this module GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789' @@ -716,8 +716,8 @@ # SIG # Begin signature block # MIIcYgYJKoZIhvcNAQcCoIIcUzCCHE8CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUDgkrl94Yhk7Lmg55GsQsZUnh -# Gc2ggheRMIIFGjCCBAKgAwIBAgIQAsF1KHTVwoQxhSrYoGRpyjANBgkqhkiG9w0B +# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUVUWQXWVo8TSNxbuPekls9Oci +# CymggheRMIIFGjCCBAKgAwIBAgIQAsF1KHTVwoQxhSrYoGRpyjANBgkqhkiG9w0B # AQsFADByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD # VQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFz # c3VyZWQgSUQgQ29kZSBTaWduaW5nIENBMB4XDTE3MDUwOTAwMDAwMFoXDTIwMDUx @@ -848,22 +848,22 @@ # c3N1cmVkIElEIENvZGUgU2lnbmluZyBDQQIQAsF1KHTVwoQxhSrYoGRpyjAJBgUr # DgMCGgUAoHgwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKAADAZBgkqhkiG9w0BCQMx # DAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkq -# hkiG9w0BCQQxFgQU2BmDgSv1CqL4UuUMSU6G8E1u8QswDQYJKoZIhvcNAQEBBQAE -# ggEAV0mPvdIr3ETBc+U976/OWo7fR3gFaS5hp71ERiwv7fMRWNFc1UnvkhKDIe6S -# RFqqNPco1uH0dJSkNgS07x1eDONf95cfvbTQrxElgi414dgdCzoM3m9yumKJUatG -# +TIa4B0F5mScQn4WsrufUkUsv/YxOArqZ5td6kdGd+nL8aWPrgTGabyCYsPb4LFh -# m5SHZ/WZdaD2sXx3+5r5yMxqXL+lCa2Whg6NzCr7TUTfFb8wGePaBAf8EA1G2yKB -# 1cc71UI34PHs/5+HNOQsDCQUGhHxW17d62mU45stF4zzb+qnOwudhML9VZFHCo7b -# Cbl1uKi75iKRddAj7EV6uVLDmKGCAg8wggILBgkqhkiG9w0BCQYxggH8MIIB+AIB +# hkiG9w0BCQQxFgQUIizWMUBdjTgOWlRbTNEOMiNhq2AwDQYJKoZIhvcNAQEBBQAE +# ggEAYluACMwMxOkxjHAWE6HtcksxaG4ML63R+FGH3PhRyqRHvD8+OHXmkSfxhVr5 +# X3L89iro2tbwOMibRL2Fwy/0wmYzJOrP6rmIEOl42F1tiszXY+vSOIkasVF/4qzT +# y9NcAOj6mGpGWua6Ld+L6OHBM3gnJM5e7UU6yFUIH2jOkcjTNH8NF2jTPplFHN7F +# r9H8KGjhx8s2WCl9E8HzTBW16kNvsvlmDEiUVK5/DfbeaOtHR/+SLzmh/FDM84T0 +# jZ7TaGKe5V1WMNvwU4I7ehR+rYrCjclphSSHI0I6N1nMwNiCo1AboQQ0q/0BbsVN +# H5gyj1VEytOU2NPkNXWNTPsX2qGCAg8wggILBgkqhkiG9w0BCQYxggH8MIIB+AIB # ATB2MGIxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNV # BAsTEHd3dy5kaWdpY2VydC5jb20xITAfBgNVBAMTGERpZ2lDZXJ0IEFzc3VyZWQg # SUQgQ0EtMQIQAwGaAjr/WLFr1tXq5hfwZjAJBgUrDgMCGgUAoF0wGAYJKoZIhvcN -# AQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTgwOTA5MTYxNDQxWjAj -# BgkqhkiG9w0BCQQxFgQUyVuRUDfCQoJoZh1L9cLRtY9VG7MwDQYJKoZIhvcNAQEB -# BQAEggEAclaog9gqNZZjk7eK09Slt5y+BuTAANswhI6d/QmdE87ndA8DwGVIp8Vc -# /JYzTPn2/JAhpEeUdZy23bM6Ia5KaBknynOElCXXIj9/BpK0oLIlY8OapAmoFyvX -# nrVqSf8pRslQBRb/svsGyD2uXov9jrsWkIMyvfdieBU1qWrP0DwCbq72yVIqiZ6M -# 3T26ePv/TAnCTc8ue64AOuBBZ0/vdFrKuDe/VoUwurJc09Uy2Vv4YtDwPdApv9ct -# 21SmX2q3LCh7fW+AgIkvC8RdHw4fNf/mw2odyh3EUoF63SILnoIgbvsZ74FRRB6j -# 7Kre4jV0geOeWTf9InxTFTGUxjTm6A== +# AQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTgwOTExMTQ0MDEyWjAj +# BgkqhkiG9w0BCQQxFgQU+JjYlW4bWu7mXLV8rHu+YpUzIJYwDQYJKoZIhvcNAQEB +# BQAEggEAiJUx6pUUWxKYV+ez83DtpD7PCd8Qk8nSLAGKzIriSha57E6lGetPJ8Dj +# uMReNVyco/jjyazu6Hgbkm8g/eMCYwBSmT2VFUHrXmCiYUz5dMEuXLG8CDIUBHJR +# ccDGciMH3VytcMtFWYYb/mpoS4WPAgNrRc7at+zrqIvLUMiCanDd0iQymTQE7CCZ +# +n+m9HEyAPLLJYlEYTb8GONI5VxpY2CZpWLa0TPjfb6N5Y8ODUCNlcBr4mwp8ru5 +# TNttldKlVXetB/OWRMJNwDX5iFzm+tgMYte+0B/EPrYd/ZyrCAnVJ7gOArO/DQg7 +# Gxcihnodp4fVKgE98i34UUaqzi8bBg== # SIG # End signature block diff --git a/dbatools.psm1 b/dbatools.psm1 index da07122b32..a86d08934e 100644 --- a/dbatools.psm1 +++ b/dbatools.psm1 @@ -1078,12 +1078,12 @@ if ($PSCommandPath -like "*.psm1") { # ATB2MGIxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNV # BAsTEHd3dy5kaWdpY2VydC5jb20xITAfBgNVBAMTGERpZ2lDZXJ0IEFzc3VyZWQg # SUQgQ0EtMQIQAwGaAjr/WLFr1tXq5hfwZjAJBgUrDgMCGgUAoF0wGAYJKoZIhvcN -# AQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTgwOTA5MTYxNDQyWjAj +# AQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTgwOTExMTQ0MDEyWjAj # BgkqhkiG9w0BCQQxFgQU0SLTSXIlA81lZ+rOW5rrRwQLdMswDQYJKoZIhvcNAQEB -# BQAEggEAT0tGBWdvwy53nTWP0ugvLmKjLgypesCn/b40X+7ywuyQPs0Em9czScCe -# Acehf0SBubUsKxA6Cb1pV9efzj/24OtKNZR+X6qfgiDkBwYGYTPxWAKS/99c2yQD -# NYgrTF/I3kJyJ29jxOdfrvAk+KoSADW5KaCjiqx6zydYeX9LicrPSlQC0FGdMLih -# ZQbjO9tfKiNdkDbQ1ezu2Z/beBDSI1EYGLU+Xv2+/gGx522qAzqXImi0JdEimgfU -# cCU1W0QP4XUJj8k4Eavp7EKVh80GbTgkr2nDWIljRftKmog9XS7YWm0qv/AgPc4E -# +D9xllqw1Gd8KPcxPGAGoAjUY2SH8A== +# BQAEggEAAlASJuFG03cOcHzcOW2BdRNQcgQRlB2d+K3PvxPM5pssbwXELc1aEX3T +# 1Lyd2HWJJ/9TJsxwj6aLbHeHYyePU3uMMOgwrm8romMc8NCv3pHj/BUzyGZEP5H0 +# ai1nb4TpsTMgQWA8WZxI2lNd/AU3caG6qBKZWTo58Yf10N8twO1dJYS8xkgJmf6z +# mX56OW1VtHPHy5MeUKF2mTNx9snOhPdZawoq7z87sz+1aKoFRN9hlRiNQ+RRxjph +# o/fp/P255r98FWW1S/hyDU1YQ+ouAWbq2VYZVkYFX4DV8PN//lwDELeY1nSUjkBJ +# zXBNCFprZ4MWgU5N2ndXX2nCtcJMOQ== # SIG # End signature block diff --git a/install.ps1 b/install.ps1 index 1bb800d732..c5efa9e615 100644 --- a/install.ps1 +++ b/install.ps1 @@ -317,12 +317,12 @@ Write-LocalMessage -Message "`n`nIf you experience any function missing errors a # ATB2MGIxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNV # BAsTEHd3dy5kaWdpY2VydC5jb20xITAfBgNVBAMTGERpZ2lDZXJ0IEFzc3VyZWQg # SUQgQ0EtMQIQAwGaAjr/WLFr1tXq5hfwZjAJBgUrDgMCGgUAoF0wGAYJKoZIhvcN -# AQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTgwOTA5MTYxNDQ4WjAj +# AQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTgwOTExMTQ0MDEzWjAj # BgkqhkiG9w0BCQQxFgQU2ergF7YU3jz7T4v+V2ggn9yhehowDQYJKoZIhvcNAQEB -# BQAEggEANZdGtK+fYAX9OjJJm1lyKxtifwksYj9HKyiPBoWmwzvHnd/Wryqkx+wp -# AXCPyQfjyGgMeHxQxL6I1oN+nOG++VJu47tkYHZcC/MwDj8MLAxcqdzp/ClHP1KG -# C2zM+LSBtZv5qUsfxRNNI3ht9pf9/K7fAeaeKHOK/BA9IdpMqUMHdZfymn5jPieZ -# Vq97lrEX3/eU/VOZTMMcxO2rCgKHzzJ6NcfuInNTCmw7j7osivFmzYwnfAzPxGFO -# 01tzfM5JaPQ2Z0wQ90Yp/avwfRvic7uDVVS4W2wMg7a3fi2UD5Ko/crUbG2mNXIg -# siHZVj+A4Me0gAqvKj2p8OkomPM6aA== +# BQAEggEAQXnHuAlOwFyQ202C0G1xslEt3S8AGthu2TIKfIur4lwIrYNDl54M9w5G +# sb3R6wd0hib2YgKFPDfvyP4839hgObWGwZnF3O0hGV8bth3orDw/ezFVf/3J43Bz +# Yh2FoAeqje2d+j199Ba/NL3yM64SZnYhqrNnit8vb2UIFpkA+vei/Bnk0rpwCQLv +# gAOr2g4/JJvoCTu5yfrL6HP7AjsFD3nU4STvxK9e+8cYR5M8ZaD+tqTH3hx2t3Ur +# qAutNIF5ZVvWQFq/HGhVAwBzOhWCSija3Z71KArdmUcgY80j/l3LNI0DkJ5tpn9G +# uZJzmPyiaOBx97msoMrc5CR+YfocwQ== # SIG # End signature block diff --git a/xml/dbatools.Format.ps1xml b/xml/dbatools.Format.ps1xml index 5bec8e8c2e..d6be206c0e 100644 --- a/xml/dbatools.Format.ps1xml +++ b/xml/dbatools.Format.ps1xml @@ -695,12 +695,12 @@ - + - - - - - - + + + + + + diff --git a/xml/dbatools.Types.ps1xml b/xml/dbatools.Types.ps1xml index 0d87d522aa..f2a6636574 100644 --- a/xml/dbatools.Types.ps1xml +++ b/xml/dbatools.Types.ps1xml @@ -210,12 +210,12 @@ - + - - - - - - + + + + + +