Author Posts

June 3, 2014 at 8:11 am

ok, I have been in the Social Forums with this question, and they tell me it cant be done.
If I had my servers in Core mode, versus the GUI, how would I change this schedule from weekly to daily? (see attached screenshots)

and better yet, if I had 1000 servers how would I check to see what they were set for?
(Background....OpsMan2012 R2 is telling me my drives need optimized, I know how to optimize them, but would rather programaticaly change the schedule to daily on all my servers, and then deal with the outlayers that cant stay with-in the range.)

thanks
Guy
(Social Link
http://social.technet.microsoft.com/Forums/windowsserver/en-US/ba48760d-b295-4dd1-b701-8977d3344b90/drive-optimization-setting-the-frequency?forum=winserverpowershell )

June 3, 2014 at 8:18 am

So does this schedule live in Scheduled Tasks or entirely in SCOM?

The Social link included a post from "Anna" about scheduling the command in Scheduled Tasks. Windows 8 and Windows Server 2012 certainly contain commands that would let you set up that schedule on multiple computers, provided you can communicate with them via Remoting. On older machines, you could certainly do it via WMI instead if you preferred.

That's what the Invoke-Command reference was. That would let you run Anna's commands on one or more remote computers. It would require them to have Remoting enabled; almost any "do this on hundreds of remote computers" will involve Remoting, since it's the technology PowerShell uses to do that.

June 3, 2014 at 8:47 am

Ok, this lives inside Scheduled Tasks, under task scheduler library ->Windows -> Defrag.
I guess I figured it was running the PowerShell command and not %windir%\system32\defrag.exe -c -h -o -$

I can push the script via PowerShell to run each night, and might do that as part of my build process, I guess I drank the Kool-Aid of if you can set it in the GUI, it really is just running a PowerShell command behind the scenes, which in most cases, I have found to be true, but some things are still running legacy technology.

But my Standardization Side of me (read as OCD), does not like the GUI Saying weekly, but I am running it Nightly. I will have to go back and change those as I run across them.

once again, thank you for your quick response.

-Guy

June 3, 2014 at 9:47 am

In Server 2012 / Windows 8 or later, there's a ScheduledTasks module with PowerShell cmdlets that can allow you to get and set that information (Get-ScheduledTask, Get-ScheduledTaskInfo, etc). If you need to do this on older operating systems, you'll have to work with schtasks.exe instead.

For example:

schtasks.exe /Query /TN "Microsoft\Windows\Defrag\ScheduledDefrag" /XML

This output can be cast to the [xml] type in PowerShell to work with it fairly easily. See http://blogs.technet.com/b/heyscriptingguy/archive/2013/12/14/working-with-task-scheduler-xml.aspx for some good examples of this.

The content of this task seems to have changed quite a bit between Server 2008 R2 and Server 2012, so you might need to use different commands to modify (or more likely, delete and recreate) the task depending on the OS.

June 3, 2014 at 2:14 pm

Thank You, David.
This helps a lot, At least I can pull this from all my machines and figure out which ones need to be changed.
between you and Anna's script, I should be able to knock out this inconstancy pretty quickly.

thanks again.
Guy