Wildcards in VisibleExternalCommands not working in PSSessionConfiguration


Wildcards in VisibleExternalCommands not working in PSSessionConfiguration



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:scriptshello.ps1 -Force
echo "Write-Output world" | Out-File c:scriptsworld.ps1 -Force



Using Wildcard (NOT working):


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



Using Full Path (works fine):


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



The documentation (https://docs.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?





Discovered another rarity: If using Enter-PSSession instead of Invoke-Command and saving the logic as a script file and executing that, then it seems to be running in an un-restricted session - not using the PSSessionConfiguration which is the whole point, because it WILL then print both "hello" and "world" in both the wildcard and full path scenarios. Furthermore if executing Get-Command within the script file when using Enter-PSSession, in addition to the expected 8 cmdlets (Exit-PSSession etc.), it will return all sorts of other cmdlets, which were meant to be restricted away.
– tholesen
Jul 5 at 12:52









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

iOS Top Alignment constraint based on screen (superview) height