-
-
Notifications
You must be signed in to change notification settings - Fork 852
Description
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
Running command:
Copy-DbaAgentJob -Source "SourceInstance" -Destination "DestinationInstance" -Verbose
Returns the following verbose output:
VERBOSE: 13:22:281[Connect-DbaInstance] Starting loop for '': ComputerName = '', InstanceName = '', IsLocalHost = 'False', Type = 'Default'
VERBOSE: 13:22:282[Connect-DbaInstance] String is passed in, will build server object from instance object and other parameters, do some checks and then return the server object
VERBOSE: 13:22:283[Connect-DbaInstance] authentication method is 'local integrated'
VERBOSE: 13:22:284[Get-DbaAgentJob] The -Job parameter was explicitly provided but contains only null, empty, or whitespace values. No jobs will be returned.
VERBOSE: 13:22:285[Connect-DbaInstance] Starting loop for '': ComputerName = '', InstanceName = '', IsLocalHost = 'True', Type = 'Default'
VERBOSE: 13:22:286[Connect-DbaInstance] String is passed in, will build server object from instance object and other parameters, do some checks and then return the server object
VERBOSE: 13:22:287[Connect-DbaInstance] authentication method is 'local integrated'
Please not the following verbose output:
[Get-DbaAgentJob] The -Job parameter was explicitly provided but contains only null, empty, or whitespace values. No jobs will be returned.
Steps to Reproduce
Copy-DbaAgentJob -Source "SourceInstance" -Destination "DestinationInstance" -Verbose
Sync-DbaAvailabilityGroup -Primary "SourceInstance" -Secondary "DestinationInstance" -Force -Verbose
Please confirm that you are running the most recent version of dbatools
This is running dbatools version 2.7.8, issue did not occur in version 2.7.6
Other details or mentions
In issue #9931, changes were introduced to address issue #9441 by adding Test-Bound validation in Get-DbaAgentJob for the -Job and -ExcludeJob parameters. This validation detects null, empty, or whitespace values.
However, when running Copy-DbaAgentJob (or Sync-DbaAvailabilityGroup, which uses the same logic of Copy-DbaAgentJob) without specifying -Job—with the intention of copying or syncing all jobs—no jobs are selected. This happens because the Copy-DbaAgentJob function explicitly passes -Job $Job to Get-DbaAgentJob, even when $Job was not provided:
if ($Source) {
try {
$InputObject = Get-DbaAgentJob -SqlInstance $Source -SqlCredential $SourceSqlCredential -Job $Job -ExcludeJob $ExcludeJob
} catch {
Stop-Function -Message "Error occurred while establishing connection to $Source" -Category ConnectionError -ErrorRecord $_ -Target $Source
return
}
}
Question:
How can we restore the ability to copy or sync all jobs without requiring a value for the -Job parameter?
What PowerShell host was used when producing this error
Windows PowerShell (powershell.exe)
PowerShell Host Version
Name Value
PSVersion 5.1.17763.8024
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.8024
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
SQL Server Edition and Build number
Microsoft SQL Server 2019 (RTM-CU32-GDR) (KB5068404) - 15.0.4455.2 (X64) Oct 7 2025 21:10:15 Copyright (C) 2019 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2019 Datacenter 10.0 (Build 17763: ) (Hypervisor)
.NET Framework Version
.NET Framework 4.8.4795.0