Author | Mikey Bronowski (@MikeyBronowski), bronowski.it |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Remove-DbaDbUdf on GitHub.
Want to see the Bill Of Health for this command? Check out Remove-DbaDbUdf.
Removes user-defined functions from SQL Server databases.
Removes user-defined functions from specified databases, providing a clean way to drop obsolete or unwanted UDFs without manual T-SQL scripting. This function is particularly useful during database cleanup operations, code refactoring projects, or when removing deprecated functions that are no longer needed. Supports filtering by schema and function name, and can exclude system UDFs to prevent accidental removal of built-in functions. Works seamlessly with Get-DbaDbUdf for pipeline operations.
Remove-DbaDbUdf
[-SqlInstance] <DbaInstanceParameter[]>
[-SqlCredential <PSCredential>]
[-Database <String[]>]
[-ExcludeDatabase <Object[]>]
[-ExcludeSystemUdf]
[-Schema <String[]>]
[-ExcludeSchema <String[]>]
[-Name <String[]>]
[-ExcludeName <String[]>]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Remove-DbaDbUdf -InputObject <UserDefinedFunction[]>
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> Remove-DbaDbUdf -SqlInstance localhost, sql2016 -Database db1, db2 -Name udf1, udf2, udf3
Removes udf1, udf2, udf3 from db1 and db2 on the local and sql2016 SQL Server instances.
PS C:\> $udfs = Get-DbaDbUdf -SqlInstance localhost, sql2016 -Database db1, db2 -Name udf1, udf2, udf3
PS C:\> $udfs | Remove-DbaDbUdf
Removes udf1, udf2, udf3 from db1 and db2 on the local and sql2016 SQL Server instances.
The target SQL Server instance or instances.
Alias | |
Required | True |
Pipeline | false |
Default Value |
Accepts UDF objects directly from Get-DbaDbUdf pipeline operations.
Use this when you need to filter or examine UDFs first before removal, enabling complex selection logic not possible with simple name matching.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
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 |
Specifies which databases to process for UDF removal. Accepts multiple database names and supports wildcards.
Use this to limit the operation to specific databases instead of processing all databases on the instance.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies databases to skip during UDF removal operations. Auto-populated with server database names for tab completion.
Use this when you want to process most databases but exclude specific ones like production or system databases.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Excludes system-generated and built-in user-defined functions from removal operations.
Use this safety switch to prevent accidental deletion of system UDFs that may be required for database functionality.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Specifies which schemas to include when removing UDFs. Accepts multiple schema names.
Use this to target UDFs in specific schemas like 'dbo', 'reporting', or custom application schemas while leaving others untouched.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies schemas to skip during UDF removal operations.
Use this to protect critical schemas from modification while processing UDFs in other schemas throughout the database.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies the exact names of UDFs to remove. Accepts multiple function names and supports wildcards.
Use this for targeted removal of specific functions like deprecated calculation functions or obsolete business logic UDFs.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies UDF names to skip during removal operations. Accepts multiple function names and wildcards.
Use this to protect specific functions from deletion while removing others that match your criteria.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |
Shows what would happen if the command were to run. No actions are actually performed.
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
Prompts you for confirmation before executing any changing operations within the command.
This is the default. Use -Confirm:$false to suppress these prompts.
Alias | cf |
Required | False |
Pipeline | false |
Default Value |