'VisibleCmdlets' and 'VisibleFunctions' break internal functions usage #42
Comments
Can you try adding Microsoft.PowerShell.Utility to ModulesToImport in your PSRC? JEA can get funny with dependencies because the module discovery and auto-loading doesn't work the same as it does in a full language session. We generally recommend adding any modules called inside custom scripts or functions to ModulesToImport to ensure they're pre-loaded into the session. You can also try fully qualifying the cmdlet name in your function definition: |
Unfortunately it's exactly the same. We tried many different workarounds and never got back functions :-/ |
@PaulHigin Any tips for Julien? I'm not sure why the built-in commands would stop working inside custom functions. |
I provided some workarounds on this page: https://jnury.github.io/JEA_term_not_recognized_name_cmdlet/ By the way, I only found 6 functions affected:
These functions are all provided by the Microsoft.PowerShell.Utility module |
I'll take a look. |
@jnury Thanks for reporting this. I am able to reproduce the problem. This is old endpoint configuration code that imports core modules into the restricted session through "snapins". The Microsoft.PowerShell.Utility module consists of binary and script components but snapins only deal with the binary component and leave the script out, which is why the script functions are not available. I think this is just old legacy code that should be re-written to use module loading rather than snapins. |
Thank-you @PaulHigin ! |
With the following PowerShell version:
If I use VisibleCmdlets or VisibleFunctions in a RoleCapability file, module functions are no more available for other functions.
How to reproduce
A PSSessionConfiguration file, 'Test-JEA.pssc':
Registered with the command:
A RoleCapability file, 'Test-JEA.psrc' in the folder 'C:\Program Files\WindowsPowerShell\Modules\Test-JEA\RoleCapabilities':
If I enter in the Test-JEA PSSession, TestGuid function works and GetUtilityCommand returns a list of functions and cmdlets from the Microsoft.PowerShell.Utility module:
Now if I want to allow the Clear-Variable cmdlet, in the 'Test-JEA.psrc' file:
The Clear-Variable CmdLet is available, GetUtilityCommand and TestGuid functions are available too. But function TestGuid doesn't work as the New-Guid function is no more available. GetUtilityCommand now only returns cmdlets; functions have disappeared from Microsoft.PowerShell.Utility module:
Using only VisibleCmdLets or VisibleFunctions do the same result.
Expected behavior
The expected behavior is that VisibleCmdlets or VisibleFunctions only affect 'Visible' cmdlet or function but not available functions for internal use
Impact
This is a huge problem as VisibleCmdlets is a main feature of JEA and many modules or custom scripts use functions. In our use case, we would-like to expose Pester based custom functions for monitoring purpose, but Pester cannot load without functions.
The text was updated successfully, but these errors were encountered: