Jump to content
rgg

How to keep workstations (including laptops) on overnight

Recommended Posts

We were having trouble managing workstations, especially laptops, because they were going offline overnight. This monitor/autofix setup has drastically improved the situation.

Components:

  1. Install and Apply Power Plan [function script]
    • This creates and runs a powershell script to download a .pow file, install the power plan, and apply it.
    • This assumes that @powerplanFileSource@ has been defined and points to a .pow file in the LTShare transfer folder. So if your powerplan file is \LTShare\Transfers\PowerPlans\nosleep.pow, you will have defined powerPlanFileSource = PowerPlans\nosleep.pow
    • This sets a variable @installAndApplyPowerPlanResult@ = success upon success, so you can check the result after calling it.
  2. Apply Power Plan [function script]
    • This creates and runs a powershell script to apply an already installed power plan
    • This assumes that @powerPlanName@ has been defined and is the power plan it should apply to the computer
    • This sets a variable @applyPowerPlanResult@ = success upon success, so you can check the result after calling it.
  3. Apply [YOUR POWER PLAN NAME] [script]
    • This script conditionally runs the two function scripts above. You set the required variables in lines 2 and 3, and it will check to see if the plan is installed or not and act accordingly.
    • This sets a variable @autofixResult@ = success upon success, so you can check it after calling it.
  4. ~Autofix incorrect power plan [script]
    • This is an autofix script to be called by a monitor. If called, it will run the Apply [YOUR POWER PLAN NAME] script.
    • If the script is successful, we're fine.
    • If the script fails, it will create a ticket with subject and body defined by lines 2 and 3 of the Then section, and if the monitor succeeds it will close the ticket with the note defined by line 2 of the Else section.
  5. On Incorrect Power Plan [monitor]
    • This is a RAWSQL monitor that fails if your power plan isn't applied, and will be configured to use an alert template executing ~Autofix incorreect power plan.

Configuration

  1. Create your power plan
    1. On a laptop, set up the desired power configuration, including lid actions. Save it with a name you want your clients to see if they go looking at their power plan.
    2. Get the GUID of your power plan with the powershell command
      • powercfg /List
    3. Export the power plan to a .pow file with the powershell command
      • powercfg -export "%UserProfile%\Desktop\MyPowerPlan.pow" GUID
      • (GUID is the GUID from the previous step)
    4. Move MyPowerPlan.pow somewhere in your LTShare\Transfer
  2. Import the attached files into Automate
  3. Modify the Apply [YOUR POWER PLAN NAME] script
    1. Rename it and change the Notes section as needed
    2. Set lines 2 and 3 to the correct values for the power plan you created and the file you exported
    3. Ensure line 24 runs the "Install and Apply Power Plan script
    4. Ensure line 34 runs the "Apply Power Plan script
  4. Modify the ~Autofix incorrect power plan script
    1. Set lines 2 and 3 of the Then section and line 2 of the Else section as desired
    2. Ensure line 13 points to the Apply [YOUR POWER PLAN NAME] script
  5. Modify the On Incorrect Power Plan monitor
    1. In Configuration>Additional Condition, change pp.currentPlan != "[YOUR POWER PLAN NAME]"  so it references the name of the power plan you created in step 1 (no brackets)
    2. In Configuration>Additional Condition, change WHERE AgentID=[YOUR MONINTOR ID] with the monitor id (this is set upon import)
  6. Create an alert template
    1. Go to Automation>Templates>Alert Templates (assuming automate 12)
    2. Click on New Template
    3. Name it as you like
    4. Add an alert to run the ~Autofix incorrect power plan script, applied every day all day

Now it's just a vanilla monitor setup where you enable the monitor for whatever groups you want (e.g. Patching.Patch Install - Workstations, Service Plans.Windows Workstations.Managed 24x7) and set it to use the alert template you created in step 6.

-rgg

 

*thanks to @Gavsto for his rawsql writeup. It's so good I just open it by default every time I'm starting a RAWSQL monitor.

 

~Autofix incorrect power plan.xml

Apply [YOUR POWER PLAN NAME].xml

Apply Power Plan.xml

incorrect_powerplan_monitor.sql

Install and Apply Power Plan.xml

  • Like 1

Share this post


Link to post
Share on other sites

I posted an internal RawSQL monitor that just checks for the power policy to match the defined name and issues a command to switch it if needed. In the example I posted you could even create a list of policies by hour, so that different policies would be applied at different times of day.

https://www.labtechgeek.com/topic/3507-manage-power-profiles-using-an-internal-monitor/

That monitor was sort of for fun, and only works if the specified power policy already exists. But if you want a lighter touch, just using the built in power plans, it works.

We actually use a similar setup as to what @rgg outlined above with scripts to create specific power policies, an EDF to control which policy should be enforced, an internal monitor to catch systems with a missing or incorrect power policy set and a script to correct it. We also have configured scheduled wakeups for Dell and HP Desktops through BIOS to automatically power on at 1:30 AM, plus enabled WOL/VPro where applicable to have additional methods to power on a system that has been shutdown. It works well except for clients with Vostro or random Whitebox/OEM systems that don't support the BIOS management features.

Share this post


Link to post
Share on other sites
On 4/2/2018 at 3:44 PM, rgg said:

 

The Configuration section does not contain the changes needed to script Apply Power Plan.  Should it?  Line 2 a ps1 and it seems that nowhere is that ps1 copied or installed or provided.  Line 11 would seem to need to be modified.  Also, the Install and Apply Power Plan script would seem to need to have changes outlined for lines 2,3,4, and 19.

Share this post


Link to post
Share on other sites

If it helps these two commands will disable standby and hibernate (on AC power only) in whatever the current power plan is.

%windir%\system32\powercfg.exe -change standby-timeout-ac 0

%windir%\system32\powercfg.exe -change hibernate-timeout-ac 0

Share this post


Link to post
Share on other sites

Hi @SteveYates @DarrenWhite99

Sorry if I am going over old topics, however I am looking for something very simple.

A script to set sleep settings on a device to never. We want to run this script on individual devices rather than across our estate.

Do you happen to have a script or guide that can achieve this?

 

Kind regards,

Share this post


Link to post
Share on other sites
On 3/25/2020 at 9:47 AM, Aenabs said:

Do you happen to have a script or guide that can achieve this?

Use Process Execute script function on the two commands I posted. :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...