locked
Script to cleanup the C drive RRS feed

  • Question

  • Hi,

    I have SCOM 2007 R2 installed in our environment.  I need to cleanup the C drive space through powershell script. I have already prepared a powershell script. When we manually run the script through powershell, it clears the space from temp directory and other locations, which is futile. Now, my question is:

    Can I schedule the script through SCOM so that every time the alert for C drive appears, the script could run automatically and clear the space in C drive?

    Regards

    Wednesday, April 22, 2015 2:42 PM

Answers

  • Hi There,

    You can do it VIA recovery tasks.  So you will need to associate the recovery task with the low disk space alert. Once the alert appears SCOM will run the task. Refer the below on how to do it.

    http://www.server-log.com/blog/2012/9/18/running-powershell-scripts-as-recovery-tasks-in-system-cente.html

    https://social.technet.microsoft.com/Forums/systemcenter/en-US/2b5bb75a-e407-4c1b-ab9e-e0896dc1d83d/recovery-task-scom-execute-large-powershell-scripts?forum=operationsmanagerauthoring

    https://social.technet.microsoft.com/Forums/systemcenter/en-US/19e311d7-5adc-4a09-9df2-f552c455ea47/powershell-recovery-task-not-working?forum=operationsmanagergeneral


    Gautam.75801

    Wednesday, April 22, 2015 8:28 PM
  • Hi Vinay,

    Can you create a custom monitor targeting "Windows sever operating system" so it will apply for all the agents for free disk space alert.

    Then create a task for the same target and then associate the same to the monitor and see if the error does not appear.

    Also try this in another management pack or new management pack. 


    Gautam.75801

    Tuesday, April 28, 2015 6:54 AM

All replies

  • Hi There,

    You can do it VIA recovery tasks.  So you will need to associate the recovery task with the low disk space alert. Once the alert appears SCOM will run the task. Refer the below on how to do it.

    http://www.server-log.com/blog/2012/9/18/running-powershell-scripts-as-recovery-tasks-in-system-cente.html

    https://social.technet.microsoft.com/Forums/systemcenter/en-US/2b5bb75a-e407-4c1b-ab9e-e0896dc1d83d/recovery-task-scom-execute-large-powershell-scripts?forum=operationsmanagerauthoring

    https://social.technet.microsoft.com/Forums/systemcenter/en-US/19e311d7-5adc-4a09-9df2-f552c455ea47/powershell-recovery-task-not-working?forum=operationsmanagergeneral


    Gautam.75801

    Wednesday, April 22, 2015 8:28 PM
  • Hi Gautam,

    Thanks for writing in.

    I have just one query. I am using command line based scripting through SCOM, 2007 R2. Therein, I have provided the parameter as the path of the cleanup script. As a part of testing, we ran that on one server only. For enabling the script to run on management group servers, do we need to copy the script to all the servers, or it can run from a single path itself for all servers.

    Kind Regards

    Thursday, April 23, 2015 4:28 PM
  • Hi Vinay,

    Are you using a PS1 file to achieve this ? Or are you just using a single line shell command to clear the disk space ?


    Gautam.75801

    Friday, April 24, 2015 10:20 AM
  • Hi Gautam,

    I am using PS1 file. I copied the PS1 file at the same location on couple of servers and executed the script through command line rule- scom 2007 r2.

    I have one query. I have developed a powershell script to check the high memory consumption processes and created a diagnostic task for the alert "Available Megabytes of Memory is too low". Therein, during the creation of a diagnostic task, the target was by default set to Windows Server 2008 R2 Operating System. I tried to create the task by providing the below details:

    Post providing the parameters, I tried to create it, but it was throwing some error about the target, so I changed the target to Windows 2008 r2 core operating system. After the creation, the script is not yielding any results. However, when I created the command line rule with some interval, it was running fine, but that will not suffice the requirement. 

    Any suggestions on that.

    Kind Regards.


    Friday, April 24, 2015 9:40 PM
  • Hi There,

    If it is a PS1 script then you will need to place the script on the servers in a location and mention that there.

    Also Post the error what you are getting while targetting ?

    As wrong targettign will not make the task work as you have mentioned Windows server core right ? Do you have any core servers being monitored by your SCOM by the way ?


    Gautam.75801

    Saturday, April 25, 2015 5:30 PM
  • Hi Gautam,

    Thanks for writing in.

    Thank you for clearing out the first confusion.

    The error thrown was:

    No, server cores are not being monitored in our environment :)

    Is there any MP to monitor server core?

    Kind Regards.

    Monday, April 27, 2015 9:56 AM
  • Since the monitor for free space is targeted at Logical Disk (Server 2003/8/12), you'll need put the recovery in the Recovery tab of the Free Space monitor. You'll also probably want to disable it for non-system disks.


    "Fear disturbs your concentration"


    • Edited by andyinsdca Monday, April 27, 2015 9:26 PM
    Monday, April 27, 2015 9:24 PM
  • Hi Vinay,

    Can you create a custom monitor targeting "Windows sever operating system" so it will apply for all the agents for free disk space alert.

    Then create a task for the same target and then associate the same to the monitor and see if the error does not appear.

    Also try this in another management pack or new management pack. 


    Gautam.75801

    Tuesday, April 28, 2015 6:54 AM