Skip to content

Commit

Permalink
Support OwnerLoginName in New-DbaAgentSchedule (#9370)
Browse files Browse the repository at this point in the history
Co-authored-by: Chrissy LeMaire <[email protected]>
  • Loading branch information
david-garcia-garcia and potatoqualitee authored Jun 5, 2024
1 parent df5f991 commit ef13659
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions public/New-DbaAgentSchedule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ function New-DbaAgentSchedule {
If force is used the start time will be '23:59:59'
.PARAMETER Owner
Login to own the job, defaults to login running the command.
.PARAMETER WhatIf
Shows what would happen if the command were to run. No actions are actually performed.
Expand Down Expand Up @@ -167,6 +170,7 @@ function New-DbaAgentSchedule {
[string]$EndDate,
[string]$StartTime,
[string]$EndTime,
[string]$Owner,
[switch]$Force,
[switch]$EnableException
)
Expand Down Expand Up @@ -523,6 +527,10 @@ function New-DbaAgentSchedule {
$jobschedule.ActiveEndTimeOfDay = $EndTime
}

if ($Owner) {
$jobschedule.OwnerLoginName = $Owner
}

$jobschedule.Create()

Write-Message -Message "Job schedule created with UID $($jobschedule.ScheduleUid)" -Level Verbose
Expand Down
2 changes: 1 addition & 1 deletion tests/New-DbaAgentSchedule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
It "Should only contain our specific parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') }
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Job', 'Schedule', 'Disabled', 'FrequencyType', 'FrequencyInterval', 'FrequencySubdayType', 'FrequencySubdayInterval', 'FrequencyRelativeInterval', 'FrequencyRecurrenceFactor', 'StartDate', 'EndDate', 'StartTime', 'EndTime', 'Force', 'EnableException'
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Job', 'Schedule', 'Disabled', 'FrequencyType', 'FrequencyInterval', 'FrequencySubdayType', 'FrequencySubdayInterval', 'FrequencyRelativeInterval', 'FrequencyRecurrenceFactor', 'StartDate', 'EndDate', 'StartTime', 'EndTime', 'Owner', 'Force', 'EnableException'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should -Be 0
}
Expand Down

0 comments on commit ef13659

Please sign in to comment.