I am trying to use wildcards like "c:\scripts\*.ps1" in VisibleExternalCommands for New-PSSessionConfigurationFile and the resulting .pssc file looks fine, but cannot get it to work as expected and the documentation is weak here. I can only make VisibleExternalCommands work by giving full path.
Steps to reproduce, tested on Win10 with PowerShell 5.1:
Setup directory and scripts:
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
Using Wildcard (NOT working):
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
Using Full Path (works fine):
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
The documentation (https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/new-pssessionconfigurationfile?view=powershell-5.1) says that wildcard characters are supported, but shows no example of it.
Am I missing something or is this a bug?
The VisibleExternalCommands
option does not accept wildcards. This documentation bug was fixed in https://github.com/MicrosoftDocs/PowerShell-Docs/issues/4756.