{"id":815657,"date":"2026-05-28T12:23:24","date_gmt":"2026-05-28T12:23:24","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=815657"},"modified":"2026-05-28T12:23:24","modified_gmt":"2026-05-28T12:23:24","slug":"guia-do-windows-power-management-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/pt-br\/script-hub\/guia-do-windows-power-management-powershell\/","title":{"rendered":"Dominando o gerenciamento de energia do Windows: Um guia do PowerShell para profissionais de TI e MSPs"},"content":{"rendered":"<h2>Principais conclus\u00f5es<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"1\"><strong>Gerenciamento automatizado de energia<\/strong>: O script automatiza os ajustes das configura\u00e7\u00f5es de energia e suspens\u00e3o nos dispositivos Windows, aumentando a efici\u00eancia dos ambientes de TI.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\"><strong>Op\u00e7\u00f5es vers\u00e1teis de configura\u00e7\u00e3o<\/strong>: Oferece par\u00e2metros para configura\u00e7\u00f5es de tela, hiberna\u00e7\u00e3o, tempo limite de suspens\u00e3o, planos de energia e suspens\u00e3o USB, adapt\u00e1veis a v\u00e1rias necessidades.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><strong>Capacidade de implanta\u00e7\u00e3o remota<\/strong>: Ideal para MSPs e departamentos de TI, permitindo a configura\u00e7\u00e3o remota em v\u00e1rios dispositivos.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\"><strong>Compatibilidade e limita\u00e7\u00f5es<\/strong>: Compat\u00edvel com o Windows 7 e posterior, mas limita\u00e7\u00f5es espec\u00edficas do dispositivo podem se aplicar a determinadas configura\u00e7\u00f5es.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\"><strong>Controle granular das configura\u00e7\u00f5es<\/strong>: Oferece mais flexibilidade e precis\u00e3o em compara\u00e7\u00e3o com os ajustes manuais tradicionais ou pol\u00edticas de grupo.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"6\" data-aria-level=\"1\"><strong>Verifica\u00e7\u00e3o do aplicativo de configura\u00e7\u00f5es<\/strong>: Inclui fun\u00e7\u00f5es para confirmar a aplica\u00e7\u00e3o bem-sucedida de novas configura\u00e7\u00f5es.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"7\" data-aria-level=\"1\"><strong>Os testes s\u00e3o cruciais<\/strong>: \u00c9 aconselh\u00e1vel testar o script em um ambiente controlado para evitar interrup\u00e7\u00f5es n\u00e3o intencionais.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"8\" data-aria-level=\"1\"><strong>Integra\u00e7\u00e3o com ferramentas de gerenciamento de TI<\/strong>: Pode ser combinado de forma eficaz com plataformas como o NinjaOne para um gerenciamento abrangente de ativos de TI.<\/li>\n<\/ul>\n<p>O gerenciamento das configura\u00e7\u00f5es de energia em dispositivos Windows \u00e9 um aspecto crucial do gerenciamento de TI, garantindo a efici\u00eancia energ\u00e9tica e o desempenho ideal. O script do PowerShell fornecido oferece uma solu\u00e7\u00e3o abrangente para que os profissionais de TI ajustem as configura\u00e7\u00f5es de energia e suspens\u00e3o em sistemas baseados no Windows. Esse recurso \u00e9 essencial para manter a integridade do sistema, prolongar a vida \u00fatil da bateria e garantir que os dispositivos funcionem de forma eficiente em v\u00e1rios ambientes.<\/p>\n<h2>Hist\u00f3rico<\/h2>\n<p>No \u00e2mbito da TI, especialmente para os <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">provedores de servi\u00e7os gerenciados (MSPs)<\/a> e departamentos de TI, a capacidade de ajustar remotamente e de forma program\u00e1tica as configura\u00e7\u00f5es de energia em v\u00e1rios dispositivos \u00e9 inestim\u00e1vel. Tradicionalmente, isso exigia interven\u00e7\u00e3o manual ou <a href=\"https:\/\/www.ninjaone.com\/blog\/how-to-force-a-gpupdate-remotely-with-powershell\/\">altera\u00e7\u00f5es na pol\u00edtica do grupo<\/a>, o que pode ser inc\u00f4modo e demorado. O script que estamos discutindo simplifica esse processo, permitindo uma configura\u00e7\u00e3o de energia precisa e variada em uma frota de dispositivos. Sua versatilidade em lidar com diferentes configura\u00e7\u00f5es, como tempo limite de tela, hiberna\u00e7\u00e3o e suspens\u00e3o, bem como planos de energia e configura\u00e7\u00f5es de suspens\u00e3o USB, torna-o uma ferramenta poderosa para profissionais de TI.<\/p>\n<h2>O roteiro:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">&lt;#\r\n.SYNOPSIS\r\n    Set Power and Sleep Settings. It can adjust just the plugged in or battery settings if requested.\r\n    Please Note not all devices support all options.\r\n.DESCRIPTION\r\n    Please Note not all devices support all options.\r\n    Options: ScreenTimeout, HibernateTimeout, SleepTimeout, Disk Timeout, PowerPlan, Lid Action, Wake Timers, USB Suspend, Critical Action\r\n    Low Action, Power Button Action, Critical Level, Low Level, Reserve Level, Critical Notification, and Low Notification.\r\n.EXAMPLE\r\n    (No Parameters)\r\n    \r\n    By default The Script doesn't do anything without some parameters.\r\n.LINK \r\n    https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/power\/power-policy-settings\r\n\r\nPARAMETER: -ScreenTimeout \"60\"\r\n    Replace 60 with any time in seconds to set the screen timeout. (0 for disabled)\r\n\r\nPARAMETER: -HibernateTimeout \"28800\"\r\n    Replace 28800 with any time in seconds. (0 for disabled)\r\n\r\nPARAMETER: -SleepTimeout \"14400\"\r\n    Replace 14400 with any time in seconds. (0 for disabled)\r\n\r\nPARAMETER: -DiskTimeout \"0\"\r\n    Replace 0 with your desired time in seconds. (0 for disabled)\r\n\r\nPARAMETER: -PowerPlan \"High Performance\"\r\n    Replace \"High Performance\" with your desired power plan. Keep in mind that most newer computers no longer have seperate power plans.\r\n\r\nPARAMETER: -LidAction \"Nothing\"\r\n    Replace Nothing with one of these three available options. Sleep, Shutdown, Nothing.\r\n    Will be skipped for non-laptops and this script cannot verify if the action was successfully set.\r\n\r\nPARAMETER: -AllowWakeTimers\r\n    Allows the ability for software to wake the computer from sleep at a later date.\r\n\r\nPARAMETER: -DisableWakeTimers\r\n    Disables the ability for software to wake the computer from sleep at a later date.\r\n\r\nPARAMETER: -EnableUSBSuspend\r\n    Allows the OS to suspend USB devices to conserve power.\r\n\r\nPARAMETER: -DisableUSBSuspend\r\n    Disable's the OS's ability to suspend USB devices to conserve power.\r\n\r\nPARAMETER: -CriticalAction \"Hibernate\"\r\n    Replace Hibernate with your desired action for when the machine is at a \"Critical\" batter level.\r\n    Valid Options: Hibernate, Sleep, Shutdown, Nothing\r\n\r\nPARAMETER: -LowAction \"Hibernate\"\r\n    Replace Hibernate with your desired action for when the machine is at a \"Low\" battery level.\r\n    Valid Options: Hibernate, Sleep, Shutdown, Nothing.\r\n\r\nPARAMETER: -CriticalLevel \"7\"\r\n    Replace 7 with your desired battery percent level to be considered critical (without the % symbol).\r\n\r\nPARAMETER: -LowLevel \"10\"\r\n    Replace 10 with your desired battery percent level to be considered low (without the % symbol).\r\n\r\nPARAMETER: -LowNotify\r\n    Allows the notification that comes in when the battery hits \"low\" levels.\r\n\r\nPARAMETER: -AC\r\n    Only applies your chosen battery settings to the \"Plugged In\" section of a power plan.\r\n\r\nPARAMETER: -DC\r\n    Only applies your chosen battery settings to the \"Battery\" section of a power plan.\r\n.OUTPUTS\r\n    None\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 7, Windows Server 2008\r\n    General notes\r\n    Version: Initial Release\r\nBy using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https:\/\/www.ninjaone.com\/terms-of-use.\r\n    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. \r\n    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. \r\n    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. \r\n    Warranty Disclaimer: The script is provided \u201cas is\u201d and \u201cas available\u201d, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. \r\n    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. \r\n    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. \r\n    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).\r\n#&gt;\r\n\r\n[CmdletBinding()]\r\nparam (\r\n    [Parameter()]\r\n    [String]$ScreenTimeout,\r\n    [Parameter()]\r\n    [String]$HibernateTimeout,\r\n    [Parameter()]\r\n    [String]$SleepTimeout,\r\n    [Parameter()]\r\n    [String]$DiskTimeout,\r\n    [Parameter()]\r\n    [String]$PowerPlan,\r\n    [Parameter()]\r\n    [String]$LidAction,\r\n    [Parameter()]\r\n    [Switch]$AllowWakeTimers,\r\n    [Parameter()]\r\n    [Switch]$DisableWakeTimers,\r\n    [Parameter()]\r\n    [Switch]$EnableUSBSuspend,\r\n    [Parameter()]\r\n    [Switch]$DisableUSBSuspend,\r\n    [Parameter()]\r\n    [String]$CriticalAction,\r\n    [Parameter()]\r\n    [String]$LowAction,\r\n    [Parameter()]\r\n    [String]$CriticalLevel,\r\n    [Parameter()]\r\n    [String]$LowLevel,\r\n    [Parameter()]\r\n    [Switch]$LowNotify,\r\n    [Parameter()]\r\n    [Switch]$LowNoNotify,\r\n    [Parameter()]\r\n    [Switch]$AC,\r\n    [Parameter()]\r\n    [Switch]$DC\r\n)\r\n\r\nbegin {\r\n    # Grab Script Variables if present\r\n    if ($env:policy -and $env:policy -notlike \"null\") {\r\n        switch ($env:policy) {\r\n            \"Plugged In\" { $AC = $True }\r\n            \"On Battery\" { $DC = $True }\r\n        }\r\n    }\r\n    if ($env:screenTimeoutInMinutes -and $env:screenTimeoutInMinutes -notlike \"null\") { $ScreenTimeout = $env:screenTimeoutInMinutes }\r\n    if ($env:hibernateTimeoutInMinutes -and $env:hibernateTimeoutInMinutes -notlike \"null\") { $HibernateTimeout = $env:hibernateTimeoutInMinutes }\r\n    if ($env:sleepTimeoutInMinutes -and $env:sleepTimeoutInMinutes -notlike \"null\") { $SleepTimeout = $env:sleepTimeoutInMinutes }\r\n    if ($env:diskTimeoutInMinutes -and $env:diskTimeoutInMinutes -notlike \"null\") { $DiskTimeout = $env:diskTimeoutInMinutes }\r\n    if ($env:powerPlan -and $env:powerPlan -notlike \"null\") { $PowerPlan = $env:powerPlan }\r\n    if ($env:lidAction -and $env:lidAction -notlike \"null\") { $LidAction = $env:lidAction }\r\n    if ($env:wakeTimers -and $env:wakeTimers -notlike \"null\") {\r\n        switch ($env:wakeTimers) {\r\n            \"Enable\" { $AllowWakeTimers = $True }\r\n            \"Disable\" { $DisableWakeTimers = $True }\r\n        }\r\n    }\r\n    if ($env:usbSuspend -and $env:usbSuspend -notlike \"null\") {\r\n        switch ($env:usbSuspend) {\r\n            \"Enable\" { $EnableUSBSuspend = $True }\r\n            \"Disable\" { $DisableUSBSuspend = $True }\r\n        }\r\n    }\r\n    if ($env:criticalBatteryAction -and $env:criticalBatteryAction -notlike \"null\") { $CriticalAction = $env:criticalBatteryAction }\r\n    if ($env:lowBatteryAction -and $env:lowBatteryAction -notlike \"null\") { $LowAction = $env:lowBatteryAction }\r\n    if ($env:criticalBatteryLevel -and $env:criticalBatteryLevel -notlike \"null\") { $CriticalLevel = $env:criticalBatteryLevel }\r\n    if ($env:lowBatteryLevel -and $env:lowBatteryLevel -notlike \"null\") { $LowLevel = $env:lowBatteryLevel }\r\n    if ($env:lowNotification -and $env:lowNotification -notlike \"null\") {\r\n        switch ($env:lowNotification) {\r\n            \"Enable\" { $LowNotify = $True }\r\n            \"Disable\" { $LowNoNotify = $True }\r\n        }\r\n    }\r\n\r\n    if ($ScreenTimeout) { [int]$ScreenTimeoutValue = [int]$ScreenTimeout * 60 }\r\n    if ($HibernateTimeout) { [int]$HibernateTimeoutValue = [int]$HibernateTimeout * 60 }\r\n    if ($SleepTimeout) { [int]$SleepTimeoutValue = [int]$SleepTimeout * 60 }\r\n    if ($DiskTimeout) { [int]$DiskTimeoutValue = [int]$DiskTimeout * 60 }\r\n    if ($CriticalLevel){ [int]$CriticalLevelValue = [int]$CriticalLevel }\r\n    if ($LowLevel){ [int]$LowLevelValue = [int]$LowLevel }\r\n\r\n    # Elevation Test\r\n    function Test-IsElevated {\r\n        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()\r\n        $p = New-Object System.Security.Principal.WindowsPrincipal($id)\r\n        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)\r\n    }\r\n\r\n    if (\r\n        -not $ScreenTimeout -and -not $HibernateTimeout -and -not $SleepTimeout -and -not $DiskTimeout -and -not $PowerPlan -and\r\n        -not $LidAction -and -not $AllowWakeTimers -and -not $DisableWakeTimers -and -not $EnableUSBSuspend -and\r\n        -not $DisableUSBSuspend -and -not $CriticalAction -and -not $LowAction -and -not $CriticalLevel -and\r\n        -not $LowLevel -and -not $LowNotify -and -not $LowNoNotify\r\n    ) {\r\n        Write-Error -Message '[Error] No action given!'\r\n        exit 1\r\n    }\r\n    \r\n    # Check for battery and whether or not the device is a laptop\r\n    if ($PSVersionTable.PSVersion.Major -lt 5) {\r\n        $BatteryCheck = @(Get-WmiObject -Class Win32_Battery).Count -gt 0\r\n        $LaptopCheck = Get-WmiObject -Class win32_systemenclosure | Where-Object { $_.chassistypes -eq 9 -or $_.chassistypes -eq 10 -or $_.chassistypes -eq 14 }\r\n    }\r\n    else {\r\n        $BatteryCheck = @(Get-CimInstance -Class Win32_Battery).Count -gt 0\r\n        $LaptopCheck = Get-CimInstance -Class win32_systemenclosure | Where-Object { $_.chassistypes -eq 9 -or $_.chassistypes -eq 10 -or $_.chassistypes -eq 14 }\r\n    }\r\n    \r\n    # Function to test if policy was set correctly\r\n    function Test-PowerValue {\r\n        [CmdletBinding()]\r\n        param(\r\n            [Parameter()]\r\n            [String]$GUID,\r\n            [Parameter()]\r\n            [String]$Index,\r\n            [Parameter()]\r\n            [int]$Value,\r\n            [Parameter()]\r\n            [String]$Setting\r\n        )\r\n\r\n        # LidAction shows no information so we'll issue a warning and then exit the test function.\r\n        if ($GUID -eq \"SUB_BUTTONS\" -and $Index -eq \"5ca83367-6e45-459f-a27b-476b1d01c936\") {\r\n            Write-Warning \"Unable to verify LidAction via script.\"\r\n            break\r\n        }\r\n\r\n        # Values are stored in hex so we'll need to convert it.\r\n        $Hex = \"0x\" + '{0:X8}' -f $Value\r\n\r\n        $PowerQuery = powercfg.exe \/QUERY SCHEME_CURRENT $GUID | Out-String\r\n        $RelevantSetting = $PowerQuery -split \"Power Setting GUID:\" | Where-Object { $_ -like \"*$Index*\" }\r\n        if (-not ($RelevantSetting)) {\r\n            Write-Warning \"Unable to verify setting for $GUID $Index. This option may not exist for this machine.\"\r\n            break\r\n        }\r\n\r\n        # Depending on how the script was ran we'll need to verify in different ways (ex. its on a laptop or only AC was specified)\r\n        if ($AC -or -not $BatteryCheck) {\r\n            $ACQuery = $RelevantSetting -split 's{2}' | Where-Object { $_ -eq \"Current AC Power Setting Index: $Hex\" }\r\n\r\n            # Actual check code is really similar though (only difference is AC vs DC).\r\n            if (-not $ACQuery) {\r\n                Write-Warning \"AC Value of $Hex Not Found for $GUID $Index. You may want to verify the results.\"\r\n                break\r\n            }\r\n        }\r\n        elseif ($DC) {\r\n            $BatteryQuery = $RelevantSetting -split 's{2}' | Where-Object { $_ -eq \"Current DC Power Setting Index: $Hex\" }\r\n\r\n            if (-not $BatteryQuery) {\r\n                Write-Warning \"DC Value of $Hex Not Found for $GUID $Index. You may want to verify the results.\"\r\n                break\r\n            }\r\n        }\r\n        else {\r\n            $BatteryQuery = $RelevantSetting -split 's{2}' | Where-Object { $_ -eq \"Current DC Power Setting Index: $Hex\" }\r\n            if (-not $BatteryQuery) {\r\n                Write-Warning \"DC Value of $Hex Not Found for $GUID $Index. You may want to verify the results.\"\r\n                break\r\n            }\r\n\r\n            $ACQuery = $RelevantSetting -split 's{2}' | Where-Object { $_ -eq \"Current AC Power Setting Index: $Hex\" }\r\n            if (-not $ACQuery) {\r\n                Write-Warning \"AC Value of $Hex Not Found for $GUID $Index. You may want to verify the results.\"\r\n                break\r\n            }\r\n        }\r\n\r\n        Write-Host \"Successfully set power setting for $Setting!\"\r\n    }\r\n    function Set-PowerAction {\r\n        [CmdletBinding()]\r\n        param(\r\n            [Parameter()]\r\n            [ValidateSet(\"Nothing\", \"Sleep\", \"Hibernate\", \"ShutDown\")]\r\n            [String]$Action,\r\n            [Parameter()]\r\n            [String]$GUID,\r\n            [Parameter()]\r\n            [String]$Index,\r\n            [Parameter()]\r\n            [String]$Setting\r\n        )\r\n        try {\r\n            switch ($Action) {\r\n                \"Nothing\" {\r\n                    if ($AC -or -not $BatteryCheck) {\r\n                        powercfg.exe \/SETACVALUEINDEX SCHEME_CURRENT $GUID $Index 0\r\n                    }\r\n                    elseif ($DC) {\r\n                        powercfg.exe \/SETDCVALUEINDEX SCHEME_CURRENT $GUID $Index 0\r\n                    }\r\n                    else {\r\n                        powercfg.exe \/SETACVALUEINDEX SCHEME_CURRENT $GUID $Index 0\r\n                        powercfg.exe \/SETDCVALUEINDEX SCHEME_CURRENT $GUID $Index 0\r\n                    }\r\n    \r\n                    Test-PowerValue $GUID $Index 0 -Setting $Setting\r\n                }\r\n                \"Sleep\" {\r\n                    if ($AC -or -not $BatteryCheck) {\r\n                        powercfg.exe \/SETACVALUEINDEX SCHEME_CURRENT $GUID $Index 1\r\n                    }\r\n                    elseif ($DC) {\r\n                        powercfg.exe \/SETDCVALUEINDEX SCHEME_CURRENT $GUID $Index 1\r\n                    }\r\n                    else {\r\n                        powercfg.exe \/SETACVALUEINDEX SCHEME_CURRENT $GUID $Index 1\r\n                        powercfg.exe \/SETDCVALUEINDEX SCHEME_CURRENT $GUID $Index 1\r\n                    }\r\n    \r\n                    Test-PowerValue $GUID $Index 1 -Setting $Setting\r\n                }\r\n                \"Hibernate\" {\r\n                    if ($AC -or -not $BatteryCheck) {\r\n                        powercfg.exe \/SETACVALUEINDEX SCHEME_CURRENT $GUID $Index 2\r\n                    }\r\n                    elseif ($DC) {\r\n                        powercfg.exe \/SETDCVALUEINDEX SCHEME_CURRENT $GUID $Index 2\r\n                    }\r\n                    else {\r\n                        powercfg.exe \/SETACVALUEINDEX SCHEME_CURRENT $GUID $Index 2\r\n                        powercfg.exe \/SETDCVALUEINDEX SCHEME_CURRENT $GUID $Index 2\r\n                    }\r\n    \r\n                    Test-PowerValue $GUID $Index 2 -Setting $Setting\r\n                }\r\n                \"Shutdown\" {\r\n                    if ($AC -or -not $BatteryCheck) {\r\n                        powercfg.exe \/SETACVALUEINDEX SCHEME_CURRENT $GUID $Index 3\r\n                    }\r\n                    elseif ($DC) {\r\n                        powercfg.exe \/SETDCVALUEINDEX SCHEME_CURRENT $GUID $Index 3\r\n                    }\r\n                    else {\r\n                        powercfg.exe \/SETACVALUEINDEX SCHEME_CURRENT $GUID $Index 3\r\n                        powercfg.exe \/SETDCVALUEINDEX SCHEME_CURRENT $GUID $Index 3\r\n                    }\r\n    \r\n                    Test-PowerValue $GUID $Index 3 -Setting $Setting\r\n                }\r\n                default {\r\n                    throw \"$Action is not a valid action for $Setting, valid actions are Shutdown, Hibernate, Sleep and Nothing.\"\r\n                }\r\n            }\r\n        }\r\n        catch {\r\n            Write-Warning $_.Exception.Message\r\n            Write-Warning \"Failed to set power setting for $Setting\"\r\n        }\r\n    }\r\n\r\n    # The actual code required to set these values is very similar.\r\n    function Set-PowerValue {\r\n        [CmdletBinding()]\r\n        param(\r\n            [Parameter()]\r\n            [String]$Value,\r\n            [Parameter()]\r\n            [String]$GUID,\r\n            [Parameter()]\r\n            [String]$Index,\r\n            [Parameter()]\r\n            [String]$Setting\r\n        )\r\n\r\n        try {\r\n            if ($AC -or -not $BatteryCheck) {\r\n                powercfg.exe \/SETACVALUEINDEX SCHEME_CURRENT $GUID $Index $Value\r\n            }\r\n            elseif ($DC) {\r\n                powercfg.exe \/SETDCVALUEINDEX SCHEME_CURRENT $GUID $Index $Value\r\n            }\r\n            else {\r\n                powercfg.exe \/SETACVALUEINDEX SCHEME_CURRENT $GUID $Index $Value\r\n                powercfg.exe \/SETDCVALUEINDEX SCHEME_CURRENT $GUID $Index $Value\r\n            }\r\n\r\n            Test-PowerValue $GUID $Index $Value -Setting $Setting\r\n        }\r\n        catch {\r\n            Write-Warning $_.Exception.Message\r\n            Write-Warning \"Failed to set power setting for $Setting\"\r\n        }\r\n    }\r\n\r\n    # Before changing the power plan we should check if it exists and whether or not it is in use.\r\n    function Get-PowerPlan {\r\n        [CmdletBinding()]\r\n        param(\r\n            [Parameter()]\r\n            [Switch]$Active,\r\n            [Parameter()]\r\n            [String]$Name\r\n        )\r\n        if ($Active) {\r\n            $PowerPlan = powercfg.exe \/getactivescheme\r\n            $PowerPlan = ($PowerPlan -replace \"Power Scheme GUID:\" -split \"(?=S{8}-S{4}-S{4}-S{17})\" -split '(' -replace ')') | Where-Object { $_ -ne \" \" }\r\n            $PowerPlan = @(\r\n                [PSCustomObject]@{\r\n                    Name = $($PowerPlan | Where-Object { $_ -notmatch \"S{8}-S{4}-S{4}-S{17}\" })\r\n                    GUID = $($PowerPlan | Where-Object { $_ -match \"S{8}-S{4}-S{4}-S{17}\" })\r\n                }\r\n            )\r\n        }\r\n        else {\r\n            $PowerPlan = powercfg.exe \/L\r\n            $PowerPlan = $PowerPlan -replace 's{2,}', ',' -replace ' *', ',True' -replace \"Existing Power Schemes (* Active)\", \"GUID,Name,Active\" -replace \"-{2,}\" -replace \"Power Scheme GUID: \" -replace '(' -replace ')' | Where-Object { $_ } | ConvertFrom-Csv\r\n        }\r\n\r\n        if ($Name) {\r\n            $PowerPlan | Where-Object { $_.Name -like $Name }\r\n        }\r\n        else {\r\n            $PowerPlan\r\n        }\r\n    }\r\n}\r\nprocess {\r\n    # If not elevated, exit the script.\r\n    if (-not (Test-IsElevated)) {\r\n        Write-Error -Message \"Access Denied. Please run with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n\r\n    # If a power plan was specified, let the user know that this might not actually be a changeable option (depending on computer age).\r\n    if ($PowerPlan) {\r\n        Write-Warning \"Devices with modern standby might only have `\"Balanced`\" as an option.\"\r\n        Write-Warning \"Link: https:\/\/learn.microsoft.com\/en-us\/windows\/win32\/power\/power-policy-settings\"\r\n\r\n        $TargetPlan = Get-PowerPlan -Name $PowerPlan\r\n        # If totally not available we're going to exit as all these settings are tied to the active power plan. \r\n        # If we're not able to set it we'll want to give an opportunity to correct the error.\r\n        if ($null -eq $TargetPlan) {\r\n            Write-Error \"Your targeted Power Plan is not available.\"\r\n            exit 1\r\n        }\r\n\r\n        if ($TargetPlan.Active -ne $True) {\r\n            powercfg.exe \/setactive $TargetPlan.GUID\r\n        }\r\n\r\n        $CurrentPlan = Get-PowerPlan -Active\r\n        if ($CurrentPlan.GUID -notlike \"*$($TargetPlan.GUID)*\") {\r\n            Write-Error \"Failed to change power plan!\"\r\n            exit 1\r\n        }\r\n        else {\r\n            Write-Host \"Successfully set Power Plan!\"\r\n        }\r\n    }\r\n\r\n    # We're going to run through all the various options and if requested we'll adjust them.\r\n    if ($ScreenTimeout) { Set-PowerValue -GUID \"SUB_VIDEO\" -Index \"3c0bc021-c8a8-4e07-a973-6b14cbcb2b7e\" -Value $ScreenTimeoutValue -Setting \"Screen Timeout\" }\r\n    if ($HibernateTimeout) { \r\n        Write-Warning \"Hibernate timeout is not supported by all devices and may be ignored by the System.\" \r\n        Set-PowerValue -GUID \"SUB_SLEEP\" -Index \"9d7815a6-7ee4-497e-8888-515a05f02364\" -Value $HibernateTimeoutValue -Setting \"Hibernate Timeout\"\r\n    }\r\n    if ($SleepTimeout) { Set-PowerValue -GUID \"SUB_SLEEP\" -Index \"29f6c1db-86da-48c5-9fdb-f2b67b1f44da\" -Value $SleepTimeoutValue -Setting \"Sleep Timeout\" }\r\n    if ($DiskTimeout) { \r\n        Write-Warning \"An HDD is required for this setting to display (has no effect on SSDs).\"\r\n        Set-PowerValue -GUID \"SUB_DISK\" -Index \"6738e2c4-e8a5-4a42-b16a-e040e769756e\" -Value $DiskTimeoutValue -Setting \"Disk Timeout\"\r\n    }\r\n    if ($DisableUSBSuspend) { Set-PowerValue -GUID \"2a737441-1930-4402-8d77-b2bebba308a3\" -Index \"48e6b7a6-50f5-4782-a5d4-53bb8f07e226\" -Value 0 -Setting \"Disable USB Auto-Suspend\" }\r\n    if ($EnableUSBSuspend) { Set-PowerValue -GUID \"2a737441-1930-4402-8d77-b2bebba308a3\" -Index \"48e6b7a6-50f5-4782-a5d4-53bb8f07e226\" -Value 1 -Setting \"Enable USB Auto-Suspend\" }\r\n    if ($AllowWakeTimers) { Set-PowerValue -GUID \"SUB_SLEEP\" -Index \"bd3b718a-0680-4d9d-8ab2-e1d2b4ac806d\" -Value 1 -Setting \"Allow Wake Timers\" }\r\n    if ($DisableWakeTimers) { Set-PowerValue -GUID \"SUB_SLEEP\" -Index \"bd3b718a-0680-4d9d-8ab2-e1d2b4ac806d\" -Value 0 -Setting \"Disable Wake Timers\" }\r\n    # Lid Action has slightly different options than Set-PowerAction.\r\n    if ($LidAction -and $LaptopCheck) { \r\n        switch ($LidAction) {\r\n            \"Nothing\" { Set-PowerValue -GUID \"SUB_BUTTONS\" -Index \"5ca83367-6e45-459f-a27b-476b1d01c936\" -Value 0 -Setting \"Lid Action\" }\r\n            \"Sleep\" { Set-PowerValue -GUID \"SUB_BUTTONS\" -Index \"5ca83367-6e45-459f-a27b-476b1d01c936\" -Value 1 -Setting \"Lid Action\" }\r\n            \"Shutdown\" { Set-PowerValue -GUID \"SUB_BUTTONS\" -Index \"5ca83367-6e45-459f-a27b-476b1d01c936\" -Value 3 -Setting \"Lid Action\" }\r\n            default {\r\n                Write-Error \"Invalid PowerButton Option. Only Sleep, Nothing and Shutdown are allowed!\"\r\n                exit 1\r\n            }\r\n        } \r\n    }\r\n    if ($CriticalAction) { \r\n        Set-PowerAction -GUID \"SUB_BATTERY\" -Index \"637ea02f-bbcb-4015-8e2c-a1c7b9c0b546\" -Action $CriticalAction -Setting \"Critical Battery Action\"\r\n    }\r\n    if ($LowAction) { \r\n        Set-PowerAction -GUID \"SUB_BATTERY\" -Index \"d8742dcb-3e6a-4b3c-b3fe-374623cdcf06\" -Action $LowAction -Setting \"Low Battery Action\"\r\n    }\r\n    if ($CriticalLevel) { Set-PowerValue -GUID \"SUB_BATTERY\" -Index \"9a66d8d7-4ff7-4ef9-b5a2-5a326ca2a469\" -Value $CriticalLevelValue -Setting \"Critical Battery Level\" }\r\n    if ($LowLevel) { Set-PowerValue -GUID \"SUB_BATTERY\" -Index \"8183ba9a-e910-48da-8769-14ae6dc1170a\" -Value $LowLevelValue -Setting \"Low Battery Level\" }\r\n    if ($LowNoNotify) { Set-PowerValue -GUID \"SUB_BATTERY\" -Index \"bcded951-187b-4d05-bccc-f7e51960c258\" -Value 0 -Setting \"Disable Low Battery Notification\" }\r\n    if ($LowNotify) { Set-PowerValue -GUID \"SUB_BATTERY\" -Index \"bcded951-187b-4d05-bccc-f7e51960c258\" -Value 1 -Setting \"Enable Low Battery Notification\" }\r\n}\r\nend {\r\n    \r\n    \r\n    \r\n}<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p>Acesse mais de 300 scripts no NinjaOne Dojo<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/freetrialform\/\">Obter acesso<\/a><\/p>\n<\/div>\n<h2>Detalhamento<\/h2>\n<p>O script funciona como uma ferramenta multiuso para ajustar v\u00e1rias configura\u00e7\u00f5es de energia. Ele come\u00e7a com defini\u00e7\u00f5es de par\u00e2metros, permitindo que os usu\u00e1rios especifiquem valores para tempo limite de tela, hiberna\u00e7\u00e3o, tempo limite de suspens\u00e3o, tempo limite de disco e muito mais. As vari\u00e1veis ambientais podem ser definidas para cada par\u00e2metro, proporcionando flexibilidade e facilidade de uso. O script inclui uma s\u00e9rie de fun\u00e7\u00f5es para verificar os recursos do sistema, verificar se uma altera\u00e7\u00e3o de configura\u00e7\u00e3o foi bem-sucedida e aplicar as altera\u00e7\u00f5es.<\/p>\n<p>Por exemplo, se um administrador de TI quiser alterar a configura\u00e7\u00e3o de tempo limite da tela, ele poder\u00e1 passar o par\u00e2metro <strong>ScreenTimeout<\/strong> com o valor de tempo limite desejado em segundos. Em seguida, o script converte esse valor no formato apropriado e o aplica ao sistema usando o comando <strong>powercfg.exe<\/strong>.<\/p>\n<p>Essa abordagem \u00e9 replicada em v\u00e1rias configura\u00e7\u00f5es, como hiberna\u00e7\u00e3o, tempo limite de suspens\u00e3o e tempo limite de disco. O script tamb\u00e9m permite a configura\u00e7\u00e3o de planos de energia e op\u00e7\u00f5es de suspens\u00e3o USB, que s\u00e3o cruciais para o gerenciamento do consumo de energia e do desempenho do dispositivo.<\/p>\n<h2>Casos de uso em potencial<\/h2>\n<p>Imagine um MSP gerenciando uma frota de laptops para um cliente corporativo. Eles precisam garantir que todos os dispositivos mudem para um modo de economia de energia ap\u00f3s um per\u00edodo espec\u00edfico de inatividade, sem interven\u00e7\u00e3o manual. Ao implementar esse script, o MSP pode configurar remotamente o tempo limite de suspens\u00e3o, o tempo limite de hiberna\u00e7\u00e3o e at\u00e9 mesmo as configura\u00e7\u00f5es de a\u00e7\u00e3o da tampa em todos os dispositivos, garantindo uniformidade e ades\u00e3o \u00e0s pol\u00edticas de economia de energia da empresa.<\/p>\n<h2>Compara\u00e7\u00f5es<\/h2>\n<p>Os m\u00e9todos tradicionais de gerenciamento das configura\u00e7\u00f5es de energia geralmente envolvem ajustes manuais em cada dispositivo ou a implementa\u00e7\u00e3o de pol\u00edticas de grupo por meio do <a href=\"https:\/\/www.ninjaone.com\/it-hub\/gerenciamento-de-endpoints\/what-is-active-directory\/\">Active Directory<\/a>. Embora eficazes, esses m\u00e9todos n\u00e3o t\u00eam a granularidade e a facilidade de personaliza\u00e7\u00e3o oferecidas pelo script. Com essa abordagem do PowerShell, os profissionais de TI podem adaptar as configura\u00e7\u00f5es a necessidades espec\u00edficas e aplic\u00e1-las de forma mais din\u00e2mica em diferentes grupos de dispositivos.<\/p>\n<h2>Implica\u00e7\u00f5es<\/h2>\n<p>Embora esse script facilite muito o gerenciamento de energia, o uso inadequado pode levar a consequ\u00eancias indesejadas, como suspens\u00e3o ou hiberna\u00e7\u00e3o prematura do sistema, o que pode interromper processos importantes. \u00c9 essencial testar o script em um ambiente controlado antes da implanta\u00e7\u00e3o generalizada.<\/p>\n<h2>Recomenda\u00e7\u00f5es<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\">Sempre fa\u00e7a backup das configura\u00e7\u00f5es de energia atuais antes de aplicar novas configura\u00e7\u00f5es.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\">Teste o script em um pequeno conjunto de dispositivos antes da implementa\u00e7\u00e3o completa.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"6\" data-aria-level=\"1\">Atualize regularmente o script para acomodar novas atualiza\u00e7\u00f5es e recursos do Windows.<\/li>\n<\/ul>\n<h2>Considera\u00e7\u00f5es finais<\/h2>\n<p>Em uma era em que o gerenciamento remoto e a automa\u00e7\u00e3o s\u00e3o fundamentais, ferramentas como o NinjaOne se tornaram inestim\u00e1veis. O NinjaOne oferece recursos robustos <a href=\"https:\/\/www.ninjaone.com\/pt-br\/rmm\/\">de monitoramento e gerenciamento remotos<\/a>, complementando scripts como esse ao fornecer uma plataforma para implanta\u00e7\u00e3o, monitoramento e gerenciamento de ativos de TI. A integra\u00e7\u00e3o desses scripts em uma estrutura de gerenciamento de TI mais ampla, como o <a href=\"https:\/\/www.ninjaone.com\/pt-br\/eficiencia\/\">NinjaOne, pode aumentar a efici\u00eancia<\/a>, reduzir a carga de trabalho manual e contribuir para uma estrat\u00e9gia de gerenciamento de TI mais proativa.<\/p>\n","protected":false},"author":35,"featured_media":193887,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_lmt_disableupdate":"no","_lmt_disable":""},"operating_system":[4212],"use_cases":[12456],"class_list":["post-815657","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/script_hub\/815657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/comments?post=815657"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media\/193887"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media?parent=815657"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/operating_system?post=815657"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/use_cases?post=815657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}