首页 > 解决方案 > VisibleExternalCommands 中的通配符在 PSSessionConfiguration 中不起作用

问题描述

我正在尝试在VisibleExternalCommands中为New-PSSessionConfigurationFile使用诸如“c:\scripts\*.ps1”之类的通配符,生成的 .pssc 文件看起来不错,但无法按预期工作,而且这里的文档很弱。我只能通过提供完整路径来使 VisibleExternalCommands 工作。

重现步骤,在 Win10 上使用 PowerShell 5.1 进行测试:

安装目录和脚本:

Enable-PSRemoting -Force
mkdir c:\scripts
echo "Write-Output hello" | Out-File c:\scripts\hello.ps1 -Force
echo "Write-Output world" | Out-File c:\scripts\world.ps1 -Force

使用通配符(不工作):

New-PSSessionConfigurationFile -VisibleExternalCommands "c:\scripts\*.ps1" -Path c:\scripts\TestWildcard.pssc -SessionType RestrictedRemoteServer -LanguageMode FullLanguage
Register-PSSessionConfiguration -Name TestWildcard -Path c:\scripts\TestWildcard.pssc -Force
Invoke-Command . -ConfigurationName TestWildcard {c:\scripts\hello.ps1; c:\scripts\world.ps1}
# Fails to recognize both .ps1 scripts as external commands

使用完整路径(工作正常):

New-PSSessionConfigurationFile -VisibleExternalCommands "c:\scripts\hello.ps1" -Path c:\scripts\TestFullPath.pssc -SessionType RestrictedRemoteServer -LanguageMode FullLanguage
Register-PSSessionConfiguration -Name TestFullPath -Path c:\scripts\TestFullPath.pssc -Force
Invoke-Command . -ConfigurationName TestFullPath {c:\scripts\hello.ps1; c:\scripts\world.ps1}
# Prints hello and fails to recognize c:\scripts\world.ps1

文档(https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/new-pssessionconfigurationfile?view=powershell-5.1)说支持通配符,但没有显示它的例子.

我错过了什么还是这是一个错误?

标签: powershellpowershell-remoting

解决方案


VisibleExternalCommands选项不接受通配符。此文档错误已在https://github.com/MicrosoftDocs/PowerShell-Docs/issues/4756中修复。


推荐阅读