powershell - 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)说支持通配符,但没有显示它的例子.
我错过了什么还是这是一个错误?
解决方案
该VisibleExternalCommands
选项不接受通配符。此文档错误已在https://github.com/MicrosoftDocs/PowerShell-Docs/issues/4756中修复。
推荐阅读
- html - Laravel 公共 CSS 样式表
- solidity - 如何修复“警告:不推荐使用“var”关键字”?
- javascript - 如何在 React.js 前端应用程序中显示来自 Rails 5 API 的数据?
- r - ggplot sec_axis 不适用于在 3.1 版中将轴提升到幂的转换
- c++ - run protobuf example on Mac OS with error
- php - How to change value output after edit Nestable
- python - Count of records of table in mssql server
- python - How to write single class based view for multiple url?
- angularjs - accessing node modules from index.html from public folder
- c - Binary Search Tree (BST) - Traversal search