Guarda una demo×
×

Guarda NinjaOne in azione!

Inviando questo modulo, accetto La politica sulla privacy di NinjaOne.

Padroneggiare PowerShell: Automatizzare la configurazione di Notizie e interessi in Windows

Punti chiave

  • Controllo automatico: Lo script automatizza la gestione della funzionalità Notizie e interessi in Windows 10 e “Widget” in Windows 11.
  • Gestione multiutente: Consente di apportare modifiche a tutti i profili utente di un sistema, coprendo vari tipi di account.
  • Sono richiesti privilegi amministrativi: L’esecuzione dello script per configurare Notizie e interessi richiede i diritti amministrativi per modificare le impostazioni del sistema.
  • Modifiche alla chiave di registro: La funzione centrale dello script per configurare Notizie e interessi è la capacità di alterare chiavi di registro specifiche in base alla versione del sistema operativo.
  • Opzione per un effetto immediato: Lo script per configurare Notizie e interessi può riavviare Windows Explorer per applicare le modifiche istantaneamente, evitando il riavvio del sistema.
  • Versatilità d’uso: Ideale per gli ambienti aziendali, per garantire l’uniformità e ridurre al minimo le distrazioni su tutti i computer della società.
  • Superiore ai metodi manuali: Offre un approccio più efficiente rispetto alle tradizionali modifiche manuali o alle regolazioni dei criteri di gruppo.
  • Reversibilità: Le modifiche apportate dallo script per configurare Notizie e interessi possono essere annullate, consentendo una certa flessibilità nella gestione delle impostazioni del sistema.
  • Si consigliano misure di sicurezza: Per un uso sicuro ed efficace degli script per configurare Notizie e interessi, si consiglia di adottare precauzioni quali test approfonditi, backup del registro e una documentazione chiara.
  • Gestione IT migliorata con strumenti dedicati: L’integrazione di questo script per configurare Notizie e interessi in piattaforme come NinjaOne può semplificare ulteriormente le attività di gestione IT.

Gli script PowerShell sono diventati uno strumento essenziale nell’arsenale dei professionisti IT, perché offrono un potente mezzo per automatizzare e gestire vari aspetti dei sistemi Windows. Una di queste attività è la configurazione della funzionalità “Notizie e interessi” in Windows 10 e della scheda “Widget” in Windows 11. Questa funzionalità, pur essendo utile per alcuni, può essere una distrazione o un elemento indesiderato per altri, soprattutto in un ambiente professionale. Capire come gestire in modo efficiente questa funzionalità è fondamentale per mantenere uno spazio di lavoro efficiente e dove sia possibile concentrarsi.

Background

Lo script per configurare Notizie e interessi è progettato per dare agli amministratori il controllo sulla visualizzazione della scheda “Notizie e interessi” (o scheda “Widget” in Windows 11) nella barra delle applicazioni. Questo aspetto è particolarmente importante per i professionisti IT e i Managed Service Provider (MSP) che gestiscono ambienti con più utenti. La possibilità di attivare, disattivare o impedire le modifiche a queste funzioni da remoto e di farlo in massa garantisce un ambiente uniforme per gli utenti, fondamentale sia per la sicurezza che per la facilità di gestione.

Lo script per configurare Notizie e Interessi in Windows:

#Requires -Version 5.1

<#
.SYNOPSIS
    Hides or shows the 'News and Interests' tab in the taskbar. On Windows 11, it hides or shows the widgets tab.
.DESCRIPTION
    Hides or shows the 'News and Interests' tab in the taskbar. On Windows 11, it hides or shows the widgets tab.
.EXAMPLE
    (No Parameters)
    
    WARNING: Hiding News and Interests from the taskbar for all users!
    Registry::HKEY_USERS\S-1-12-1-2117605486-1182246982-3318994623-3070967164\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarDa changed from 1 to 0
    Registry::HKEY_USERS\S-1-5-21-4122835015-3639794443-155648563-1001\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarDa changed from 1 to 0
    WARNING: This script will take effect the next time the user completes a full sign-in or restarts.

PARAMETER: -Enable
    Reveals the 'News and Interests' tab in the taskbar.
.EXAMPLE
    -Enable

    Revealing News and Interests for all users!
    Registry::HKEY_USERS\S-1-12-1-2117605486-1182246982-3318994623-3070967164\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarDa changed from 0 to 1
    Registry::HKEY_USERS\S-1-5-21-4122835015-3639794443-155648563-1001\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarDa changed from 0 to 1
    WARNING: This script will take effect the next time the user completes a full sign-in or restarts.

PARAMETER: -PreventChanges
    Should the end-user be able to modify this setting after it's been set with this script?
.EXAMPLE
    -PreventChanges
    
    WARNING: Hiding News and Interests from the taskbar for all users!
    Set Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Dsh\AllowNewsAndInterests to 0
    WARNING: This script will take effect the next time the user completes a full sign-in or restarts.

PARAMETER: -RestartExplorer
    In order for this script to take immediate effect, explorer.exe will need to be restarted.
.EXAMPLE
    -RestartExplorer

    WARNING: Hiding News and Interests from the taskbar for all users!
    Registry::HKEY_USERS\S-1-12-1-2117605486-1182246982-3318994623-3070967164\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarDa changed from 1 to 0
    Registry::HKEY_USERS\S-1-5-21-4122835015-3639794443-155648563-1001\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\TaskbarDa changed from 1 to 0
    WARNING: Restarting Explorer.exe

.OUTPUTS
    None
.NOTES
    Minimum Supported OS: Windows 10+
    Release Notes: Initial Release
By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/it/condizioni-utilizzo
    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. 
    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. 
    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. 
    Warranty Disclaimer: The script is provided “as is” and “as available”, 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. 
    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. 
    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. 
    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
#>

[CmdletBinding()]
param (
    [Parameter()]
    [Switch]$Enable,
    [Parameter()]
    [Switch]$PreventChanges = [System.Convert]::ToBoolean($env:preventChanges),
    [Parameter()]
    [Switch]$RestartExplorer = [System.Convert]::ToBoolean($env:restartExplorer)
)

begin {
    # Grabbing dynamic script variables
    if ($env:showOrHide -and $env:showOrHide -notlike "null") { if ($env:showOrHide -eq "Show") { $Enable = $True } }

    # Check if script is running with local admin privileges.
    function Test-IsElevated {
        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $p = New-Object System.Security.Principal.WindowsPrincipal($id)
        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
    }

    # Get a list of all the user profiles for when the script is run as System.
    function Get-UserHives {
        param (
            [Parameter()]
            [ValidateSet('AzureAD', 'DomainAndLocal', 'All')]
            [String]$Type = "All",
            [Parameter()]
            [String[]]$ExcludedUsers,
            [Parameter()]
            [switch]$IncludeDefault
        )
    
        # User account SID's follow a particular pattern depending on if they're Azure AD or a Domain account or a local "workgroup" account.
        $Patterns = switch ($Type) {
            "AzureAD" { "S-1-12-1-(\d+-?){4}$" }
            "DomainAndLocal" { "S-1-5-21-(\d+-?){4}$" }
            "All" { "S-1-12-1-(\d+-?){4}$" ; "S-1-5-21-(\d+-?){4}$" } 
        }
    
        # We'll need the NTuser.dat file to load each user's registry hive. So we grab it if their account sid matches the above pattern. 
        $UserProfiles = Foreach ($Pattern in $Patterns) { 
            Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\*" |
                Where-Object { $_.PSChildName -match $Pattern } | 
                Select-Object @{Name = "SID"; Expression = { $_.PSChildName } },
                @{Name = "UserName"; Expression = { "$($_.ProfileImagePath | Split-Path -Leaf)" } }, 
                @{Name = "UserHive"; Expression = { "$($_.ProfileImagePath)\NTuser.dat" } }, 
                @{Name = "Path"; Expression = { $_.ProfileImagePath } }
        }
    
        # There are some situations where grabbing the .Default user's info is needed.
        switch ($IncludeDefault) {
            $True {
                $DefaultProfile = "" | Select-Object UserName, SID, UserHive, Path
                $DefaultProfile.UserName = "Default"
                $DefaultProfile.SID = "DefaultProfile"
                $DefaultProfile.Userhive = "$env:SystemDrive\Users\Default\NTUSER.DAT"
                $DefaultProfile.Path = "C:\Users\Default"
    
                $DefaultProfile | Where-Object { $ExcludedUsers -notcontains $_.UserName }
            }
        }
    
        $UserProfiles | Where-Object { $ExcludedUsers -notcontains $_.UserName }
    }

    # Helper function for setting registry keys
    function Set-RegKey {
        param (
            $Path,
            $Name,
            $Value,
            [ValidateSet("DWord", "QWord", "String", "ExpandedString", "Binary", "MultiString", "Unknown")]
            $PropertyType = "DWord"
        )
        if (-not $(Test-Path -Path $Path)) {
            # Check if path does not exist and create the path
            New-Item -Path $Path -Force | Out-Null
        }
        if ((Get-ItemProperty -Path $Path -Name $Name -ErrorAction Ignore)) {
            # Update property and print out what it was changed from and changed to
            $CurrentValue = (Get-ItemProperty -Path $Path -Name $Name -ErrorAction Ignore).$Name
            try {
                Set-ItemProperty -Path $Path -Name $Name -Value $Value -Force -Confirm:$false -ErrorAction Stop | Out-Null
            }
            catch {
                Write-Error "[Error] Unable to Set registry key for $Name please see below error!"
                Write-Error $_
                exit 1
            }
            Write-Host "$Path\$Name changed from $CurrentValue to $($(Get-ItemProperty -Path $Path -Name $Name -ErrorAction Ignore).$Name)"
        }
        else {
            # Create property with value
            try {
                New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $PropertyType -Force -Confirm:$false -ErrorAction Stop | Out-Null
            }
            catch {
                Write-Error "[Error] Unable to Set registry key for $Name please see below error!"
                Write-Error $_
                exit 1
            }
            Write-Host "Set $Path\$Name to $($(Get-ItemProperty -Path $Path -Name $Name -ErrorAction Ignore).$Name)"
        }
    }

    # Restarts explorer.exe
    function Reset-Explorer {
        Write-Warning "Restarting Explorer.exe"
        
        Start-Sleep -Seconds 1
        Get-Process explorer | Stop-Process -Force
        Start-Sleep -Seconds 1

        if (-not (Get-Process explorer)) {
            Start-Process explorer.exe
        }
    }
    
    # Gets the OS Name E.g. Windows 10 Enterprise or Windows 11 Enterprise
    function Get-OSName {
        systeminfo | findstr /B /C:"OS Name"
    }

    $OSName = Get-OSName
}
process {
    if (-not (Test-IsElevated)) {
        Write-Error -Message "Access Denied." -RecommendedAction "Please run with Administrator privileges." -Exception (New-Object -TypeName System.UnauthorizedAccessException) -Category PermissionDenied
        exit 1
    }

    # The registry key is different depending on if its Windows 10 or Windows 11
    if ($OSName -Like "*11*") {
        $AllUserPath = (Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Dsh" -ErrorAction Ignore).AllowNewsAndInterests
    }
    else {
        $AllUserPath = (Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds" -ErrorAction Ignore).EnableFeeds
    }

    # Issues a warning prior to removing the registry key that prevents changes from end-users
    if ($AllUserPath -ge 0) {
        $EnableOrDisable = switch ($AllUserPath) {
            1 { "revealed" }
            default { "hidden" }
        }

        if (-not ($PreventChanges)) {
            Write-Warning "News and Interests is currently $EnableOrDisable for all users. Removing 'Prevent Changes' setting to replace it with individual user setting as requested."
            
            if ($OSName -Like "*11*") {
                Remove-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Dsh" -Name "AllowNewsAndInterests"
            }
            else {
                Remove-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds" -Name "EnableFeeds"
            }
        }
    }

    if ($OSName -Like "*11*") {
        $KeyPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Dsh"
        $KeyName = "AllowNewsAndInterests"
        $Value = if ($Enable) { 1 }else { 0 }
    }
    else {
        $KeyPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Feeds"
        $KeyName = "EnableFeeds"
        $Value = if ($Enable) { 1 }else { 0 }
    }

    # Sets a per user registry key if the end-user lock isn't set
    if (-not ($PreventChanges)) {
        $UserProfiles = Get-UserHives -Type "All"

        $KeyPath = New-Object System.Collections.Generic.List[string]
        $LoadedProfiles = New-Object System.Collections.Generic.List[Object]

        Foreach ($UserProfile in $UserProfiles) {
            # Load User ntuser.dat if it's not already loaded
            If ((Test-Path "Registry::HKEY_USERS\$($UserProfile.SID)" -ErrorAction Ignore) -eq $false) {
                $LoadedProfiles.Add($UserProfile)
                Start-Process -FilePath "cmd.exe" -ArgumentList "/C reg.exe LOAD HKU\$($UserProfile.SID) `"$($UserProfile.UserHive)`"" -Wait -WindowStyle Hidden
            }
            if ($OSName -Like "*11*") {
                $KeyPath.Add("Registry::HKEY_USERS\$($UserProfile.SID)\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced")
            }
            else {
                $KeyPath.Add("Registry::HKEY_USERS\$($UserProfile.SID)\Software\Microsoft\Windows\CurrentVersion\Feeds")
            }
        }

        if ($OSName -Like "*11*") {
            $KeyName = "TaskbarDa"
            $Value = if ($Enable) { 1 }else { 0 }
        }
        else {
            $KeyName = "ShellFeedsTaskbarViewMode"
            $Value = if ($Enable) { 0 }else { 2 }
        }
    }

    # Change the message depending on if we're hiding or showing the menu
    if ($Enable) {
        Write-Host "Revealing News and Interests for all users!"
    }
    else {
        Write-Warning "Hiding News and Interests from the taskbar for all users!"
    }
    
    # Setting the registry key
    $KeyPath | ForEach-Object { Set-RegKey -Path $_ -Name $KeyName -Value $Value }

    # Unload any profiles we loaded up earlier (if any)
    Foreach ($LoadedProfile in $LoadedProfiles) {
        [gc]::Collect()
        Start-Sleep 1
        Start-Process -FilePath "cmd.exe" -ArgumentList "/C reg.exe UNLOAD HKU\$($LoadedProfile.SID)" -Wait -WindowStyle Hidden | Out-Null
    }

    # Restart explorer.exe
    if ($RestartExplorer) {
        Reset-Explorer
    }
    else {
        Write-Warning "This script will take effect the next time the user completes a full sign-in or restarts."
    }
}
end {
    
    
    
}

 

Accedi a oltre 700 script nel Dojo di NinjaOne

Ottieni l’accesso

Analisi dettagliata dello script per configurare Notizie e interessi

  1. Inizializzazione e impostazione dei parametri: Lo script per configurare Notizie e interessi inizia impostando i parametri per abilitare la funzionalità, impedire le modifiche da parte degli utenti finali e decidere se riavviare Windows Explorer per le modifiche immediate. Inoltre, lo script per configurare Notizie e interessi regola dinamicamente alcune impostazioni in base alle variabili ambientali.
  2. Controllo dei privilegi dell’amministratore: Un passo fondamentale è la verifica dei privilegi amministrativi. Lo script controlla se è in esecuzione con i permessi necessari, assicurandosi che non vengano apportate modifiche non autorizzate.
  3. Gestione del profilo utente: Identifica tutti i profili utente del sistema, passaggio essenziale per applicare le impostazioni a più utenti. Questo include la gestione di diversi tipi di account, come di Azure AD, di dominio o account locali.
  4. Manipolazione della chiave di registro: Lo script per la configurazione di Notizie e interessi accede e modifica il registro di Windows. È qui che si attiva o disattiva la funzionalità “Notizie e interessi” o “Widget”. A seconda della versione del sistema operativo (Windows 10 o 11), lo script lavora su chiavi di registro diverse.
  5. Riavviare il processo di esplorazione: Opzionalmente, lo script per l’impostazione di Notizie e interessi può riavviare il processo di Windows Explorer per applicare immediatamente le modifiche, senza richiedere l’accesso dell’utente o il riavvio del sistema.

Casi d’uso potenziali

Immagina un ambiente aziendale in cui il reparto IT deve garantire uno spazio di lavoro standardizzato e privo di distrazioni su tutti i computer aziendali. Utilizzando questo script per configurare Notizie e interessi, è possibile disattivare la funzionalità “Notizie e interessi” su tutti i computer in modo efficiente, garantendo un’esperienza utente coerente e riducendo al minimo le distrazioni.

Confronti

Tradizionalmente, questi interventi richiedevano la modifica manuale del registro o dei criteri di gruppo. Questo script semplifica il processo, consentendo di apportare modifiche in modo rapido e in blocco, rispetto ai metodi manuali che richiedono molto tempo.

Domande frequenti

D1: Questo script per configurare Notizie e interessi funziona su qualsiasi versione di Windows?
A1: Lo script è progettato per Windows 10 e versioni successive.

D2: L’accesso come amministratore è obbligatorio per eseguire questo script per configurare Notizie e interessi?
A2: Sì, per apportare modifiche al registro sono necessari i privilegi di amministrazione.

D3: Questo script per configurare Notizie e interessi può annullare le modifiche, permettendo di tornare allo stato precedente se necessario?
A3: Sì, lo script può attivare o disattivare la funzionalità, consentendo quindi la reversibilità.

Implicazioni

Sebbene questo script sia decisamente utile, è importante considerarne le implicazioni. L’uso non autorizzato può portare a configurazioni indesiderate del sistema e gli errori involontari nell’esecuzione possono portare all’instabilità del sistema.

Raccomandazioni

  • Esegui dei test accurati: Esegui lo script per configurare Notizie e interessi in un ambiente controllato prima della distribuzione.
  • Effettua un backup dei registri: Esegui sempre un backup delle impostazioni del registro prima di apportare modifiche.
  • Documentazione chiara: Mantieni una documentazione chiara delle modifiche apportate utilizzando questo script per riferimenti futuri.

Considerazioni finali

Nel campo della gestione IT, strumenti come NinjaOne svolgono un ruolo fondamentale. Offrono una piattaforma unificata per il monitoraggio e l’automazione delle attività IT, compresa la distribuzione degli script. Questo script PowerShell, combinato con uno strumento di gestione solido come NinjaOne, può migliorare in modo significativo la capacità di un professionista IT di gestire e mantenere operativo il proprio ambiente digitale, aiutando a ottenere efficienza e controllo maggiori.

Passi successivi

La creazione di un team IT efficiente ed efficace richiede una soluzione centralizzata che funga da principale strumento per la fornitura di servizi. NinjaOne consente ai team IT di monitorare, gestire, proteggere e supportare tutti i dispositivi, ovunque essi si trovino, senza la necessità di una complessa infrastruttura locale.

Per saperne di più su NinjaOne Endpoint Management, fai un tour dal vivo, o inizia la tua prova gratuita della piattaforma NinjaOne.

Ti potrebbe interessare anche

Termini e condizioni NinjaOne

Cliccando sul pulsante “Accetto” qui sotto, dichiari di accettare i seguenti termini legali e le nostre condizioni d’uso:

  • Diritti di proprietà: NinjaOne possiede e continuerà a possedere tutti i diritti, i titoli e gli interessi relativi allo script (compreso il copyright). NinjaOne ti concede una licenza limitata per l’utilizzo dello script in conformità con i presenti termini legali.
  • Limitazione d’uso: Puoi utilizzare lo script solo per legittimi scopi personali o aziendali interni e non puoi condividere lo script con altri soggetti.
  • Divieto di ripubblicazione: In nessun caso ti è consentito ripubblicare lo script in una libreria di script appartenente o sotto il controllo di un altro fornitore di software.
  • Esclusione di garanzia: Lo script viene fornito “così com’è” e “come disponibile”, senza garanzie di alcun tipo. NinjaOne non promette né garantisce che lo script sia privo di difetti o che soddisfi le tue esigenze o aspettative specifiche.
  • Assunzione del rischio: L’uso che farai dello script è da intendersi a tuo rischio. Riconosci che l’utilizzo dello script comporta alcuni rischi intrinseci, che comprendi e sei pronto ad assumerti.
  • Rinuncia e liberatoria: Non riterrai NinjaOne responsabile di eventuali conseguenze negative o indesiderate derivanti dall’uso dello script e rinuncerai a qualsiasi diritto legale o di equità e a qualsiasi rivalsa nei confronti di NinjaOne in relazione all’uso dello script.
  • EULA: Se sei un cliente NinjaOne, l’uso dello script è soggetto al Contratto di licenza con l’utente finale (EULA) applicabile.