Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

problem create job schedule smo

Hello,

i try to create a job schedule with
if ($J -match "FULL") {
            Write-Debug "Create SQL Agent Job Schedule..."
            $jobSchedule = new-object ('Microsoft.SqlServer.Management.Smo.Agent.JobSchedule') ($job, 'Schedule weekly')
            $jobSchedule.FrequencyTypes = "Weekly"
            $jobSchedule.FrequencySubDayTypes = "Once"
            $jobSchedule.ActiveStartTimeOfDay = $StartTS
            $jobSchedule.ActiveEndTimeOfDay = $EndTS
            $jobSchedule.FrequencyInterval = 1
            $jobSchedule.ActiveStartDate = get-date
            $jobSchedule.Create()
            }
TRAPPED: Create failed for JobSchedule 'Schedule weekly'.

How can I resolve this problem?
Thanks
Avatar of SubSun
SubSun
Flag of India image

Try with..
$jobSchedule.FrequencyTypes = [Microsoft.SqlServer.Management.Smo.Agent.FrequencyTypes]::Weekly
$jobSchedule.FrequencySubDayTypes = [Microsoft.SqlServer.Management.Smo.Agent.FrequencySubDayTypes]::Once

Open in new window

Ref : http://technet.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.agent.job.jobschedules.aspx
Avatar of bibi92

ASKER

Thanks, I have tested, it does not work.
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bibi92

ASKER

Thanks for the technet URL, I have found solution :
$jobsch.FrequencyTypes = [Microsoft.SqlServer.Management.SMO.Agent.FrequencyTypes]::Weekly
$jobsch.FrequencyInterval = [Microsoft.SqlServer.Management.SMO.Agent.WeekDays]::(Get-Date -Format "dddd")
$jobsch.FrequencyRecurrenceFactor = 1
$timespan =  New-Object -TypeName TimeSpan -argumentlist (get-random -Minimum 0 -Maximum 8), (get-random -Minimum 0 -Maximum 59), 00
$jobsch.ActiveStartTimeOfDay = $timespan
$jobsch.ActiveStartDate = (Get-Date -format "MM/dd/yyyy")