我试图在Win10上的PowerShell ISE中创建一个脚本,该脚本可切换我的桌面背景。
不起作用。我的脚本怎么了? $newWallpaper
似乎具有正确的值,因此最终Set-Wallpaper
函数似乎无法正常工作。
还是我需要更改任何其他设置才能使其正常工作?
#To make powershell scripts work in general type
#"set-executionpolicy remotesigned"
#into the PS-Console firstly
#This script changes the background picture
Function Set-WallPaper($Value) {
Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop' -Name wallpaper -Value $value
rundll32.exe user32.dll, UpdatePerUserSystemParameters
}
$testWallpaper = "C:\Users\test\Pictures\Backgrounds\test_wallpaper.jpg"
$testWallpaperPlaceholder = "*test_wallpaper.jpg*"
$otherWallpaper = "C:\Users\test\Pictures\Backgrounds\Dark_Canyon.jpg"
#Get-ItemProperty -path 'HKCU:\Control Panel\Desktop' | Select -Property WallPaper
$currentWallpaper = Get-ItemProperty -Path 'HKCU:\Control Panel\Desktop'
$currentWallpaper = $currentWallpaper.WallPaper
$isTest = $currentWallpaper -like $testWallpaperPlaceholder
$newWallpaper = if ($isTest) {$otherWallpaper} else {$testWallpaper}
Set-WallPaper -Value $newWallpaper.Trim('"')