有关为何在PS中运行w /的原因有任何想法和建议,但在从定义为:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Users\bin\ChangeDesktop.ps1"
Run Code Online (Sandbox Code Playgroud)
ChangeDesktop.ps1的内容:
set-itemproperty -path "HKCU:Control Panel\Desktop" -name WallPaper -value ""
rundll32.exe user32.dll, UpdatePerUserSystemParameters
Run Code Online (Sandbox Code Playgroud)
如果我在PS"命令提示符"环境中,桌面背景将自动删除并刷新,除此之外我必须手动刷新桌面以实现更改.
系统是Windows Server 2008 R2 - 全新安装.脚本executionpolicy设置为RemoteSigned,我没有看到任何PS错误.我从桌面快捷方式运行时看不到桌面自动刷新.
划痕头
寻找这个,但找不到解决方案."额外"输出,我的意思是写入输出在错误消息文本后发出的额外文本.即:
write-error -Message "test"
Run Code Online (Sandbox Code Playgroud)
生产:
write-error -Message "test" : test
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
Run Code Online (Sandbox Code Playgroud)
我想只看到文本"test",并通过运行PS脚本的Process对象从stderr中检索它.
我知道可以开发一个复杂的正则表达式(以捕捉可能出现在类别中的所有潜在字符等),但我想避免这种情况.不要忘记,由于控制台,Write-Error也会在每80个字符位置注入一个换行符,因此也必须将其考虑在内.
有没有办法告诉Powershell(2.0)在写入stderr并且只写消息部分时不那么罗嗦?
我有一个简单的PS脚本,需要接受恰好是目录路径的参数.我把这条路径交给我并调用ps脚本如下:
powershell.exe -ExecutionPolicy Bypass -F "C:\temp\ctest\logging test\postinstall.ps1" "C:\temp\ctest\logging test\"
Run Code Online (Sandbox Code Playgroud)
我无法控制将"\"添加到作为此脚本的参数的路径,并且必须使用双引号来说明路径中的空间.所以,我最终得到的是我的ps脚本中的一个变量,即字符串:
C:\temp\ctest\logging test" <<-- error in path! with the double-quote char. :(
Run Code Online (Sandbox Code Playgroud)
我希望,我的问题很简单,但我无法找到解决它的人.在这种情况下,有没有办法告诉powershell不要逃避最后的双引号?
感谢您的时间,并教育我.