Skip to content

Commit

Permalink
New-DbaAgentJobStep: Fix for using DatabaseUser (#9380)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasjordan authored Jun 6, 2024
1 parent 2212131 commit d589743
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions public/New-DbaAgentJobStep.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function New-DbaAgentJobStep {
[ValidateSet('QuitWithSuccess', 'QuitWithFailure', 'GoToNextStep', 'GoToStep')]
[string]$OnFailAction = 'QuitWithFailure',
[int]$OnFailStepId = 0,
[object]$Database,
[string]$Database,
[string]$DatabaseUser,
[int]$RetryAttempts,
[int]$RetryInterval,
Expand Down Expand Up @@ -341,14 +341,14 @@ function New-DbaAgentJobStep {
}
}

if ($DatabaseUser -and $DatabaseName) {
if ($DatabaseUser -and $Database) {
# Check if the username is present in the database
if ($Server.Databases[$DatabaseName].Users.Name -contains $DatabaseUser) {
if ($Server.Databases[$Database].Users.Name -contains $DatabaseUser) {

Write-Message -Message "Setting job step database username to $DatabaseUser" -Level Verbose
$jobStep.DatabaseUserName = $DatabaseUser
} else {
Stop-Function -Message "The database user is not present in the database $DatabaseName on instance $instance." -Target $instance -Continue
Stop-Function -Message "The database user is not present in the database $Database on instance $instance." -Target $instance -Continue
}
}

Expand Down

0 comments on commit d589743

Please sign in to comment.