通过powershell远程按需设置壁纸

zlhcx6iw  于 2023-01-26  发布在  Shell
关注(0)|答案(1)|浏览(146)

我创建了一个函数Set-Wallpaper

Function Set-WallPaper($Value)
{
    Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $value
    rundll32.exe user32.dll, UpdatePerUserSystemParameters
}

并且可以在本地运行它以使用到期望的JPG的网络路径

Set-Wallpaper -value "\\server\share\image.jpg"

而且很有效。
现在我想在远程PC上运行此功能,我尝试了

Invoke-Command -ComputerName TARGETPC Set-Wallpaper -value "\\server\share\image.jpg"

但错误为Invoke-Command : A parameter cannot be found that matches parameter name 'value'.
我错过了什么?

fwzugrvs

fwzugrvs1#

$session= new-pssession -Computername "yourClientname"
$reslt= Invoke-Command -Session $session -ScriptBlock {your code}

如果你想结束一场争论,就像这样

$reslt= Invoke-Command -Session $session -argumentlist $argument  -ScriptBlock {param ($argument) your code with $argument[0]}

相关问题