For background info, anything you can do from the command line (either dos or powershell) you can also do through a script. Any script you create can be run automatically through the task scheduler. With that in mind, here’s how I would do it. For organization purposes, I like to create a folder named “scripts” on the C:\ drive and put all my production scripts there, often in subfolders to further organize them. I'm unable to add any pictures to this right now, but I can later if you need.
So let’s assume you have a group named “daytime”. This group is the group of folks who you want to log in only from 9 to 5. To add this group to the RDP group via the CMD prompt, use:
Code
Net localgroup “Remote Desktop Users” daytime /add
To remove this group from the RDP group via the command line, use:
Code
Net localgroup “Remote Desktop Users” daytime /delete
Note the quotation marks above. For any group with a space in the name, that is required.
To automate this, open notepad and paste the /add line. Click file, save as, in the file-type drop down box, pick all files, give it name like “daytime-add.bat” and save it to the C:\scripts folder.
To create a scheduled task to run this batch file, open task scheduler, click “action” near the top, “create basic task”, and the wizard opens. Give it a name, something intelligible so you remember what it is without having to look closer at it, and click next. Choose “daily” inside the “trigger” section and click next. Give it a start time and click next. Select “start a program” and click next. Click “browse” to navigate to your batch file, click next and verify everything is correct and then hit finish.
Once that’s done, the task will appear in the list of scheduled tasks. If you right-click the task, you can run it on demand to test it, disable it without deleting it, delete it, or edit it’s properties.
To remove that group from the rdp group, do that whole process over, but using the /delete line instead. The same goes for any other group you want to control this way, create a batch file with the other group name and the add or delete action, and make a scheduled task for it.
I highly recommend testing this with empty groups before just throwing it out there and assuming it’ll work. To do this, all you’d need to do is create two new local groups on the machine, edit the batch file to reflect the names of the test groups, and manually run it to see what happens. Once you know the batch file is good and will work, then work on getting it into scheduled tasks. You may have to open up the properties after creating it to make changes, like what username it’s supposed to run under.