dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.39k stars 787 forks source link

New-DbaAgentJobStep -DatabaseUser is not setting the username for the job. #9378

Closed Xyaran closed 3 weeks ago

Xyaran commented 4 weeks ago

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

I'm not getting any error, but the username is not set inside the job step.

Steps to Reproduce


    $newJobParams = @{
        SqlInstance = $dataWarehouseConfiguration.FullSqlServerInstance
        SqlCredential = GetDbCredential($dataWarehouseConfiguration)
        Job = 'Run Job'
        Database = $dataWarehouseConfiguration.SqlServerDatabaseName
        OnSuccessAction = 'GotoNextStep'
        Confirm = $false
    }

    New-DbaAgentJobStep @newJobParams -StepId 1  `
                                      -StepName 'Update Datawarehouse Objects'  `
                                      -OnFailAction 'QuitWithFailure' -RetryAttempts 5 -RetryInterval 1  `
                                      -DatabaseUser "$login"  `
                                      -Subsystem 'TransactSql'  `
                                      -Command 'EXEC [dbo].[usp_UpdateDWObjects]'  `
        | Out-Null

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

2.1.14

Other details or mentions

Set-DbaAgentJobStep -DatabaseUser is setting the username properly.

I looked into the code, New-DbaAgentJobStep.ps1 line 344 is not checking the right variable ($DatabaseName instead of $Database)

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

Name Value


PSVersion 5.1.26100.461
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.26100.461
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-CU26) (KB5035123) - 15.0.4365.2 (X64) Mar 29 2024 23:02:47 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: ) (Hypervisor)

.NET Framework Version

.NET Framework 4.8.9232.0

andreasjordan commented 3 weeks ago

Thanks for reporting this, a fix is on its way...

Xyaran commented 3 weeks ago

Thank you very much!