{"id":815649,"date":"2026-05-28T12:16:43","date_gmt":"2026-05-28T12:16:43","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=815649"},"modified":"2026-05-28T12:16:43","modified_gmt":"2026-05-28T12:16:43","slug":"como-forcar-uma-atualizacao-do-gpup-remotamente-com-o-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/pt-br\/script-hub\/como-forcar-uma-atualizacao-do-gpup-remotamente-com-o-powershell\/","title":{"rendered":"Como for\u00e7ar uma atualiza\u00e7\u00e3o de GPU remotamente com o PowerShell: Um guia 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\">Os scripts do PowerShell s\u00e3o essenciais para o gerenciamento eficiente da TI, especialmente para atualiza\u00e7\u00f5es da Pol\u00edtica 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=\"2\" data-aria-level=\"1\">O script facilita a execu\u00e7\u00e3o remota de &#8216;gpupdate \/force&#8217; em v\u00e1rios sistemas.<\/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\">Ele garante a aplica\u00e7\u00e3o imediata e uniforme das altera\u00e7\u00f5es da Pol\u00edtica 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=\"4\" data-aria-level=\"1\">Significativamente mais eficiente do que as atualiza\u00e7\u00f5es manuais ou a espera por atualiza\u00e7\u00f5es programadas.<\/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\">Compat\u00edvel com todas as vers\u00f5es do Windows que oferecem suporte ao PowerShell e \u00e0 Pol\u00edtica 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\">Escal\u00e1vel para uso em redes pequenas e grandes.<\/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\">Requer uma implementa\u00e7\u00e3o cuidadosa para evitar <a href=\"https:\/\/www.ninjaone.com\/blog\/common-network-issues\/\">problemas de rede<\/a> generalizados.<\/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\">Recomenda-se a realiza\u00e7\u00e3o de testes, monitoramento de feedback e auditorias regulares para otimizar o uso.<\/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=\"9\" data-aria-level=\"1\">Complementa a plataforma da NinjaOne para o gerenciamento aprimorado da infraestrutura de TI.<\/li>\n<\/ul>\n<h2>Introdu\u00e7\u00e3o<\/h2>\n<p>No cen\u00e1rio em constante evolu\u00e7\u00e3o do gerenciamento de TI, a efici\u00eancia e a precis\u00e3o s\u00e3o fundamentais. Os scripts do PowerShell, especialmente para tarefas como a atualiza\u00e7\u00e3o da Pol\u00edtica de Grupo, surgiram como ferramentas vitais no arsenal dos profissionais de TI e dos <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">provedores de servi\u00e7os gerenciados (MSPs)<\/a>. Sua capacidade de simplificar processos complexos \u00e9 fundamental para manter a integridade e a seguran\u00e7a das infraestruturas de TI.<\/p>\n<h2>Hist\u00f3rico<\/h2>\n<p>A Pol\u00edtica de Grupo \u00e9 um recurso do Windows que oferece gerenciamento e configura\u00e7\u00e3o centralizados de sistemas operacionais, aplicativos e configura\u00e7\u00f5es de usu\u00e1rios. O script em que estamos nos concentrando utiliza o PowerShell para <a href=\"https:\/\/www.ninjaone.com\/blog\/gpupdate-how-to-force-a-group-policy-update\/\">executar remotamente o &#8220;gpupdate&#8221;<\/a>, um comando crucial para atualizar as Pol\u00edticas de Grupo. Isso \u00e9 particularmente importante para os profissionais de TI e MSPs que precisam garantir que as altera\u00e7\u00f5es de pol\u00edticas sejam aplicadas prontamente e de maneira uniforme em v\u00e1rios sistemas.<\/p>\n<h2>O roteiro:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 5.1\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Initiates a gpupdate. It will perform a gpupdate \/force, if the script is executed as the system or if either \"Logout All Users\" or \"Reboot\" options are selected.\r\n.DESCRIPTION\r\n    Initiates a gpupdate. It will perform a gpupdate \/force, if the script is executed as the system or if either \"Logout All Users\" or \"Reboot\" options are selected.\r\n.EXAMPLE\r\n    (No Parameters)\r\n  \r\n    Computer Policy updated successfully!\r\n    User Policy updated successfully!\r\n\r\n    ##### Group Policy Result ##### \r\n\r\n    Domain: test.lan \r\n    Site Name: Default-First-Site-Name \r\n    Slow Link?: false \r\n\r\n    Computer Account Used: TESTKYLE-WIN10-TEST$ \r\n    User Account Used: TESTtuser \r\n\r\n    Name                                   Type     Enabled IsValid FilterAllowed AccessDenied\r\n    ----                                   ----     ------- ------- ------------- ------------\r\n    {1ED0F3EF-6E54-4380-8BB3-6683A8D02E59} Computer N\/A     false   false         false       \r\n    {31B2F340-016D-11D2-945F-00C04FB984F9} User     N\/A     false   false         N\/A         \r\n    Default Domain Policy                  Computer true    true    true          false       \r\n    Local Group Policy                     Computer true    true    true          false       \r\n    Local Group Policy                     User     true    true    true          false       \r\n    Test GPO                               User     true    true    true          N\/A         \r\n\r\nPARAMETER: -Timeout \"30\"\r\n    The amount of time in seconds gpupdate should try to update. After that time gpupdate will timeout if no update is received.\r\n    \r\nPARAMETER: -CustomFieldName \"ReplaceMeWithAnyMultilineCustomField\"\r\n\r\n    The name of a multiline customfield to store the results in.\r\n\r\nPARAMETER: -User \"CONTOSOjdoe\"\r\n    The name of a user you'd like to generate a gpresult report with.\r\n\r\nPARAMETER: AllUsers\r\n    When the script is ran as system it will logout all logged in users upon successful gpupdate. If ran as a user it will logout only just that user if required.\r\n.EXAMPLE\r\n    Computer Policy updated successfully!\r\n    User Policy updated successfully!\r\n\r\n    ##### Group Policy Result ##### \r\n\r\n    Domain: test.lan \r\n    Site Name: Default-First-Site-Name \r\n    Slow Link?: false \r\n\r\n    Computer Account Used: TESTKYLE-WIN10-TEST$ \r\n    User Account Used: TESTtuser \r\n\r\n    Name                                   Type     Enabled IsValid FilterAllowed AccessDenied\r\n    ----                                   ----     ------- ------- ------------- ------------\r\n    {1ED0F3EF-6E54-4380-8BB3-6683A8D02E59} Computer N\/A     false   false         false       \r\n    {31B2F340-016D-11D2-945F-00C04FB984F9} User     N\/A     false   false         N\/A         \r\n    Default Domain Policy                  Computer true    true    true          false       \r\n    Local Group Policy                     Computer true    true    true          false       \r\n    Local Group Policy                     User     true    true    true          false       \r\n    Test GPO                               User     true    true    true          N\/A         \r\n\r\n\r\n\r\n    WARNING: -LogoutAllUsers was specified. Logging out all users!\r\n\r\nPARAMETER: -Reboot\r\n    Will schedule a reboot for 15 minutes after script completion (if gpupdate was successful).\r\n.EXAMPLE\r\n    Computer Policy updated successfully!\r\n    User Policy updated successfully!\r\n\r\n    ##### Group Policy Result ##### \r\n\r\n    Domain: test.lan \r\n    Site Name: Default-First-Site-Name \r\n    Slow Link?: false \r\n\r\n    Computer Account Used: TESTKYLE-WIN10-TEST$ \r\n    User Account Used: TESTtuser \r\n\r\n    Name                                   Type     Enabled IsValid FilterAllowed AccessDenied\r\n    ----                                   ----     ------- ------- ------------- ------------\r\n    {1ED0F3EF-6E54-4380-8BB3-6683A8D02E59} Computer N\/A     false   false         false       \r\n    {31B2F340-016D-11D2-945F-00C04FB984F9} User     N\/A     false   false         N\/A         \r\n    Default Domain Policy                  Computer true    true    true          false       \r\n    Local Group Policy                     Computer true    true    true          false       \r\n    Local Group Policy                     User     true    true    true          false       \r\n    Test GPO                               User     true    true    true          N\/A         \r\n\r\n\r\n\r\n    WARNING: -Reboot was specified. Scheduling a reboot for 06\/22\/2023 13:24:16!\r\n.OUTPUTS\r\n  None\r\n.NOTES\r\n  Minimum OS Architecture Supported: Windows 10, Windows Server 2016\r\n  Release Notes: Renamed script and added Script Variable support\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]$CustomFieldName = \"groupPolicy\",\r\n    [Parameter()]\r\n    [Int]$Timeout = 120,\r\n    [Parameter()]\r\n    [String]$User,\r\n    [Parameter()]\r\n    [Switch]$Reboot = [System.Convert]::ToBoolean($env:reboot),\r\n    [Parameter()]\r\n    [Switch]$LogoutAllUsers = [System.Convert]::ToBoolean($env:logoutAllUsers)\r\n)\r\n\r\nbegin {\r\n    # If script variables are used overwrite their parameter\r\n    if ($env:customFieldName -and $env:customFieldName -notlike \"null\") { $CustomFieldName = $env:customFieldName }\r\n    if ($env:groupPolicyTimeout -and $env:groupPolicyTimeout -notlike \"null\") { $Timeout = $env:groupPolicyTimeout }\r\n    if ($env:user -and $env:user -notlike \"null\") { $User = $env:user }\r\n\r\n    # Checks if script is running with elevated permissions\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    # Checks if script is running as system\r\n    function Test-IsSystem {\r\n        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()\r\n        return $id.Name -like \"NT AUTHORITY*\" -or $id.IsSystem\r\n    }\r\n\r\n    # Check if the computer is domain joined (group policy is still a thing on non-domain joined machine just not normally used)\r\n    function Test-IsDomainJoined {\r\n        return $(Get-CimInstance -Class Win32_ComputerSystem).PartOfDomain\r\n    }\r\n\r\n    # Check if its a domain controller running this\r\n    function Test-IsDomainController {\r\n        return $(Get-CimInstance -ClassName Win32_OperatingSystem).ProductType -eq 2\r\n    }\r\n\r\n    # Outputs the currently logged in users in a more powershell friendly format\r\n    function Get-QUser {\r\n        $quser = quser.exe\r\n        $quser -replace 's{2,}', ',' -replace '&gt;' | ConvertFrom-Csv\r\n    }\r\n\r\n    # Simply checks if gpupdate threw any errors\r\n    function Test-GroupPolicyResults {\r\n        param(\r\n            [string]$Type,\r\n            [string]$Result\r\n        )\r\n\r\n        if ($Result | Select-String \"errors\") {\r\n            Write-Error \"[Error] $Type Policy was not updated successfully!\"\r\n            $False\r\n        }\r\n        else {\r\n            Write-Host \"$Type Policy updated successfully!\"\r\n            $True\r\n        }\r\n    }\r\n\r\n}\r\nprocess {\r\n    # We don't want to exit the script for most errors as the gpresult report might still be helpful\r\n    $Success = $True\r\n\r\n    if (-not (Test-IsElevated)) {\r\n        Write-Warning \"This script is not running with Administrator priveledges. The end report will not contain Computer GPO data.\"\r\n        if ($User) {\r\n            Write-Warning \"Not elevated unable to create group policy result report for specified user. Will create a report for the current user instead.\"\r\n        }\r\n    }\r\n\r\n    # Warns the end user if the computer is not-domain joined. I don't consider this a failure though just something to keep in mind.\r\n    if (-not (Test-IsDomainJoined)) {\r\n        Write-Warning \"This computer is not joined to the domain!\"\r\n    }\r\n\r\n    # If a secure connection to the domain cannot be established group policy will fail to update. \r\n    if ((Test-IsDomainJoined) -and -not (Test-IsDomainController) -and -not (Test-ComputerSecureChannel -ErrorAction Ignore)) {\r\n        Write-Warning \"This device does not have a secure connection to the Domain Controller! Is the domain controller reachable?\"\r\n        $Success = $False\r\n    }\r\n\r\n    # Updates group policy. We only use \/force when Logoff is specified due to gpupdate stalling the script if a logoff is needed.\r\n    $gpupdate = if (-not (Test-IsSystem) -and $LogoutAllUsers) {\r\n        Invoke-Command { gpupdate.exe \/force \/Logoff \/wait:$Timeout }\r\n    }\r\n    elseif ((Test-IsSystem)) {\r\n        Invoke-Command { gpupdate.exe \/force \/wait:$Timeout }\r\n    }\r\n    else {\r\n        Invoke-Command { gpupdate.exe \/wait:$Timeout }\r\n    }\r\n\r\n    # Split up the results between Computer Policy and User Policy\r\n    $computerResult = $gpupdate | Select-String \"Computer Policy\"\r\n    $userResult = $gpupdate | Select-String \"User Policy\"\r\n\r\n    # Testing them to confirm gpupdate worked\r\n    $ComputerTest = Test-GroupPolicyResults -Type \"Computer\" -Result $computerResult\r\n    $UserTest = Test-GroupPolicyResults -Type \"User\" -Result $userResult\r\n\r\n    # If either of them are unsuccessful we'll want to exit with a status code of 1 but we'll want the result report first.\r\n    if (-not $UserTest -or -not $ComputerTest) {\r\n        $Success = $False\r\n    }\r\n\r\n    # If the script somehow got interupted before it had a chance to clean up its results we'll want to remove the previous results\r\n    if (Test-Path \"$env:TEMPgpresult.xml\" -ErrorAction Ignore) { Remove-Item \"$env:TEMPgpresult.xml\" -Force }\r\n\r\n    # We can't generate results with gpresult as the SYSTEM user so we'll attempt to generate results for the last logged in user.\r\n    if ((Test-IsSystem) -and -not $User) {\r\n        $LastLoggedInUser = Get-ItemPropertyValue -Path \"Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionAuthenticationLogonUI\" -Name \"LastLoggedOnUser\" -ErrorAction Ignore \r\n        if ($LastLoggedInUser) {\r\n            Invoke-Command { gpresult.exe \/USER $LastLoggedInUser \/X \"$env:TEMPgpresult.xml\" }\r\n        }\r\n        else {\r\n            Write-Error \"[Error] Couldn't determine the last logged on user. We cannot generate a report as System please either specify a user using -User or have one sign in. :)\"\r\n        }\r\n    }\r\n    elseif ($User -and (Test-IsElevated)) {\r\n        # Of course if we were given a user to generate results for we'll want to do that instead.\r\n        Invoke-Command { gpresult.exe \/USER $User \/X \"$env:TEMPgpresult.xml\" }\r\n    }\r\n    else {\r\n        # All other cases we'll want to generate the results as the same user the script is running as.\r\n        Invoke-Command { gpresult.exe \/X \"$env:TEMPgpresult.xml\" }\r\n    }\r\n\r\n    # If we failed to generate the results that's not a big deal but we'll want to alert whoever ran it that that's what happened.\r\n    if (-not (Test-Path \"$env:TEMPgpresult.xml\" -ErrorAction Ignore) ) {\r\n        Write-Error \"Failed to generate report with gpresult!\"\r\n        exit 0\r\n    }\r\n\r\n    # Cast the xml to an xml type\r\n    [xml]$resultXML = Get-Content \"$env:TEMPgpresult.xml\"\r\n\r\n    # Cleaning up after ourself\r\n    if (Test-Path \"$env:TEMPgpresult.xml\" -ErrorAction Ignore) { Remove-Item \"$env:TEMPgpresult.xml\" -Force }\r\n\r\n    # Lets construct an object for the active gpo's that we can format into a table later\r\n    $GPOs = $resultXML.DocumentElement | ForEach-Object {\r\n        ForEach ($GPO in $_.ComputerResults.GPO.Name) {\r\n            $ComputerGPO = [PSCustomObject]@{\r\n                Name          = $GPO\r\n                Type          = \"Computer\"\r\n                Enabled       = $resultXML.DocumentElement.ComputerResults.GPO | Where-Object { $_.Name -like $GPO } | Select-Object Enabled -ExpandProperty Enabled -ErrorAction Ignore\r\n                IsValid       = $resultXML.DocumentElement.ComputerResults.GPO | Where-Object { $_.Name -like $GPO } | Select-Object IsValid -ExpandProperty IsValid -ErrorAction Ignore\r\n                FilterAllowed = $resultXML.DocumentElement.ComputerResults.GPO | Where-Object { $_.Name -like $GPO } | Select-Object FilterAllowed -ExpandProperty FilterAllowed -ErrorAction Ignore\r\n            }\r\n\r\n            # If any values are blank we'll want to replace it with N\/A\r\n            if (-not $ComputerGPO.Enabled) { $ComputerGPO.Enabled = \"N\/A\" }\r\n            if (-not $ComputerGPO.IsValid) { $ComputerGPO.IsValid = \"N\/A\" }\r\n            if (-not $ComputerGPO.FilterAllowed) { $ComputerGPO.FilterAllowed = \"N\/A\" }\r\n\r\n            $ComputerGPO\r\n        }\r\n\r\n        ForEach ($GPO in $_.UserResults.GPO.Name) {\r\n            $UserGPO = [PSCustomObject]@{\r\n                Name          = $GPO\r\n                Type          = \"User\"\r\n                Enabled       = $resultXML.DocumentElement.UserResults.GPO | Where-Object { $_.Name -like $GPO } | Select-Object Enabled -ExpandProperty Enabled -ErrorAction Ignore\r\n                IsValid       = $resultXML.DocumentElement.UserResults.GPO | Where-Object { $_.Name -like $GPO } | Select-Object IsValid -ExpandProperty IsValid -ErrorAction Ignore\r\n                FilterAllowed = $resultXML.DocumentElement.UserResults.GPO | Where-Object { $_.Name -like $GPO } | Select-Object FilterAllowed -ExpandProperty FilterAllowed -ErrorAction Ignore\r\n            }\r\n\r\n            # If any values are blank we'll want to replace it with N\/A\r\n            if (-not $UserGPO.Enabled) { $UserGPO.Enabled = \"N\/A\" }\r\n            if (-not $UserGPO.IsValid) { $UserGPO.IsValid = \"N\/A\" }\r\n            if (-not $UserGPO.FilterAllowed) { $UserGPO.FilterAllowed = \"N\/A\" }\r\n\r\n            $UserGPO\r\n        }\r\n    }\r\n\r\n    # Construct report\r\n    $Report = New-Object System.Collections.Generic.List[string]\r\n    $Report.Add(\"`n##### Group Policy Result #####\")\r\n    $Report.Add(\"`n`nDomain: $($resultXML.DocumentElement.UserResults.Domain)\")\r\n    $Report.Add(\"`nSite Name: $($resultXML.DocumentElement.UserResults.Site)\")\r\n    $Report.Add(\"`nSlow Link?: $($resultXML.DocumentElement.UserResults.SlowLink)\")\r\n    $Report.Add(\"`n`nComputer Account Used: $($resultXML.DocumentElement.ComputerResults.Name)\")\r\n    $Report.Add(\"`nUser Account Used: $($resultXML.DocumentElement.UserResults.Name)\")\r\n    $Report.Add(\"`n$($GPOs | Sort-Object -Property Name | Format-Table | Out-String)\")\r\n\r\n    # Output Report\r\n    Write-Host $Report\r\n    if ($CustomFieldName) { Ninja-Property-Set -Name $CustomFieldName -Value $Report }\r\n\r\n\r\n    # If we had any kind of failures its best to not reboot the system or logoff any users\r\n    if (-not $Success) {\r\n        exit 1\r\n    }\r\n    elseif ($LogoutAllUsers -and (Test-IsSystem)) {\r\n        Write-Warning \"-LogoutAllUsers was specified. Logging out all users!\"\r\n        (Get-QUser).ID | ForEach-Object {\r\n            Invoke-Command { logoff.exe $_ }\r\n        }\r\n    }\r\n    elseif ($Reboot) {\r\n        $RebootTime = (Get-Date).AddMinutes(15)\r\n        Write-Warning \"-Reboot was specified. Scheduling a reboot for $RebootTime!\"\r\n        Invoke-Command { shutdown.exe \/r \/t 900 }\r\n    }\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>&nbsp;<\/p>\n<p style=\"text-align: center;\">Acesse mais de 300 scripts no NinjaOne Dojo<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.ninjaone.com\/freetrialform\/\">Obter acesso<\/a><\/p>\n<\/div>\n<h2>Detalhamento<\/h2>\n<p>O roteiro funciona com base em uma premissa simples, mas poderosa. Aqui est\u00e1 um guia passo a passo de sua funcionalidade:<\/p>\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>Iniciando a sess\u00e3o do PowerShell<\/strong>: O script come\u00e7a criando uma sess\u00e3o remota do PowerShell na m\u00e1quina de destino. Essa etapa \u00e9 fundamental para a execu\u00e7\u00e3o de comandos remotamente.<\/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>Executando &#8216;gpupdate&#8217;<\/strong>: Depois que a sess\u00e3o \u00e9 estabelecida, o script executa &#8216;gpupdate \/force&#8217;. Esse comando imp\u00f5e uma atualiza\u00e7\u00e3o imediata das configura\u00e7\u00f5es da Pol\u00edtica de Grupo, garantindo que todas as altera\u00e7\u00f5es recentes sejam aplicadas.<\/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>Verifica\u00e7\u00e3o e feedback<\/strong>: Ap\u00f3s a execu\u00e7\u00e3o do comando, o script verifica o sucesso e fornece feedback. Esse feedback \u00e9 essencial para que os administradores de TI saibam o status da atualiza\u00e7\u00e3o da pol\u00edtica.<\/li>\n<\/ul>\n<h2>Casos de uso em potencial<\/h2>\n<p>Imagine um administrador de TI gerenciando uma rede de 500 computadores. Uma atualiza\u00e7\u00e3o cr\u00edtica de seguran\u00e7a exige uma atualiza\u00e7\u00e3o imediata da Pol\u00edtica de Grupo. Usando esse script do PowerShell, o administrador pode acionar remotamente e simultaneamente um gpupdate em todas as m\u00e1quinas, garantindo a conformidade e a seguran\u00e7a rapidamente.<\/p>\n<h2>Compara\u00e7\u00f5es<\/h2>\n<p>Os m\u00e9todos tradicionais envolvem a atualiza\u00e7\u00e3o manual de cada m\u00e1quina ou a espera pela atualiza\u00e7\u00e3o programada da Pol\u00edtica de Grupo. A abordagem desse script reduz significativamente o tempo e o esfor\u00e7o, eliminando a necessidade de interven\u00e7\u00e3o manual e reduzindo a janela de vulnerabilidade.<\/p>\n<h2>Implica\u00e7\u00f5es<\/h2>\n<p>Embora o script aumente a efici\u00eancia, ele tamb\u00e9m enfatiza a necessidade de um gerenciamento respons\u00e1vel da Pol\u00edtica de Grupo. O uso incorreto pode levar a problemas generalizados em toda a rede. Portanto, \u00e9 fundamental entender o impacto das mudan\u00e7as nas pol\u00edticas antes da implementa\u00e7\u00e3o.<\/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=\"7\" data-aria-level=\"1\"><strong>Teste antes da implementa\u00e7\u00e3o<\/strong>: Sempre teste o script em um ambiente controlado antes da implementa\u00e7\u00e3o em grande escala.<\/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>Feedback do monitor<\/strong>: Preste aten\u00e7\u00e3o ao feedback fornecido pelo script ap\u00f3s a execu\u00e7\u00e3o para detectar antecipadamente qualquer problema em potencial.<\/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>Auditorias regulares<\/strong>: Realizar auditorias regulares de pol\u00edticas para garantir a relev\u00e2ncia e a efic\u00e1cia cont\u00ednuas.<\/li>\n<\/ul>\n<h2>Considera\u00e7\u00f5es finais<\/h2>\n<p>No contexto do gerenciamento da Pol\u00edtica de Grupo, o NinjaOne oferece ferramentas que complementam <a href=\"https:\/\/www.ninjaone.com\/blog\/category\/scripts\/\">os scripts do PowerShell<\/a>, fornecendo uma plataforma integrada para um <a href=\"https:\/\/www.ninjaone.com\/pt-br\/\">gerenciamento de TI<\/a> mais <a href=\"https:\/\/www.ninjaone.com\/pt-br\/\">abrangente<\/a>. Ao combinar scripts como o discutido com os robustos recursos de gerenciamento do NinjaOne, os profissionais de TI podem obter maior controle, <a href=\"https:\/\/www.ninjaone.com\/pt-br\/eficiencia\/\">efici\u00eancia<\/a> e seguran\u00e7a em seus ambientes de rede.<\/p>\n","protected":false},"author":35,"featured_media":192784,"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-815649","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\/815649","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=815649"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media\/192784"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media?parent=815649"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/operating_system?post=815649"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/use_cases?post=815649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}