首先,这里是我的代码:ErrorVariable输出并不如预期
$InputPath = "\\Really\long\path\etc"
Get-ChildItem -Path $InputPath -Recurse -Force -ErrorVariable ErrorPath
$ErrorPath | select TargetObject
我面临的问题是与ErrorVariable
参数。 Get-ChildItem要处理的路径太长(通常大约250个字符)。当我管$ ErrorPath选择,输出看起来是这样的:
TargetObject : \\Really\long\path\etc\1
TargetObject : \\Really\long\path\etc\2
TargetObject : \\Really\long\path\etc\3
但是,如果我跑最后一行再次(可以通过运行选择或通过手动键入它),则输出变为这样:
TargetObject
------------
\\Really\long\path\etc\1
\\Really\long\path\etc\2
\\Really\long\path\etc\3
我不知道该如何解释。我更喜欢第二个输出,但我不知道为什么它从第一次到第二次不同。有任何想法吗?
但为什么会发生变化?当我执行两次相同的命令时,它不应该总是这样吗? –