OSD Task Seqeunce High Performance – Native PowerCFG – VBS – MDT -SCCM

So like a lot of ConfigMgr Admins out there I strive to produce the fastest and most robust task sequences I can. This obviously led me down the path of configuring the Power Settings on the OS during deployment and capture phases.

The issue that I found is probably like many of you have and that is that it requires exporting the native “PowerCFG.exe” from each version of the OS that you would like to dynamically change the power configuration during Operating System Deployment.

So Jack and I were discussing why… in short… do we not use the “PowerCFG.exe” that is is already in the OS that we are configuring. Anyway after a little persuasion we came up with this little beauty of a script. This script will also create a CMTrace “Log”Β  using its name in the Log folder that is currently in use in the Task sequence.

Setup is simple:

MDT Setup
  • For MDT just place it into the Scripts folder of you “Deployment Share”.”
    "<YourDeploymentShareDrive>:\<DeploymentShareRoot>\Scripts\Set-PowerCFG.wsf"
  • You can then call this during any stage of you Reference image capture i.e. WinPE or full OS phase to set the power cfg with these below Command Lines:
    "%ScriptRoot%\Set-PowerCFG.wsf" /High
    "%ScriptRoot%\Set-PowerCFG.wsf" /Bal
SCCM Setup
  • For SCCM you must be using the MDT integration (if you’re not… Start now!), you can make it work without it but I will not cover that here.
  • Find your current MDT Toolkit Package that is associated with the Task Sequence you would like to configure power settings in.
  • Open the “Source” location of your toolkit package, then open the scripts folder.

  • Once inside the scripts folder copy the “Set-PowerCFG.wsf” into it.

    • Now, update the Package in ConfigMgr.
    • Next we need to add the step to the task sequence. It must go after the “Use Toolkit Package” step in the task sequence. (If you have a reboot and remember to add another use “Toolkit package”.)
    • Create a new “Run Command Line Step” and add one of the below commands.
cscript.exe "%deployroot%\scripts\Set-PowerCFG.wsf" /High
cscript.exe "%deployroot%\scripts\Set-PowerCFG.wsf" /Bal

And that is it. Your Task sequence will now set the Power Configuration Profile using the current OS’s native “Powercfg.exe”

Anyway as always, script is provided as is and if you do mod it, there is a line to add your name.

The Script:

<job id="Set-PowerCFG">
<script language="VBScript" src="ZTIUtility.vbs"/>
<script language="VBScript">
 
' //***************************************************************************
' // ***** Script Header *****
' //
' // Solution: Solution Accelerator for Microsoft Deployment
' // File: Set-PowerCFG.wsf
' // Requirements: ZTIUtility.vbs Must be located in the same folder id running from ConfigMGR.
' // Author: SCCMOG Richie Schuster - SCCMOG.com
' // Moddedby: YOURNAMEHERE
' // Date: 21/03/2018
' // Purpose:  Script sets power profile during OS deployment - Can be run in WinPE or full OS.
' //
' // Usage: cscript Set-PowerConfig.wsf [/High] - Sets high performance | [/Bal] - Sets balanced performance. [/debug:true] 
' //
' // Customer Build Version: 1.0.0
' // Customer Script Version: 1.0.0
' // Customer History:
' //
' // ***** End Header *****
' //***************************************************************************
 
'//----------------------------------------------------------------------------
'//
'// Global constant and variable declarations
'//
'//----------------------------------------------------------------------------
 
'Option Explicit
Dim strPwrBalanced	: strPwrBalanced	= "381b4222-f694-41f0-9685-ff5bb260df2e"
Dim strPwrHighPerf	: strPwrHighPerf	= "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c"
Dim strPwrCFGexe	: strPwrCFGexe		= "powercfg.exe"
Dim strPwrCFGswitch : strPwrCFGswitch	= " /S "
Dim strPwrCFGFolder : strPwrCFGFolder	= "PowerCFG"
Dim strWmessage		: strWmessage		= "Please enter one or more arguments 'E.G : /High for High Performance Profile' or '/Bal for Balanced Profile'"
Dim strWindir		: strWindir			= oShell.ExpandEnvironmentStrings("%Windir%")
Dim strSysWow64		: strSysWow64		= "SysWOW64"
Dim strSystem32		: strSystem32		= "System32"

Dim  PowerCFG, strPwrProfile, strPwrProfileLog, ostrCMD, iRetVal
 
'//----------------------------------------------------------------------------
'// End declarations
'//----------------------------------------------------------------------------

'//----------------------------------------------------------------------------
'// Main routine
'//----------------------------------------------------------------------------
'Begin
oLogging.CreateEntry "Beginning Set-PowerCFG 1.0.0", LogTypeInfo
oLogging.CreateEntry "Active Log Path: " & oUtility.LogPath, LogTypeInfo

'Take Script Args
oLogging.CreateEntry "Getting set Arguments...", LogTypeInfo
If Not WScript.Arguments.Count >= 1 Then
	oLogging.ReportFailure strWmessage, iError
End If 
If WScript.Arguments.Named.Exists("High") Then 
	strPwrProfile = strPwrHighPerf
	strPwrProfileLog = "High"
	oLogging.CreateEntry "Power Profile requested to be set: " & strPwrProfileLog, LogTypeInfo
ElseIf WScript.Arguments.Named.Exists("Bal") Then 
	strPwrProfile = strPwrBalanced
	strPwrProfileLog = "Balanced"
	oLogging.CreateEntry "Power Profile requested to be set: " & strPwrProfileLog, LogTypeInfo
Else
	oLogging.ReportFailure strWmessage, iError
End If

'OS Info for Log
oLogging.CreateEntry "Getting information on Operating System", LogTypeInfo
oLogging.CreateEntry "OS Name: " & oEnvironment.Item("OSVERSION"), LogTypeInfo
oLogging.CreateEntry "OS Version: " & oEnvironment.Item("OSCURRENTVERSION"), LogTypeInfo
oLogging.CreateEntry "OS Architecture: " & oEnvironment.Item("Architecture"), LogTypeInfo

'Get OS Arch and set folder to run powerCFG from.
If oEnvironment.Item("Architecture") = "X86" Or oEnvironment.Item("_SMSTSInWinPE") = "true" Or oEnvironment.Item("OSVERSION") = "WinPE" Then
	strPwrCFGFolder = strSystem32
	oLogging.CreateEntry "Using PowerCFG.exe from: " & strPwrCFGFolder & " Folder.", LogTypeInfo
Elseif oEnvironment.Item("Architecture") = "X64" Then
	strPwrCFGFolder = strSysWow64
	oLogging.CreateEntry "Using PowerCFG.exe from: " & strPwrCFGFolder & " Folder.", LogTypeInfo
Else
	oLogging.ReportFailure "Machine Architecture not supported.", iError
End If

'Setting PowerCFG Location
strCMD = strWindir &  "\" & strPwrCFGFolder & "\" & strPwrCFGexe

'Logging Command
oLogging.CreateEntry "PowerCFG Location set to: " & strCMD, LogTypeInfo
oLogging.CreateEntry "Testing Location Available..." & strCMD, LogTypeInfo
iRetVal = oFso.FileExists(strPath)

If iRetVal = Success Then
	oLogging.CreateEntry "Found PowerCFG.exe at Location: " & strCMD, LogTypeInfo
	strCMD =  Chr(34) & strCMD &  Chr(34)
	oLogging.CreateEntry "Building Command to be run", LogTypeInfo
	strCMD = strCMD & strPwrCFGswitch & strPwrProfile
	oLogging.CreateEntry "Final Command to be run: " & strCMD, LogTypeInfo
	'Run PowerCFG
	iRetVal = oUtility.RunWithHeartbeat(strCMD)
	If iRetVal = Success Then
		oLogging.CreateEntry "Successfully set " & strPwrProfileLog & " Performance profile.", LogTypeInfo
		oLogging.CreateEntry "Set-PowerCFG 1.0.0 Complete...", LogTypeInfo
	Else
		oLogging.ReportFailure "Failed to set " & strPwrProfileLog & " Performance profile.", iError
	End If
Else
	oLogging.ReportFailure "Failed to find path: " & strCMD, iError
End If

	</script>
</job>

Cheers,

SCCMOG

6 Replies to “OSD Task Seqeunce High Performance – Native PowerCFG – VBS – MDT -SCCM”

  1. Thank you for this. Now you say that this will work whether in WinPE or Windows, but if I recall, there is no powercfg.exe in WinPE.

  2. At what points in the task sequence should be be executed for best results.

    Does this need to enabled again after each reboot or will it hold the settings until its set back later in the task.

    1. Hi Brian,

      As WinPE does not hold changes on reboot, if you are rebooting, for example BIOS upgrades or BIOS to UEFI, then it must be rerun after every reboot.
      The next stage would be after the ConfigMgr Client setup task.
      But remember this can also be used while capturing the image (MDT), this will mean that the image is captured in High performance mode and during the Windows setup phase (Setting up devices) this will also run in high performance mode as this portion is set to balanced by default.

      Hope that helps.
      SCCMOG

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright 2016 SCCMOG | All Rights Reserved

css.php