From c5d52d12ce2a2b73ac43b0b65a313873c40423c9 Mon Sep 17 00:00:00 2001 From: SylvainDuran Date: Tue, 14 Oct 2025 09:53:08 +0200 Subject: [PATCH 1/2] Fix Set-DbaAgentJobStep parameter handling for ProxyName, RetryAttempts, and RetryInterval - Add support for removing proxy by passing $null or empty string to -ProxyName parameter - Fix RetryAttempts and RetryInterval being incorrectly set to 0 when parameters are not provided - Use $PSBoundParameters.ContainsKey() to distinguish between "parameter not provided" and "parameter provided with value 0 or $null" --- public/Set-DbaAgentJobStep.ps1 | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/public/Set-DbaAgentJobStep.ps1 b/public/Set-DbaAgentJobStep.ps1 index 7995e873a20..ebbbac58b09 100644 --- a/public/Set-DbaAgentJobStep.ps1 +++ b/public/Set-DbaAgentJobStep.ps1 @@ -343,12 +343,12 @@ function Set-DbaAgentJobStep { } } - if ($null -ne $RetryAttempts) { + if ($PSBoundParameters.ContainsKey('RetryAttempts')) { Write-Message -Message "Setting job step retry attempts to $RetryAttempts" -Level Verbose $jobStep.RetryAttempts = $RetryAttempts } - if ($null -ne $RetryInterval) { + if ($PSBoundParameters.ContainsKey('RetryInterval')) { Write-Message -Message "Setting job step retry interval to $RetryInterval" -Level Verbose $jobStep.RetryInterval = $RetryInterval } @@ -358,9 +358,13 @@ function Set-DbaAgentJobStep { $jobStep.OutputFileName = $OutputFileName } - if ($ProxyName) { - # Check if the proxy exists - if ($Server.JobServer.ProxyAccounts.Name -contains $ProxyName) { + if ($PSBoundParameters.ContainsKey('ProxyName')) { + if ([string]::IsNullOrEmpty($ProxyName)) { + # Remove proxy from job step + Write-Message -Message "Removing proxy from job step" -Level Verbose + $jobStep.ProxyName = '' + } elseif ($Server.JobServer.ProxyAccounts.Name -contains $ProxyName) { + # Set or update proxy name Write-Message -Message "Setting job step proxy name to $ProxyName" -Level Verbose $jobStep.ProxyName = $ProxyName } else { From 84b3c7e118311d7d6c441443f2ca6220e4c7c9a0 Mon Sep 17 00:00:00 2001 From: SylvainDuran Date: Tue, 14 Oct 2025 10:56:22 +0200 Subject: [PATCH 2/2] Use Test-Bound instead of PSBoundParameters.ContainsKey for parameter checks to follow dbatools project conventions --- public/Set-DbaAgentJobStep.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/Set-DbaAgentJobStep.ps1 b/public/Set-DbaAgentJobStep.ps1 index ebbbac58b09..28bba17ad06 100644 --- a/public/Set-DbaAgentJobStep.ps1 +++ b/public/Set-DbaAgentJobStep.ps1 @@ -343,12 +343,12 @@ function Set-DbaAgentJobStep { } } - if ($PSBoundParameters.ContainsKey('RetryAttempts')) { + if (Test-Bound -ParameterName 'RetryAttempts') { Write-Message -Message "Setting job step retry attempts to $RetryAttempts" -Level Verbose $jobStep.RetryAttempts = $RetryAttempts } - if ($PSBoundParameters.ContainsKey('RetryInterval')) { + if (Test-Bound -ParameterName 'RetryInterval') { Write-Message -Message "Setting job step retry interval to $RetryInterval" -Level Verbose $jobStep.RetryInterval = $RetryInterval } @@ -358,7 +358,7 @@ function Set-DbaAgentJobStep { $jobStep.OutputFileName = $OutputFileName } - if ($PSBoundParameters.ContainsKey('ProxyName')) { + if (Test-Bound -ParameterName 'ProxyName') { if ([string]::IsNullOrEmpty($ProxyName)) { # Remove proxy from job step Write-Message -Message "Removing proxy from job step" -Level Verbose