≡ Menu

Computer Uptime Compliance Policy

We have a new company requirement for workstations to have an uptime of no more than “N” days, and to force a reboot when machines are non-compliant. To enforce this, I decided the best way to evaluate computer uptime was with a compliance script.

The Compliance Script

  1. Create a new compliance item named Computer Uptime, and select the Supported Platforms appropriate for your environment.
  2. On the Settings tab, click New… and add a setting:
    Name: Uptime Days
    Setting type: Script
    Data type: Integer
  3. Under the Discovery Script section, click Add Script… and add the following Windows Powershell script:
    [math]::truncate((gwmi Win32_PerfFormattedData_PerfOS_System).SystemUpTime/60/60/24)
  4. Under Compliance Rules, add a new compliance rule:
    Name: Need Reboot
    Selected Setting: Computer Uptime \ Uptime Days
    Must comply with the following rule: Value returned is less than N (N is the integer of days for maximum uptime)
  5. Save the Compliance Item.
  6. Create a new Compliance Baseline named Computer Uptime, and add the CI to it.
  7. Note the CI ID NNNNN of the new Compliance Baseline you created – for the baseline, not the CI!  If you cannot see the CI ID, then add the CI ID column (while in Configuration Baselines, right click the columns, and check CI ID).

The Reboot Package

I could have simply used shutdown.exe to force a reboot of the machine, or initiated it using a PowerShell command as a remediation script. However, since our end users are used to seeing the Config Manager restart dialog for Software Updates and other installs that require a restart, I decided to keep their experience the same.

  1. Create a new package named Reboot Computer.  No source files will be needed. Save it.
  2. Create a new program:
    Name: Reboot
    Command line: cmd /c
    Run: Hidden
    Program can run: Whether or not a user is logged on
    After Running: Configuration Manager restarts computer

The Target Collection

Now we need a target collection of non-compliant machines to get the reboot deployment.

  1. Create a new collection named Non-compliant Computer Uptime.
  2. Add a membership rule query, with two criteria:
    Compliance Item Compliance State.CIID is equal to NNNNN (from the baseline you created above)
    and
    Configuration Item Compliance State.Compliance State Name is equal to “Non-Compliant”
  3. Evaluation should be a few times a day (every few hours), or set to use incremental updates if you [sparingly] use those in your environment.

The Deployments

  1. Deploy the Computer Uptime Compliance Baseline to the machines that need to comply with the uptime policy.  Set the evaluation to run every four hours, and no need to remediate since you are doing that outside of the compliance item.
  2. Deploy the Reboot program to your Non-compliant Computer Uptime collection:
    Required deployment
    Recurring installation (occurs every 1 day)
    Rerun behavior: Always Rerun
    If you are using maintenance windows, consider checking to perform both the installation and the reboot outside of maintenance windows.

Sit back and wait for the evaluations to happen. Once a machine is up at least N days, then it will end up in the target collection, get the deployment to reboot, and be removed from the collection after re-evaluating again. Users that are logged in will get the familiar restart warning message before the restart is enforced.

Some things to consider for the choices to make on evaluation frequencies, compliance rule values, and deployment settings:

  • Whether or not maintenance windows exist in the environment
  • The Computer Restart options set in Client Settings
{ 0 comments… add one }

Leave a Comment