• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 980
  • Last Modified:

WMI Filter: If day is Saturday or Sunday

I want a certain GPO to only apply on the weekends. I am trying to restrict all computer logons for a lab on Saturday and Sunday.

I thought a WMI filter would be an easy way to go that essientially applies the policy if the day is saturday or sunday. The policy would Deny a security group interactive logon rights.

If someone has an easier way, I am open to other ideas.
0
Joseph Moody
Asked:
Joseph Moody
  • 4
1 Solution
 
warddhoogheCommented:
If you want to restrict users or groups to logon on any of your servers/workstations then a logon hours restriction might be a better way.
This can also be done with a GPO   http://support.microsoft.com/kb/816666
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
The problem with that is I want to restrict all users on a certain group of computers but during only certain time frames.

Is that possible with that?
0
 
MidnightOneCommented:
You can pull the day of the week from WMI as seen in the code sample.

Given Thursday is listed as value 4, that suggests (and the WMI method lookup confirms) it goes from zero to six for Sunday to Saturday.
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_CurrentTime",,48) 
For Each objItem in colItems 
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_CurrentTime instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "DayOfWeek: " & objItem.DayOfWeek
Next

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Thank you MidnightOne! How would I use this filter in Group Policy?
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
This is the final WMI filter I used:

Select * from Win32_LocalTime where DayofWeek = '6' OR DayofWeek = '7'
0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Thank you so much! You taught me quite a bit!
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now