{"id":816973,"date":"2026-06-02T16:08:21","date_gmt":"2026-06-02T16:08:21","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=816973"},"modified":"2026-06-02T16:08:21","modified_gmt":"2026-06-02T16:08:21","slug":"gerenciamento-de-papel-de-parede-no-windows-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/pt-br\/script-hub\/gerenciamento-de-papel-de-parede-no-windows-powershell\/","title":{"rendered":"Como simplificar o gerenciamento de pap\u00e9is de parede no Windows com o PowerShell"},"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>Automatizar altera\u00e7\u00f5es no papel de parede<\/strong>: O script automatiza o processo de configura\u00e7\u00e3o de pap\u00e9is de parede da \u00e1rea de trabalho em v\u00e1rios perfis de usu\u00e1rio em ambientes Windows.<\/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>Economiza tempo e garante a consist\u00eancia<\/strong>: Ideal para profissionais de TI e MSPs que gerenciam v\u00e1rios computadores, garantindo uniformidade e conformidade com a marca.<\/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>Par\u00e2metros flex\u00edveis<\/strong>: Oferece suporte \u00e0 personaliza\u00e7\u00e3o com par\u00e2metros para URL da imagem, diret\u00f3rio de armazenamento e estilo do papel de parede.<\/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>Efeito imediato Caracter\u00edsticas<\/strong>: Inclui op\u00e7\u00f5es para substituir arquivos de papel de parede transcodificados e reiniciar o Explorer para altera\u00e7\u00e3o imediata.<\/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>Versatilidade em todas as vers\u00f5es do Windows<\/strong>: Projetado para o Windows 7 e vers\u00f5es mais recentes, embora alguns recursos possam variar em vers\u00f5es mais antigas.<\/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>Compat\u00edvel com formatos de imagem comuns<\/strong>: Compat\u00edvel com formatos de imagem populares, como JPG, PNG, BMP e GIF.<\/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>Considera\u00e7\u00f5es sobre seguran\u00e7a<\/strong>: Envolve a modifica\u00e7\u00e3o de configura\u00e7\u00f5es de registro e arquivos de sistema; o gerenciamento adequado das permiss\u00f5es de script \u00e9 fundamental.<\/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>Recomenda-se um teste abrangente<\/strong>: Fa\u00e7a testes completos em ambientes controlados antes da implementa\u00e7\u00e3o em toda a rede.<\/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\"><strong>Integra-se com as ferramentas de gerenciamento de TI<\/strong>: Pode ser perfeitamente incorporado \u00e0s plataformas de gerenciamento de TI, como o NinjaOne, para implementa\u00e7\u00e3o e monitoramento eficientes.<\/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=\"10\" data-aria-level=\"1\"><strong>Documentar e auditar o uso do script<\/strong>: Manter registros para uso do script para facilitar a auditoria e a solu\u00e7\u00e3o de problemas.<\/li>\n<\/ul>\n<p>Alterar o papel de parede da \u00e1rea de trabalho em v\u00e1rios perfis de usu\u00e1rio em um ambiente Windows \u00e9 uma tarefa que os profissionais de TI encontram com frequ\u00eancia. Seja para fins de marca, conformidade ou simplesmente para atualizar o espa\u00e7o de trabalho, a automa\u00e7\u00e3o desse processo economiza tempo e garante a consist\u00eancia. Os scripts do PowerShell se tornaram ferramentas indispens\u00e1veis no kit de ferramentas de TI, oferecendo solu\u00e7\u00f5es eficientes e flex\u00edveis para essas tarefas.<\/p>\n<h2>Hist\u00f3rico<\/h2>\n<p>O script em foco foi desenvolvido para automatizar o processo de configura\u00e7\u00e3o de pap\u00e9is de parede da \u00e1rea de trabalho para todos os perfis de usu\u00e1rio em um sistema Windows. Esse recurso \u00e9 particularmente valioso para profissionais de TI e <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">provedores de servi\u00e7os gerenciados (MSPs)<\/a> que gerenciam um grande n\u00famero de computadores. Ele permite a uniformidade em ambientes corporativos, garantindo que todos os usu\u00e1rios tenham o mesmo plano de fundo, o que pode ser vital para a cria\u00e7\u00e3o de marcas ou para a transmiss\u00e3o de informa\u00e7\u00f5es importantes.<\/p>\n<h2>O roteiro:<\/h2>\n<p><div class=\"button-wrap orange-button \"><a href=\"#disable-fast-startup\" data-js=\"button-script-cta\" class=\"button script-cta\" data-js=\"script-cta\"  data-modal=\"249410\" >Email me the script<\/a><\/div><br \/>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">&lt;#\r\n.SYNOPSIS\r\n    This sets the desktop wallpaper for all existing users (if run as System) or the currently logged-in user. To have the wallpaper change take effect immediately please select \"Replace Transcoded Wallpaper File\" and \"Restart Explorer\". These options may not work on Windows 7 and Server 2008.\r\n.DESCRIPTION\r\n    This sets the desktop wallpaper for all existing users (if run as System) or the currently logged-in user. \r\n    To have the wallpaper change take effect immediately please select \"Replace Transcoded Wallpaper File\" and \"Restart Explorer\". \r\n    These options may not work on Windows 7 and Server 2008.\r\n.EXAMPLE\r\n    (No Parameters) - Windows 10\r\n\r\n    C:ProgramDataNinjaRMMAgentscriptingcustomscript_gen_55.ps1 : No image given!\r\n    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException\r\n    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,customscript_gen_55.ps1\r\n\r\nPARAMETER: -Url \"https:\/\/www.example.com\/image.png\"\r\n    A link to the wallpaper you would like to set.\r\n\r\nPARAMETER: -Directory \"C:ExampleExample\"\r\n    A location to store the wallpaper.\r\n\r\n.EXAMPLE\r\n    -Url \"https:\/\/www.microsoft.com\/en-us\/microsoft-365\/blog\/wp-content\/uploads\/sites\/2\/2021\/06\/Msft_Nostalgia_Landscape.jpg\" -Directory \"C:ProgramDataWallpaper\" (Windows 10 as System)\r\n    \r\n    WARNING: Restarting Explorer.exe is required for wallpaper change to take effect!\r\n    URL Given, Downloading the file...\r\n    Download Attempt 1\r\n\r\n    Registry::HKEY_USERSS-1-5-21-3600085911-33463358-3311494591-1103Control PanelDesktopWallpaper changed from C:ProgramDataWallpaperwallpaper-686581913.jpg to C:ProgramDataWallpaperwallpaper-1935193304.jpg\r\n    Registry::HKEY_USERSS-1-5-21-3600085911-33463358-3311494591-1103Control PanelDesktopWallpaperStyle changed from 10 to 10\r\n    Registry::HKEY_USERSS-1-5-21-3600085911-33463358-3311494591-1103Control PanelDesktopTileWallpaper changed from 0 to 0\r\n    WARNING: Replacing the wallpaper transcoded file is required for wallpaper change to take immediate effect.\r\n\r\n    Registry::HKEY_USERSS-1-5-21-3870645062-3653562310-3850680542-1002Control PanelDesktopWallpaper changed from C:ProgramDataWallpaperwallpaper-686581913.jpg to C:ProgramDataWallpaperwallpaper-1935193304.jpg\r\n    Registry::HKEY_USERSS-1-5-21-3870645062-3653562310-3850680542-1002Control PanelDesktopWallpaperStyle changed from 10 to 10\r\n    Registry::HKEY_USERSS-1-5-21-3870645062-3653562310-3850680542-1002Control PanelDesktopTileWallpaper changed from 0 to 0\r\n    WARNING: Replacing the wallpaper transcoded file is required for wallpaper change to take immediate effect.\r\n\r\n    Registry::HKEY_USERSS-1-5-21-3870645062-3653562310-3850680542-1003Control PanelDesktopWallpaper changed from C:ProgramDataWallpaperwallpaper-686581913.jpg to C:ProgramDataWallpaperwallpaper-1935193304.jpg\r\n    Registry::HKEY_USERSS-1-5-21-3870645062-3653562310-3850680542-1003Control PanelDesktopWallpaperStyle changed from 10 to 10\r\n    Registry::HKEY_USERSS-1-5-21-3870645062-3653562310-3850680542-1003Control PanelDesktopTileWallpaper changed from 0 to 0\r\n    WARNING: Replacing the wallpaper transcoded file is required for wallpaper change to take immediate effect.\r\n\r\n    Registry::HKEY_USERSS-1-5-21-3870645062-3653562310-3850680542-1004Control PanelDesktopWallpaper changed from C:ProgramDataWallpaperwallpaper-686581913.jpg to C:ProgramDataWallpaperwallpaper-1935193304.jpg\r\n    Registry::HKEY_USERSS-1-5-21-3870645062-3653562310-3850680542-1004Control PanelDesktopWallpaperStyle changed from 10 to 10\r\n    Registry::HKEY_USERSS-1-5-21-3870645062-3653562310-3850680542-1004Control PanelDesktopTileWallpaper changed from 0 to 0\r\n    WARNING: Replacing the wallpaper transcoded file is required for wallpaper change to take immediate effect.\r\n\r\nPARAMETER: -WallpaperStyle \"Fill\"\r\n    This will set the wallpaper style to the appropriate option. Valid Options: \"Fill\", \"Fit\", \"Stretch\", \"Tile\", \"Center\", \"Span\"\r\n\r\nPARAMETER: -ReplaceTranscodedWallpaperFile\r\n    This will replace the file %APPDATA%MicrosoftWindowsThemesTranscodedWallpaper. This file is generated whenever the wallpaper is changed and is required for the wallpaper change to take immediate effect.\r\n\r\nPARAMETER: -RestartExplorer\r\n    This will restart explorer.exe. This is required for the wallpaper change to take immediate effect.\r\n\r\n.OUTPUTS\r\n    None\r\n.NOTES\r\n    Minimum Supported OS: Windows 7+, Server 2008+\r\n    Release Notes: 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]$Url,\r\n    [Parameter()]\r\n    [String]$Directory,\r\n    [Parameter()]\r\n    [String]$WallpaperStyle = \"Fill\",\r\n    [Parameter()]\r\n    [Switch]$ReplaceTranscodedWallpaperFile = [System.Convert]::ToBoolean($env:replaceTranscodedWallpaperFile),\r\n    [Parameter()]\r\n    [Switch]$RestartExplorer = [System.Convert]::ToBoolean($env:restartExplorer)\r\n)\r\n\r\nbegin {\r\n\r\n    # Set Dynamic Script Variables (if used)\r\n    if ($env:localWallpaperFile -and $env:localWallpaperFile -notlike \"null\") { $ExistingImage = $env:localWallpaperFile }\r\n    if ($env:directoryToStoreWallpaperIn -and $env:directoryToStoreWallpaperIn -notlike \"null\") { $Directory = $env:directoryToStoreWallpaperIn }\r\n    if ($env:linkToWallpaperFile -and $env:linkToWallpaperFile -notlike \"null\") { $Url = $env:linkToWallpaperFile }\r\n    if ($env:wallpaperDisplayMode -and $env:wallpaperDisplayMode -notlike \"null\") { $WallpaperStyle = $env:wallpaperDisplayMode }\r\n\r\n    # Validate that we received a correct value for the wallpaper style\r\n    $AllowedFit = \"Fill\", \"Fit\", \"Stretch\", \"Tile\", \"Center\", \"Span\"\r\n    if ($AllowedFit -notcontains $WallpaperStyle) {\r\n        Write-Error \"[Error] Invalid Wallpaper Display Mode selected. Please use one of the following options. Fill, Fit, Stretch, Tile, Center or Span.\"\r\n        exit 1\r\n    }\r\n\r\n    # If the local file we were told to use doesn't exist we should ignore it.\r\n    if ($ExistingImage -and -not (Test-Path $ExistingImage -ErrorAction SilentlyContinue)) {\r\n        Write-Warning \"Existing wallpaper does not exist. Ignoring...\"\r\n        $ExistingImage = $Null\r\n    }\r\n\r\n    # If we weren't given a link or a local file to use we should error out.\r\n    if (-not ($Url) -and -not ($ExistingImage)) {\r\n        Write-Error \"No image given!\"\r\n        Exit 1\r\n    }\r\n\r\n    # If we don't have a place to store the file and it doesn't already exist we should error out.\r\n    if (-not ($Directory) -and -not ($ExistingImage)) {\r\n        Write-Error \"You must specify a location to store the wallpaper.\"\r\n        Exit 1\r\n    }\r\n\r\n    # Create the directory if it does not exist.\r\n    if ($Directory -and -not (Test-Path -Path $Directory -ErrorAction SilentlyContinue)) {\r\n        try {\r\n            New-Item -Path $Directory -ItemType Directory -ErrorAction Stop | Out-Null\r\n        }\r\n        catch {\r\n            Write-Error \"Failed to create directory!\"\r\n            Exit 1\r\n        }\r\n    }\r\n\r\n    # Warn the end-user that the wallpaper change will not take immediate effect.\r\n    if (-not ($RestartExplorer)) {\r\n        Write-Warning \"Restarting Explorer.exe is required for wallpaper change to take effect!\"\r\n    }\r\n\r\n    # Handy download function.\r\n    function Invoke-Download {\r\n        param(\r\n            [Parameter()]\r\n            [String]$URL,\r\n            [Parameter()]\r\n            [String]$BaseName,\r\n            [Parameter()]\r\n            [Switch]$SkipSleep\r\n        )\r\n        Write-Host \"URL Given, Downloading the file...\"\r\n\r\n        $SupportedTLSversions = [enum]::GetValues('Net.SecurityProtocolType')\r\n        if ( ($SupportedTLSversions -contains 'Tls13') -and ($SupportedTLSversions -contains 'Tls12') ) {\r\n            [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol::Tls13 -bor [System.Net.SecurityProtocolType]::Tls12\r\n        }\r\n        elseif ( $SupportedTLSversions -contains 'Tls12' ) {\r\n            [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12\r\n        }\r\n        else {\r\n            # Not everything requires TLS 1.2, but we'll try anyways.\r\n            Write-Warning \"TLS 1.2 and or TLS 1.3 isn't supported on this system. This download may fail!\"\r\n            if ($PSVersionTable.PSVersion.Major -lt 3) {\r\n                Write-Warning \"PowerShell 2 \/ .NET 2.0 doesn't support TLS 1.2.\"\r\n            }\r\n        }\r\n\r\n        $i = 1\r\n        While ($i -lt 4) {\r\n            if (-not ($SkipSleep)) {\r\n                $SleepTime = Get-Random -Minimum 3 -Maximum 30\r\n                Start-Sleep -Seconds $SleepTime\r\n            }\r\n\r\n            Write-Host \"Download Attempt $i\"\r\n\r\n            try {\r\n                $WebClient = New-Object System.Net.WebClient\r\n                $Response = $WebClient.OpenRead($Url)\r\n                $MimeType = $WebClient.ResponseHeaders[\"Content-Type\"]\r\n                $DesiredExtension = switch -regex ($MimeType) {\r\n                    \"image\/jpeg|image\/jpg\" { \"jpg\" }\r\n                    \"image\/png\" { \"png\" }\r\n                    \"image\/gif\" { \"gif\" }\r\n                    \"image\/bmp|image\/x-windows-bmp|image\/x-bmp\" { \"bmp\" }\r\n                    default { \r\n                        Write-Error \"The URL you provided does not provide a supported image type. Image Types Supported: jpg, jpeg, bmp, png and gif. Image Type detected: $MimeType\"\r\n                        Exit 1 \r\n                    }\r\n                }\r\n                $Path = \"$BaseName.$DesiredExtension\"\r\n                $WebClient.DownloadFile($URL, $Path)\r\n                $File = Test-Path -Path $Path -ErrorAction SilentlyContinue\r\n                $Response.Close()\r\n            }\r\n            catch {\r\n                if ($Response) { $Response.Close() }\r\n                Write-Warning \"An error has occured while downloading!\"\r\n                Write-Warning $_.Exception.Message\r\n            }\r\n\r\n            if ($File) {\r\n                $i = 4\r\n            }\r\n            else {\r\n                $i++\r\n            }\r\n        }\r\n\r\n        if (-not (Test-Path $Path)) {\r\n            Write-Error \"Failed to download file!\"\r\n            Exit 1\r\n        }\r\n\r\n        $Path\r\n    }\r\n\r\n    # Get a list of all the user profiles for when the script is ran as System.\r\n    function Get-UserHives {\r\n        param (\r\n            [Parameter()]\r\n            [ValidateSet('AzureAD', 'DomainAndLocal', 'All')]\r\n            [String]$Type = \"All\",\r\n            [Parameter()]\r\n            [String[]]$ExcludedUsers,\r\n            [Parameter()]\r\n            [switch]$IncludeDefault\r\n        )\r\n    \r\n        # User account SID's follow a particular patter depending on if they're Azure AD or a Domain account or a local \"workgroup\" account.\r\n        $Patterns = switch ($Type) {\r\n            \"AzureAD\" { \"S-1-12-1-(d+-?){4}$\" }\r\n            \"DomainAndLocal\" { \"S-1-5-21-(d+-?){4}$\" }\r\n            \"All\" { \"S-1-12-1-(d+-?){4}$\" ; \"S-1-5-21-(d+-?){4}$\" } \r\n        }\r\n    \r\n        # We'll need the NTuser.dat file to load each users registry hive. So we grab it if their account sid matches the above pattern. \r\n        $UserProfiles = Foreach ($Pattern in $Patterns) { \r\n            Get-ItemProperty \"HKLM:SOFTWAREMicrosoftWindows NTCurrentVersionProfileList*\" |\r\n                Where-Object { $_.PSChildName -match $Pattern } | \r\n                Select-Object @{Name = \"SID\"; Expression = { $_.PSChildName } },\r\n                @{Name = \"UserName\"; Expression = { \"$($_.ProfileImagePath | Split-Path -Leaf)\" } }, \r\n                @{Name = \"UserHive\"; Expression = { \"$($_.ProfileImagePath)NTuser.dat\" } }, \r\n                @{Name = \"Path\"; Expression = { $_.ProfileImagePath } }\r\n        }\r\n    \r\n        # There are some situations where grabbing the .Default user's info is needed.\r\n        switch ($IncludeDefault) {\r\n            $True {\r\n                $DefaultProfile = \"\" | Select-Object UserName, SID, UserHive, Path\r\n                $DefaultProfile.UserName = \"Default\"\r\n                $DefaultProfile.SID = \"DefaultProfile\"\r\n                $DefaultProfile.Userhive = \"$env:SystemDriveUsersDefaultNTUSER.DAT\"\r\n                $DefaultProfile.Path = \"C:UsersDefault\"\r\n    \r\n                $DefaultProfile | Where-Object { $ExcludedUsers -notcontains $_.UserName }\r\n            }\r\n        }\r\n    \r\n        $UserProfiles | Where-Object { $ExcludedUsers -notcontains $_.UserName }\r\n    }\r\n\r\n    # This makes setting registry keys A LOT easier.\r\n    function Set-HKProperty {\r\n        param (\r\n            $Path,\r\n            $Name,\r\n            $Value,\r\n            [ValidateSet('DWord', 'QWord', 'String', 'ExpandedString', 'Binary', 'MultiString', 'Unknown')]\r\n            $PropertyType = 'DWord'\r\n        )\r\n        if (-not $(Test-Path -Path $Path)) {\r\n            # Check if path does not exist and create the path\r\n            New-Item -Path $Path -Force | Out-Null\r\n        }\r\n        if ((Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue)) {\r\n            # Update property and print out what it was changed from and changed to\r\n            $CurrentValue = (Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue).$Name\r\n            try {\r\n                Set-ItemProperty -Path $Path -Name $Name -Value $Value -Force -Confirm:$false -ErrorAction Stop | Out-Null\r\n            }\r\n            catch {\r\n                Write-Error \"[Error] Unable to Set registry key for $Name please see below error!\"\r\n                Write-Error $_\r\n                exit 1\r\n            }\r\n            Write-Host \"$Path$Name changed from $CurrentValue to $($(Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue).$Name)\"\r\n        }\r\n        else {\r\n            # Create property with value\r\n            try {\r\n                New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $PropertyType -Force -Confirm:$false -ErrorAction Stop | Out-Null\r\n            }\r\n            catch {\r\n                Write-Error \"[Error] Unable to Set registry key for $Name please see below error!\"\r\n                Write-Error $_\r\n                exit 1\r\n            }\r\n            Write-Host \"Set $Path$Name to $($(Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue).$Name)\"\r\n        }\r\n    }\r\n\r\n    # This function was made just so I didn't have to make two versions of what's essentially the same code.\r\n    function Set-WallpaperKeys {\r\n        param(\r\n            $BasePath,\r\n            $WallpaperStyle,\r\n            $ImagePath\r\n        )\r\n\r\n        $RegKey = \"$BasePathControl PanelDesktop\"\r\n        $Style = switch ($WallpaperStyle) {\r\n            \"Fill\" { 10 }\r\n            \"Fit\" { 6 }\r\n            \"Stretch\" { 2 }\r\n            \"Tile\" { 0 }\r\n            \"Center\" { 0 }\r\n            \"Span\" { 22 }\r\n        }\r\n\r\n        Set-HKProperty -Path $RegKey -Name \"Wallpaper\" -Value $ImagePath -PropertyType \"String\"\r\n        Set-HKProperty -Path $RegKey -Name \"WallpaperStyle\" -Value $Style -PropertyType \"String\"\r\n        if ($WallpaperStyle -eq \"Tile\") {\r\n            Set-HKProperty -Path $RegKey -Name \"TileWallpaper\" -Value 1 -PropertyType \"String\"\r\n        }\r\n        else {\r\n            Set-HKProperty -Path $RegKey -Name \"TileWallpaper\" -Value 0 -PropertyType \"String\"\r\n        }\r\n    }\r\n\r\n    # This will overwrite the %APPDATA%MicrosoftWindowsThemesTranscodedWallpaper file.\r\n    function Reset-TranscodedWallpaper {\r\n        param(\r\n            $Username,\r\n            $BasePath\r\n        )\r\n\r\n        Write-Host \"Replacing transcoded wallpaper file for $Username.\"\r\n\r\n        if (-not (Test-Path \"$BasePathMicrosoftWindowsThemesTranscodedWallpaper\" -ErrorAction SilentlyContinue)) {\r\n            Write-Host \"Transcoded Wallpaper File does not exist. Creating it...\"\r\n            New-Item -ItemType \"file\" -Path \"$BasePathMicrosoftWindowsThemes\" -Name \"TranscodedWallpaper\" | Out-Null\r\n            # After creating a blank one windows will automatically overwrite it with what's used by the current wallpaper. We'll need to sleep to overwrite it.\r\n            Start-Sleep -Seconds 7\r\n        }\r\n\r\n        # If there's more than one file or the file for some reason still does not exist then something fishy is going on.\r\n        $TranscodedWallpaper = Get-ChildItem \"$BasePathMicrosoftWindowsThemes\" | Where-Object { $_.Name -eq \"TranscodedWallpaper\" }\r\n        if (($TranscodedWallpaper | Measure-Object).Count -gt 1) {\r\n            Write-Warning -Message \"There is more than 1 Transcoded wallpaper file user $Username may have to Log out and Log back in again to complete the wallpaper update.\"\r\n        }\r\n        elseif (($TranscodedWallpaper | Measure-Object).Count -lt 1) {\r\n            Write-Warning -Message \"Transcoded wallpaper file does not exist. User $Username may have to Log out and Log back in again to complete the wallpaper update.\"\r\n        }\r\n        else {\r\n            try {\r\n                if (Test-Path $TranscodedWallpaper.FullName -ErrorAction SilentlyContinue) { Get-Item $TranscodedWallpaper.FullName | Remove-Item -Force }\r\n                Copy-Item -Path $ExistingImage -Destination $TranscodedWallpaper.FullName -Force -ErrorAction Stop\r\n            }\r\n            catch {\r\n                Write-Warning -Message \"Failed to update Transcoded wallpaper file. User $Username may have to Log out and Log back in again to complete the wallpaper update.\"\r\n            }\r\n        } \r\n    }\r\n\r\n    # This just restarts explorer.exe\r\n    function Reset-Explorer {\r\n        Write-Host \"Restarting Explorer.exe\"\r\n        Get-Process explorer | Stop-Process -Force\r\n        Start-Process explorer.exe\r\n    }\r\n\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\nprocess {\r\n\r\n    # If we were given a local file and a link use the local file.\r\n    if ($Url -and -not ($ExistingImage)) {\r\n        \r\n        $ExistingImage = Invoke-Download -Url $Url -BaseName \"$Directorywallpaper-$(Get-Random)\"\r\n    }\r\n    \r\n    # Warn that older OS's don't always show the change immediately.\r\n    if ([System.Environment]::OSVersion.Version.Major -lt 10) {\r\n        Write-Warning \"On older Operating Systems wallpaper changes may require the user to log out and log back in to take effect.\"\r\n    }\r\n\r\n    if (-not (Test-IsSystem)) {\r\n\r\n        # Set's the wallpaper registry keys.\r\n        Set-WallpaperKeys -BasePath \"Registry::HKEY_CURRENT_USER\" -ImagePath $ExistingImage -WallpaperStyle $WallpaperStyle\r\n\r\n        if (-not ($ReplaceTranscodedWallpaperFile)) {\r\n            Write-Warning \"Replacing the wallpaper transcoded file is required for wallpaper change to take immediate effect.\"\r\n            Write-Host \"\"\r\n            continue\r\n        }\r\n\r\n        # Replaces the transcoded wallpaper file.\r\n        Reset-TranscodedWallpaper -Username $env:USERNAME -BasePath $env:APPDATA\r\n        \r\n        if ($RestartExplorer) {\r\n            Reset-Explorer\r\n        }\r\n\r\n        exit 0\r\n    }\r\n\r\n    Write-Host \"\"\r\n\r\n    $UserProfiles = Get-UserHives -Type \"All\"\r\n    # Loop through each profile on the machine\r\n    Foreach ($UserProfile in $UserProfiles) {\r\n        # Load User ntuser.dat if it's not already loaded\r\n        If (($ProfileWasLoaded = Test-Path Registry::HKEY_USERS$($UserProfile.SID)) -eq $false) {\r\n            Start-Process -FilePath \"cmd.exe\" -ArgumentList \"\/C reg.exe LOAD HKU$($UserProfile.SID) `\"$($UserProfile.UserHive)`\"\" -Wait -WindowStyle Hidden\r\n        }\r\n\r\n        # Sets the wallpaper registry keys.\r\n        Set-WallpaperKeys -BasePath \"Registry::HKEY_USERS$($UserProfile.SID)\" -ImagePath $ExistingImage -WallpaperStyle $WallpaperStyle\r\n\r\n        if (-not ($ReplaceTranscodedWallpaperFile)) {\r\n            Write-Warning \"Replacing the wallpaper transcoded file is required for wallpaper change to take immediate effect.\"\r\n            Write-Host \"\"\r\n            continue\r\n        }\r\n\r\n        # Replace the transcoded wallpaper\r\n        Reset-TranscodedWallpaper -Username $UserProfile.UserName -BasePath \"$($UserProfile.Path)AppDataRoaming\"\r\n        \r\n        Write-Host \"\"\r\n\r\n        # Unload NTuser.dat\r\n        If ($ProfileWasLoaded -eq $false) {\r\n            [gc]::Collect()\r\n            Start-Sleep 1\r\n            Start-Process -FilePath \"cmd.exe\" -ArgumentList \"\/C reg.exe UNLOAD HKU$($UserProfile.SID)\" -Wait -WindowStyle Hidden | Out-Null\r\n        }\r\n    }\r\n\r\n    if ($RestartExplorer) {\r\n        Reset-Explorer\r\n    }\r\n\r\n    exit 0\r\n}\r\nend {\r\n    \r\n    \r\n    \r\n}<\/pre>\n<p>&nbsp;<\/p>\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><\/p>\n<h2>Detalhamento<\/h2>\n<p>O script funciona em v\u00e1rios est\u00e1gios:<\/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>Inicializa\u00e7\u00e3o de par\u00e2metros<\/strong>: Ele come\u00e7a definindo par\u00e2metros como o URL do papel de parede, o diret\u00f3rio de armazenamento e o estilo (por exemplo, Fill, Fit, Stretch).<\/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>Verifica\u00e7\u00f5es pr\u00e9-execu\u00e7\u00e3o<\/strong>: Valida o estilo do papel de parede e verifica a exist\u00eancia da imagem e do diret\u00f3rio especificados.<\/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>Baixando o papel de parede<\/strong>: Se for fornecido um URL, o script far\u00e1 o download da imagem para o diret\u00f3rio especificado.<\/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>Configura\u00e7\u00e3o do papel de parede para cada usu\u00e1rio<\/strong>: O script modifica as configura\u00e7\u00f5es de registro de cada perfil de usu\u00e1rio para alterar o papel de parede. Ele tamb\u00e9m lida com casos especiais, como contas do sistema.<\/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>Op\u00e7\u00f5es de efeito imediato<\/strong>: As op\u00e7\u00f5es para substituir o arquivo de papel de parede transcodificado e reiniciar o processo do Explorer garantem que as altera\u00e7\u00f5es tenham efeito imediato.<\/li>\n<\/ul>\n<h2>Casos de uso em potencial<\/h2>\n<p>Imagine que um administrador de TI de uma grande corpora\u00e7\u00e3o precise atualizar os planos de fundo da \u00e1rea de trabalho para um novo logotipo da empresa em todas as m\u00e1quinas dos funcion\u00e1rios. Usando esse script, eles podem implementar o novo papel de parede em toda a rede, garantindo que todos os usu\u00e1rios, independentemente de suas configura\u00e7\u00f5es individuais, vejam a marca atualizada.<\/p>\n<h2>Compara\u00e7\u00f5es<\/h2>\n<p>Tradicionalmente, a altera\u00e7\u00e3o de pap\u00e9is de parede em v\u00e1rios perfis exigia ajustes manuais ou pol\u00edticas de grupo. Esse script oferece uma abordagem mais direta e flex\u00edvel, especialmente \u00fatil em ambientes em que as pol\u00edticas de grupo n\u00e3o s\u00e3o vi\u00e1veis ou s\u00e3o muito complicadas de implementar.<\/p>\n<h2>Implica\u00e7\u00f5es<\/h2>\n<p>Embora esse script ofere\u00e7a conveni\u00eancia, ele tamb\u00e9m destaca a necessidade de um gerenciamento cuidadoso das permiss\u00f5es de script e das pol\u00edticas de execu\u00e7\u00e3o, pois envolve a modifica\u00e7\u00e3o das configura\u00e7\u00f5es do registro e dos arquivos do sistema, o que pode representar riscos \u00e0 seguran\u00e7a se for mal utilizado.<\/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=\"6\" data-aria-level=\"1\"><strong>Teste minuciosamente<\/strong>: Sempre teste os scripts em um ambiente controlado antes de implement\u00e1-los em toda a rede.<\/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>Gerenciar permiss\u00f5es<\/strong>: Restringir a execu\u00e7\u00e3o de scripts ao pessoal autorizado para evitar o uso indevido.<\/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>Altera\u00e7\u00f5es no documento<\/strong>: Mantenha um registro de quando e como o script \u00e9 usado para fins de auditoria e solu\u00e7\u00e3o de problemas.<\/li>\n<\/ul>\n<h2>Considera\u00e7\u00f5es finais<\/h2>\n<p>Em um ambiente de TI din\u00e2mico, ferramentas como o <a href=\"https:\/\/www.ninjaone.com\/pt-br\/eficiencia\/\">NinjaOne podem aumentar significativamente a efici\u00eancia e a efic\u00e1cia de tarefas<\/a> como a implanta\u00e7\u00e3o desse script do PowerShell. Com seus <a href=\"https:\/\/www.ninjaone.com\/pt-br\/rmm\/automacao-de-ti\/\">recursos<\/a> robustos <a href=\"https:\/\/www.ninjaone.com\/pt-br\/rmm\/automacao-de-ti\/\">de gerenciamento e automa\u00e7\u00e3o<\/a>, o NinjaOne pode simplificar o processo de implementa\u00e7\u00e3o, tornando mais simples e confi\u00e1vel para os profissionais de TI a manuten\u00e7\u00e3o de ambientes de desktop consistentes em v\u00e1rios perfis de usu\u00e1rios. Esse alinhamento da automa\u00e7\u00e3o e do gerenciamento refor\u00e7a a import\u00e2ncia da integra\u00e7\u00e3o de ferramentas avan\u00e7adas, como <a href=\"https:\/\/www.ninjaone.com\/blog\/category\/scripts\/\">os scripts do PowerShell<\/a>, a estrat\u00e9gias mais amplas de gerenciamento de TI.<\/p>\n","protected":false},"author":35,"featured_media":194544,"parent":0,"menu_order":0,"comment_status":"open","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-816973","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\/816973","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=816973"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media\/194544"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media?parent=816973"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/operating_system?post=816973"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/use_cases?post=816973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}