当我跑步时
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize
直接从 PowerShell 运行,代码运行得很好。
但是,当我将这个确切的代码放入文件script.txt
然后运行时
$stdout = Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Get-Content 'script.txt'))) *>&1
我收到以下错误:
Exception calling "Create" with "1" argument(s): "At line:1 char:163
+ ... me, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize
+ ~~~~~~~~~
The string is missing the terminator: "."
是什么导致了这种行为?我必须如何调整代码才能从外部 txt 文件执行脚本?