Freigeben über


CrawlScheduleDaysOfWeek Powershell automation scipting for crawl schedules

A coworker of mine ran into an issue yesterday that baffled us both for a few minutes, and due to the lack of information online I thought I would write about it.

My coworker wrote a script in PowerShell to automate the scheduling of incremental crawls, being there were more than 80 of them to set up. When he was using the "CrawlScheduleDaysofWeek" parameter he found that the days of week were based on numbers and not names (makes sense right?).

In our attempts to dissect how the days where numbered we output and found that Sunday equaled 1, great . . . so now Monday equaled 2 . . . now we are getting some where. But the problem was Tuesday does not equal 3 it actually equals 4.

Let me explain why, in our coding background we found that for VB, C#, Java the "daysofweek" parameter is consistent in format no matter the language. The PowerShell team has taken this common format and applied it to the SharePoint PowerShell, which is great. Now we know that PowerShell has the same roots as other programming languages (or at least tries to stick with what people are already used too).

Below is the table (and for those of you yes it is a binary based format)

Here is the table for days of week number equivalent:

Member Name Description
Sunday

Value = 1

Monday Value = 2
Tuesday Value = 4
Wednesday Value = 8
Thursday Value = 16
Friday

Value = 32

Saturday Value = 64

So in order to get the right days of week simply add the numbers up and they will equal the days of week you want checked. In our case we wanted everyday but Tuesday to be checked for incremental crawls. We simply took all the days number equivelants and added them together minus Tuesday (127 - 4) which equaled 123. When the script was ran it set up the schedule for Sunday thru Saturday and excluded Tuesdays checkbox in the SharePoint Crawl UI. Perfect.

Hope this helps everyone.

 Some associated links that were used to put this together:

https://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.pocketoutlook.daysofweek.aspx

https://technet.microsoft.com/en-us/library/ff607675.aspx