commands

^

Get-DbaSchemaChangeHistory

Author Stuart Moore (@napalmgram), stuart-moore.com
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Get-DbaSchemaChangeHistory on GitHub.
Want to see the Bill Of Health for this command? Check out Get-DbaSchemaChangeHistory.

Synopsis

Gets DDL changes logged in the system trace.

Description

Queries the default system trace for any DDL changes in the specified time frame
Only works with SQL 2005 and later, as the system trace didn't exist before then

Syntax

Get-DbaSchemaChangeHistory
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object[]>]
    [[-ExcludeDatabase] <Object[]>]
    [[-Since] <DbaDateTime>]
    [[-Object] <String[]>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaSchemaChangeHistory -SqlInstance localhost

Returns all DDL changes made in all databases on the SQL Server instance localhost since the system trace began

Example: 2
PS C:\> Get-DbaSchemaChangeHistory -SqlInstance localhost -Since (Get-Date).AddDays(-7)

Returns all DDL changes made in all databases on the SQL Server instance localhost in the last 7 days

Example: 3
PS C:\> Get-DbaSchemaChangeHistory -SqlInstance localhost -Database Finance, Prod -Since (Get-Date).AddDays(-7)

Returns all DDL changes made in the Prod and Finance databases on the SQL Server instance localhost in the last 7 days

Example: 4
PS C:\> Get-DbaSchemaChangeHistory -SqlInstance localhost -Database Finance -Object AccountsTable -Since (Get-Date).AddDays(-7)

Returns all DDL changes made to the AccountsTable object in the Finance database on the SQL Server instance localhost in the last 7 days

Required Parameters

-SqlInstance

The target SQL Server instance or instances. This can be a collection and receive pipeline input to allow the function to be executed against multiple SQL Server instances.

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-Database

The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will be processed.

Alias
Required False
Pipeline false
Default Value
-ExcludeDatabase

The database(s) to exclude - this list is auto-populated from the server

Alias
Required False
Pipeline false
Default Value
-Since

A date from which DDL changes should be returned. Default is to start at the beginning of the current trace file

Alias
Required False
Pipeline false
Default Value
-Object

The name of a SQL Server object you want to look for changes on

Alias
Required False
Pipeline false
Default Value
-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.

Alias
Required False
Pipeline false
Default Value False