Avatar of bibi92
bibi92
Flag 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
PowershellMicrosoft SQL Server 2008

Avatar of undefined
Last Comment
bibi92

8/22/2022 - Mon
SubSun

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
bibi92

ASKER
Thanks, I have tested, it does not work.
ASKER CERTIFIED SOLUTION
SubSun

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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")
Your help has saved me hundreds of hours of internet surfing.
fblack61