修改 PowerShell 脚本中的某些方面似乎会修改正在运行的 shell。如果我提供脚本而不是运行它,这将是意料之中的。
脚本.ps1
[cultureinfo]::currentculture = [cultureinfo]::InvariantCulture
Set-PSDebug -Trace 1
Run Code Online (Sandbox Code Playgroud)
> [cultureinfo]::currentculture
LCID Name DisplayName
---- ---- -----------
1031 de-DE Deutsch (Deutschland)
> .\script.ps1
> [cultureinfo]::currentculture
DEBUG: 1+ >>>> [cultureinfo]::currentculture
LCID Name DisplayName
---- ---- -----------
127 Unveränderliche Sprache (Unveränderliches Land bzw. unveränderliche Region)
Run Code Online (Sandbox Code Playgroud)
很明显,调试跟踪是活跃的,并且文化变化持续存在......
我正在编写一个使用 ValueFromRemainingArguments 包装 cmdlet 的函数(如此处所述)。
下面的简单代码演示了这个问题:
function Test-WrapperArgs {
Set-Location @args
}
Run Code Online (Sandbox Code Playgroud)
Test-WrapperArgs -Path C:\
Run Code Online (Sandbox Code Playgroud)
Test-WrapperArgs -Path C:\
Run Code Online (Sandbox Code Playgroud)
Test-WrapperUnbound -Path C:\
Set-Location: F:\cygwin\home\thorsten\.config\powershell\test.ps1:69
Line |
69 | Set-Location @UnboundArgs
| ~~~~~~~~~~~~~~~~~~~~~~~~~
| A positional parameter cannot be found that accepts argument 'C:\'.
Run Code Online (Sandbox Code Playgroud)
我尝试通过 PowerShell 社区扩展来解决该问题,GetType但EchoArgs没有成功。目前我几乎正在考虑一个错误(可能与这张票有关??)。