{"id":208175,"date":"2024-01-23T14:19:47","date_gmt":"2024-01-23T14:19:47","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/forzare-gpupdate-da-remoto-con-powershell\/"},"modified":"2024-03-04T18:24:54","modified_gmt":"2024-03-04T18:24:54","slug":"forzare-gpupdate-da-remoto-con-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/it\/script-hub\/forzare-gpupdate-da-remoto-con-powershell\/","title":{"rendered":"Come forzare GPUpdate da remoto con PowerShell: una guida per professionisti IT e MSP"},"content":{"rendered":"<h2>Punti chiave<\/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\">Gli script PowerShell sono fondamentali per una gestione IT efficiente, soprattutto per gli aggiornamenti dei Criteri di gruppo.<\/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\">Lo script facilita l&#8217;esecuzione remota del comando &#8220;gpupdate \/force&#8221; su pi\u00f9 sistemi.<\/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\">Garantisce l&#8217;applicazione immediata e uniforme delle modifiche ai Criteri di gruppo.<\/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\">Lo script per forzare GPUpdate da remoto \u00e8 molto pi\u00f9 efficiente degli aggiornamenti manuali o dell&#8217;attesa di aggiornamenti programmati.<\/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\">Compatibile con tutte le versioni di Windows che supportano PowerShell e Criteri di gruppo.<\/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\">Scalabile per l&#8217;utilizzo in reti di piccole e grandi dimensioni.<\/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\">Richiede un&#8217;attenta implementazione per evitare problemi di rete diffusi.<\/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\">Per un utilizzo ottimale, si raccomanda di eseguire test, monitorare i feedback e svolgere verifiche periodiche.<\/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\">Integra la piattaforma NinjaOne per una migliore gestione dell&#8217;infrastruttura IT.<\/li>\n<\/ul>\n<h2>Introduzione<\/h2>\n<p>Nel panorama in continua evoluzione della gestione IT, efficienza e precisione sono fondamentali. Gli script PowerShell, in particolare per attivit\u00e0 come l&#8217;aggiornamento dei Criteri di gruppo, sono emersi come strumenti vitali nell&#8217;arsenale dei professionisti IT e dei <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">Managed Service Provider (MSP)<\/a>. La loro capacit\u00e0 di semplificare processi complessi \u00e8 fondamentale per mantenere lo stato di salute e la sicurezza delle infrastrutture IT.<\/p>\n<h2>Background<\/h2>\n<p>I criteri di gruppo sono una funzione di Windows che consente la gestione e la configurazione centralizzata di sistemi operativi, applicazioni e impostazioni relative agli utenti. Lo script su cui ci concentriamo utilizza PowerShell per <a href=\"https:\/\/www.ninjaone.com\/blog\/gpupdate-how-to-force-a-group-policy-update\/\">eseguire in remoto \u201cgpupdate\u201d<\/a>, un comando fondamentale per aggiornare i Criteri di gruppo. Ci\u00f2 \u00e8 particolarmente importante per i professionisti IT e gli MSP che devono garantire che le modifiche ai criteri vengano applicate tempestivamente e in modo uniforme su numerosi sistemi.<\/p>\n<h2>Lo script per forzare GPUpdate da remoto:<\/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;\">Accedi a oltre 700 script nel Dojo di NinjaOne<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.ninjaone.com\/it\/prova-gratuita\/\">Ottieni l&#8217;accesso<\/a><\/p>\n<\/div>\n<h2>Analisi dettagliata<\/h2>\n<p>Lo script per lanciare GPUpdate da remoto si basa su una premessa semplice ma potente. Ecco una guida passo per passo delle sue funzionalit\u00e0:<\/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>Avvio della sessione PowerShell<\/strong>: Lo script per forzare GPUpdate da remoto inizia creando una sessione PowerShell remota sul computer di destinazione. Questo passaggio \u00e8 fondamentale per l&#8217;esecuzione di comandi in remoto.<\/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>Esecuzione di \u201cgpupdate\u201d<\/strong>: Una volta stabilita la sessione, lo script esegue &#8220;gpupdate \/force&#8221;. Questo comando forza l&#8217;esecuzione di un aggiornamento immediato delle impostazioni dei Criteri di gruppo, garantendo l&#8217;applicazione di tutte le modifiche recenti.<\/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 e feedback<\/strong>: Dopo l&#8217;esecuzione del comando, lo script per forzare GPUpdate da remoto ne verifica il successo e fornisce un feedback. Questo feedback \u00e8 essenziale per gli amministratori IT per conoscere lo stato dell&#8217;aggiornamento dei criteri.<\/li>\n<\/ul>\n<h2>Casi d&#8217;uso potenziali<\/h2>\n<p>Immagina un amministratore IT che gestisce una rete di 500 computer. Un aggiornamento di sicurezza critico richiede un aggiornamento immediato dei Criteri di gruppo. Utilizzando questo script PowerShell per forzare GPUpdate da remoto, l&#8217;amministratore pu\u00f2 attivare da remoto, e simultaneamente, un gpupdate su tutti i computer, garantendo rapidamente la conformit\u00e0 e la sicurezza.<\/p>\n<h2>Confronti<\/h2>\n<p>I metodi tradizionali prevedono l&#8217;aggiornamento manuale di ogni computer o l&#8217;attesa dell&#8217;aggiornamento programmato dei Criteri di gruppo. L&#8217;approccio di questo script riduce il tempo e l&#8217;impegno richiesti in modo significativo, eliminando la necessit\u00e0 di interventi manuali e riducendo la finestra di vulnerabilit\u00e0.<\/p>\n<h2>Domande frequenti<\/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\"><strong>Questo script per forzare GPUpdate da remoto \u00e8 compatibile con tutte le versioni di Windows?<\/strong><br \/>\nS\u00ec, funziona con tutte le versioni di Windows che supportano PowerShell e i Criteri di gruppo.<\/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>Che differenza c&#8217;\u00e8 tra questo script per forzare GPUpdate da remoto e gli aggiornamenti programmati dei Criteri di gruppo?<\/strong><br \/>\nQuesto script per forzare GPUpdate da remoto forza un aggiornamento immediato, a differenza degli aggiornamenti programmati che seguono una programmazione prestabilita.<\/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>Pu\u00f2 essere utilizzato su una rete di grandi dimensioni?<\/strong><br \/>\nAssolutamente s\u00ec, \u00e8 scalabile ed efficace per reti di qualsiasi dimensione.<\/li>\n<\/ul>\n<h2>Implicazioni<\/h2>\n<p>Se da un lato lo script per forzare GPUpdate da remoto migliora l&#8217;efficienza, dall&#8217;altro \u00e8 importante sottolineare la necessit\u00e0 di una gestione responsabile dei Criteri di gruppo. Un utilizzo non corretto pu\u00f2 causare problemi diffusi in tutta la rete. Per questo motivo, \u00e8 fondamentale comprendere l&#8217;impatto delle modifiche a un criterio prima dell&#8217;implementazione.<\/p>\n<h2>Raccomandazioni<\/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>Testa prima della distribuzione<\/strong>: Testa sempre lo script per forzare GPUpdate da remoto in un ambiente controllato prima della distribuzione su larga scala.<\/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>Controlla il feedback<\/strong>: Presta attenzione al feedback fornito dallo script per forzare GPUpdate da remoto dopo l&#8217;esecuzione per individuare tempestivamente eventuali problemi.<\/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>Effettua audit regolari<\/strong>: Verifica periodicamente i criteri per garantirne la rilevanza e l&#8217;efficacia.<\/li>\n<\/ul>\n<h2>Considerazioni finali<\/h2>\n<p>Nel contesto della gestione dei Criteri di gruppo, NinjaOne offre strumenti che integrano gli <a href=\"https:\/\/www.ninjaone.com\/it\/blog\/category\/scripts-it\">script PowerShell<\/a>, fornendo una piattaforma integrata per una <a href=\"https:\/\/www.ninjaone.com\/it\/\">gestione IT pi\u00f9 completa<\/a>. Abbinando script come quello descritto per forzare GPUpdate da remoto alle solide funzionalit\u00e0 di gestione di NinjaOne, i professionisti IT possono ottenere maggiori controllo, efficienza e sicurezza nei loro ambienti di rete.<\/p>\n","protected":false},"author":35,"featured_media":207304,"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":[4275],"class_list":["post-208175","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows","use_cases-configurazione-del-sistema"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/script_hub\/208175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/comments?post=208175"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/media\/207304"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/media?parent=208175"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/operating_system?post=208175"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/use_cases?post=208175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}