commands

^

Get-DbaModule

Author Brandon Abshire, netnerds.net
Availability Windows, Linux, macOS

 

Aliases : Get-DbaDbModule

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

Synopsis

Displays all objects in sys.sys_modules after specified modification date. Works on SQL Server 2008 and above.

Description

Quickly find modules (Stored Procs, Functions, Views, Constraints, Rules, Triggers, etc) that have been modified in a database, or across all databases.
Results will exclude the module definition, but can be queried explicitly.

Syntax

Get-DbaModule
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-Database] <Object[]>]
    [[-ExcludeDatabase] <Object[]>]
    [[-ModifiedSince] <DateTime>]
    [[-Type] <String[]>]
    [-ExcludeSystemDatabases]
    [-ExcludeSystemObjects]
    [[-InputObject] <Database[]>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaModule -SqlInstance sql2008, sqlserver2012

Return all modules for servers sql2008 and sqlserver2012 sorted by Database, Modify_Date ASC.

Example: 2
PS C:\> Get-DbaModule -SqlInstance sql2008, sqlserver2012 | Select-Object *

Shows hidden definition column (informative wall of text).

Example: 3
PS C:\> Get-DbaModule -SqlInstance sql2008 -Database TestDB -ModifiedSince "2017-01-01 10:00:00"

Return all modules on server sql2008 for only the TestDB database with a modified date after 1 January 2017 10:00:00 AM.

Example: 4
PS C:\> Get-DbaModule -SqlInstance sql2008 -Type View, Trigger, ScalarFunction

Return all modules on server sql2008 for all databases that are triggers, views or scalar functions.

Example: 5
PS C:\> 'sql2008' | Get-DbaModule -Database TestDB -Type View, StoredProcedure, ScalarFunction

Return all modules on server sql2008 for only the TestDB database that are stored procedures, views or scalar functions. Input via Pipeline

Example: 6
PS C:\> Get-DbaDatabase -SqlInstance sql2008 -ExcludeSystem | Get-DbaModule -Type View, Trigger, ScalarFunction

Return all modules on server sql2008 for all user databases that are triggers, views or scalar functions.

Example: 7
PS C:\> Get-DbaDatabase -SqlInstance sql2008, sqlserver2012 -ExcludeUser | Get-DbaModule -Type StoredProcedure -ExcludeSystemObjects

Return all user created stored procedures in the system databases for servers sql2008 and sqlserver2012.

Optional Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required False
Pipeline true (ByValue)
Default Value
-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. If unspecified, all databases will be processed.

Alias
Required False
Pipeline false
Default Value
-ExcludeDatabase

The database(s) to exclude.

Alias
Required False
Pipeline false
Default Value
-ModifiedSince

DateTime value to use as minimum modified date of module.

Alias
Required False
Pipeline false
Default Value 1900-01-01
-Type

Limit by specific type of module. Valid choices include: View, TableValuedFunction, DefaultConstraint, StoredProcedure, Rule, InlineTableValuedFunction, Trigger, ScalarFunction

Alias
Required False
Pipeline false
Default Value
Accepted Values View,TableValuedFunction,DefaultConstraint,StoredProcedure,Rule,InlineTableValuedFunction,Trigger,ScalarFunction
-ExcludeSystemDatabases

Allows you to suppress output on system databases

Alias
Required False
Pipeline false
Default Value False
-ExcludeSystemObjects

Allows you to suppress output on system objects

Alias
Required False
Pipeline false
Default Value False
-InputObject

Enables piping from Get-DbaDatabase.

Alias
Required False
Pipeline true (ByValue)
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