2016-08-17 62 views
0

最近我遇到了一个情况,我们需要使用PowerShell设置默认壁纸以及任何现有用户的壁纸。更改所有用户的壁纸

我们可以通过替换文件C:\ Windows \ Web \ Wallpaper \ Windows \ img0.jpg来设置默认壁纸,但我还没有找到替换任何现有壁纸的合适解决方案。

有些事情我想过/试过:

  • 设置从注册表中的墙纸。这个问题是为每个用户做的。
  • 删除并复制TranscodedWallpaper文件。问题在于Windows 7命名文件TranscodedWallpaper.jpg,Windows 8命名为TranscodedWallpaper.bmp,Windows 10命名为TranscodedWallpaper。虽然我想我们可以创建三个不同版本的文件并检查操作系统版本,但我宁愿在采用此路由之前验证没有其他解决方案。

我完全错过了什么吗?有人对我们如何设置这个建议有什么建议吗?

在此先感谢!

+0

如何使用GPO?组策略做了很多整洁的事情。 – TheMadTechnician

+0

完全同意,但我们并不总是知道这些计算机是否将使用GPO进行设置。我正在研究的东西是加载用户配置单元。看起来很有希望。 –

+0

“使用GPO进行设置”是什么意思?只需将计算机对象放入AD中相应的OU中,GPO就会自动应用。 –

回答

0

经过一番玩耍,这是我想出来的。我不是PowerShell专家,所以随时可以抛出一些更好的解决方案。

# Get each folder under "Users" 
$drive = (Get-Location).Drive.Root 
$users = Get-ChildItem "$($drive)Users" 

# For each user, load and edit their registry 
foreach ($user in $users) { 

    # If this isn't us, load their hive and set the directory 
    # If this is us, use HKEY_CURRENT_USER 
    if ($user.Name -ne $env:username) { 
     reg.exe LOAD HKU\Temp "$($drive)Users\$($user.Name)\NTUSER.DAT" 
     $dir = "Registry::HKEY_USERS\Temp\Control Panel\Desktop" 
    } else { 
     $dir = "Registry::HKEY_CURRENT_USER\Control Panel\Desktop" 
    } 

    # We don't care about users that don't have this directory 
    if ((Test-Path $dir)) { 

     # Set the image 
     Set-ItemProperty -Path $dir -Name "Wallpaper" -value "$($drive)Users\Public\Pictures\Sample Pictures\Tulips.jpg" 

     # Set the style to stretch 
     Set-ItemProperty -Path $dir -Name "WallpaperStyle" -value 2 

    } 

    # Unload user's hive 
    if ($user.Name -ne $env:username) { 
     [gc]::Collect() 
     reg.exe UNLOAD HKU\Temp 
    } 
} 

我想感谢TheMadTechnician GPO的建议。一般情况下,我肯定会同意!