小编Tho*_*ten的帖子

脚本环境影响父shell

修改 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)

很明显,调试跟踪是活跃的,并且文化变化持续存在......

powershell

3
推荐指数
1
解决办法
151
查看次数

cmdlet 的包装函数 - 传递剩余参数

我正在编写一个使用 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 社区扩展来解决该问题,GetTypeEchoArgs没有成功。目前我几乎正在考虑一个错误(可能与这张票有关??)。

parameters powershell wrapper

1
推荐指数
1
解决办法
1057
查看次数

标签 统计

powershell ×2

parameters ×1

wrapper ×1