Skip to content

Copy-DbaAgentJob from mirroring principal - initial catalog cannot be set #9853

@gauiPPP

Description

@gauiPPP

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

Powershell:
Copy-DbaAgentJob -Source $source -Destination $destination -Job $jobNamesToMigrate
=>
WARNING: [11.40.25][Get-DbaAgentJob] Failure | Use of key 'Failover Partner' requires the key 'Initial Catalog' to be present.

Powershell:
Copy-DbaAgentJob -Source $source -Destination $destination -Job $jobNamesToMigrate -Database 'msdb'
=>
Copy-DbaAgentJob : A parameter cannot be found that matches parameter name 'Database'.

Well actually the job Get-DbaAgentJob with -Database 'msdb' gets the same error about initial catalog, so it seems in both or all that would have to be set.
I tried with "Set-DbatoolsConfig -FullName sql.connection.key -Value "Initial Catalog=msdb" -Register" but no luck.

On the other hand this seems to work
Invoke-DbaQuery -SqlInstance $sourceServer -Database 'msdb' -Query "SELECT name FROM msdb.dbo.sysjobs WHERE enabled = 1" and was giving similar error before adding -Database 'msdb'

so Get and Copy DbaAgentJob would need some improvement?

Steps to Reproduce

Set up MS SQL server 2022. Set up data mirroring from MS SQL Server 2017 to the 2022.

in powershell try to run
Get-DbaAgentJob
Copy-DbaAgentJob
source 2017 destination 2022

Please confirm that you are running the most recent version of dbatools

2.7.6

Other details or mentions

No response

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

Mirror
Name Value


PSVersion 5.1.20348.4163
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.20348.4163
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

SQL Server Edition and Build number

Principal
Microsoft SQL Server 2017 (RTM-CU31-GDR) (KB5063759) - 14.0.3500.1 (X64) Jul 14 2025 13:02:12 Copyright (C) 2017 Microsoft Corporation Standard Edition (64-bit) on Windows Server 2022 Standard 10.0 (Build 20348: ) (Hypervisor)

Mirror
Microsoft SQL Server 2022 (RTM-CU20-GDR) (KB5065220) - 16.0.4212.1 (X64) Aug 13 2025 16:40:40 Copyright (C) 2022 Microsoft Corporation Standard Edition (64-bit) on Windows Server 2022 Standard 10.0 (Build 20348: ) (Hypervisor)

.NET Framework Version

Mirror (where powershell script ran)
.NET Framework 4.8.4795.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugs lifetriage requiredNew issue that has not been reviewed by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions