Thor Logo dbatools

Set-DbaAgentJobCategory

View Source
Sander Stad (@sqlstad), sqlstad.nl
Windows, Linux, macOS

Synopsis

Renames SQL Server Agent job categories to standardize naming conventions across instances.

Description

Renames existing SQL Server Agent job categories by updating their names in the msdb database. This is particularly useful for standardizing job category naming conventions across multiple environments or correcting categories that were created with inconsistent names. The function validates that source categories exist and prevents renaming to names that already exist, helping maintain clean job organization within SQL Server Agent.

Syntax

Set-DbaAgentJobCategory
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Category] <String[]>]
    [[-NewName] <String[]>]
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> New-DbaAgentJobCategory -SqlInstance sql1 -Category 'Category 1' -NewName 'Category 2'

Change the name of the category from ‘Category 1’ to ‘Category 2’.

Example: 2
PS C:\> Set-DbaAgentJobCategory -SqlInstance sql1, sql2 -Category Category1, Category2 -NewName cat1, cat2

Rename multiple jobs in one go on multiple servers.

Required Parameters

-SqlInstance

The target SQL Server instance or instances. You must have sysadmin access and server version must be SQL Server version 2000 or greater.

PropertyValue
Alias
RequiredTrue
Pipelinetrue (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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Category

Specifies the existing job category name(s) to rename. The category must already exist in the SQL Server Agent on the target instance.
Use this to identify which job categories need standardized naming across your environment.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-NewName

Specifies the new name(s) for the job category. The new name cannot already exist on the target instance.
When renaming multiple categories, provide names in the same order as the Category parameter values.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Force

Bypasses confirmation prompts and performs the rename operation without asking for user confirmation.
Use this when scripting bulk category renames where manual confirmation would be impractical.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse
-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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

PropertyValue
Aliaswi
RequiredFalse
Pipelinefalse
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command.

PropertyValue
Aliascf
RequiredFalse
Pipelinefalse
Default Value