dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer

Home Page:https://dbatools.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Copy-DbaAgentJob is not migration jobs with operators even though they exist

3xchaos opened this issue · comments

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

VERBOSE: [19:48:23][Connect-DbaInstance] Connection string is passed in, will build empty server object, set connection string from instance.InputObject, do some checks and then return the server object
VERBOSE: [19:48:23][Connect-DbaInstance] Server object passed in, will do some checks and then return the original object
VERBOSE: [19:48:23][Copy-DbaAgentJob] Working on job:
VERBOSE: Performing the operation "Operator(s) doesn't exist on destination. Skipping job " on target "".

VERBOSE: [19:48:24][Copy-DbaAgentJob] Operator(s) doesn't exist on destination. Skipping job

Steps to Reproduce

# provide your command(s) executed pertaining to dbatools
# please include variable values (redacted or fake if needed) for reference

We first run the following to migrate the operators
Copy-DbaAgentOperator -Source $SourceCS -Destination $CS -Force

We then migrate any categories that are required
Copy-DbaAgentJobCategory -Source $SourceCS -Destination $CS -JobCategory $JC -Force

We then splat are variables for the job migration

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

PS C:\Users\bstevenson1adm> get-module | Select-object version, name

Version Name


2.1.7 dbatools
2023.9.21 dbatools.library
3.1.0.0 Microsoft.PowerShell.Management
3.1.0.0 Microsoft.PowerShell.Utility
2.0.0 PSReadline

Other details or mentions

No response

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

Name Value


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

SQL Server Edition and Build number

Source -> Microsoft SQL Server 2016 (SP3-GDR) (KB5029186) - 13.0.6435.1 (X64) Jul 30 2023 19:53:42 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows Server 2016 Standard 10.0 (Build 14393: ) (Hypervisor)

Target -> Microsoft SQL Server 2019 (RTM-CU24) (KB5031908) - 15.0.4345.5 (X64) Dec 4 2023 14:44:16 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: ) (Hypervisor)

.NET Framework Version

PSChildName Version


v2.0.50727 2.0.50727.4927
v3.0 3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation 3.0.6920.4902
v3.5 3.5.30729.4926
Client 4.8.03761
Full 4.8.03761
Client 4.0.0.0

Sorry - hit enter and mess up the Steps to Reproduce

We first run the following to migrate the operators
Copy-DbaAgentOperator -Source $SourceCS -Destination $CS -Force

We then migrate any categories that are required
Copy-DbaAgentJobCategory -Source $SourceCS -Destination $CS -JobCategory $JC -Force

We then splat are variables for the job migration

$copyJobSplat = @{
Source = $SourceCS
Destination = $CS
Job = $_JobNames
DisableOnSource = $false
Force = $true
Whatif = $false
SourceSqlCredential = $MySQLCredential
DestinationSqlCredential = $MySQLCredential
Verbose = $true
}

Then execute the Copy-DbaAgentJob command
Copy-DbaAgentJob @copyJobSplat

Output of splat

Name Value


Source Data Source=;Initial Catalog=master;Mu...
Job
Whatif False
Verbose True
Destination Data Source=;Initial Catalog=master;Mu...
Force True
DisableOnSource True
SourceSqlCredential System.Management.Automation.PSCredential
DestinationSqlCredential System.Management.Automation.PSCredential

All jobs migrate except the ones that have a operator defined that gets migrated Copy-DbaAgentOperator.

Note - I just dropped and recreated the operator using TSQL and then executed the migrate job and it functioned correctly so maybe the issue is with the Copy-DbaAgentOperator even though the operator looks correct after running this command

/****** Object: Operator [ Script Date: 3/14/2024 12:14:31 PM ******/
EXEC msdb.dbo.sp_delete_operator @name=N''
GO

/****** Object: Operator [] Script Date: 3/14/2024 12:14:31 PM ******/
EXEC msdb.dbo.sp_add_operator @name=N'',
@enabled=1,
@weekday_pager_start_time=90000,
@weekday_pager_end_time=180000,
@saturday_pager_start_time=90000,
@saturday_pager_end_time=180000,
@sunday_pager_start_time=90000,
@sunday_pager_end_time=180000,
@pager_days=0,
@email_address=N'',
@category_name=N'[Uncategorized]'
GO

PS C:\Windows\system32> Copy-DbaAgentJob @copyJobSplat
VERBOSE: [12:16:25][Connect-DbaInstance] Connection string is passed in, will build empty server object, set connection string from instance
.InputObject, do some checks and then return the server object
VERBOSE: [12:16:25][Connect-DbaInstance] Server object passed in, will do some checks and then return the original object
VERBOSE: [12:16:25][Copy-DbaAgentJob] Working on job:
VERBOSE: Performing the operation "Creating Job " on target "".
VERBOSE: [12:16:26][Copy-DbaAgentJob] Copying Job
VERBOSE: [12:16:26][Connect-DbaInstance] Server object passed in, will do some checks and then return the original object

VERBOSE: Performing the operation "Disabling " on target "".
VERBOSE: [12:16:26][Copy-DbaAgentJob] Disabling SMTFO - SRC_SMART_Dialer_Process_SAT on
Type Name Status Notes


Agent Job Successful

I tried to reproduce the issue - but it works on my machine.