Product: PowerShell Studio 2020 (64 Bit)
Build: v5.7.174
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.16299.0
Does Powershell Studio Support Intellisense for Nested Modules in a Powershell Module Project? If not, is that on a road map?
I have a PS Module Project with a nested module defined in the manifest. The code works as expected when I execute the module but when editing, Powershell Studio does not recognize the functions from the nested module.
You can see in the attachments I have the nested module defined in the manifest file. In the main module code, the function "New-CronJob" is from the nested module but is not recognized by the studio and appears in gray.
Inteliisense for Nested modules
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- KeHE Distributors
- Posts: 9
- Last visit: Sat Apr 29, 2023 10:45 am
Inteliisense for Nested modules
- Attachments
-
- Code.JPG (45.77 KiB) Viewed 2217 times
-
- Manifest.JPG (32.53 KiB) Viewed 2217 times
Re: Inteliisense for Nested modules
This is most likely caused by the cache for PowerShell Studio not having that module information. Is the module 'CronTab' listed in the Object Browser panel:
If its not, then your cache needs to be rebuilt or you can import the module via the cache editor.
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- KeHE Distributors
- Posts: 9
- Last visit: Sat Apr 29, 2023 10:45 am
Re: Inteliisense for Nested modules
CronTab is not listed in the object browser. following your suggestion, I rebuilt the cache but it did not appear. I then went to the editor and tried to import it but it failed with "Import failed. Please check permissions and script execution policies" (screenshot) (Note: I am set to bypass for execution policy)
To be clear, this is not a module loaded in the WindowsPowershell\Modules folder. Its a module sitting in a subfolder of the project (screen shot). I happen to have called the subfolder "Modules" which I see is misleading of course from my initial description.
Perhaps I am approaching it incorrectly. I am trying to include with the project some sub-modules. I don't want them to be Required Modules that try to install from the PS Repo. I do know from a PS execution perspective, it does run as expected so I believe using the module being in a subfolder to the main module and defined in "ModuleList" works.
Is there a different way I should be using nested modules in the project so the intellisense can read it?
To be clear, this is not a module loaded in the WindowsPowershell\Modules folder. Its a module sitting in a subfolder of the project (screen shot). I happen to have called the subfolder "Modules" which I see is misleading of course from my initial description.
Perhaps I am approaching it incorrectly. I am trying to include with the project some sub-modules. I don't want them to be Required Modules that try to install from the PS Repo. I do know from a PS execution perspective, it does run as expected so I believe using the module being in a subfolder to the main module and defined in "ModuleList" works.
Is there a different way I should be using nested modules in the project so the intellisense can read it?
- Attachments
-
- Project.JPG (28.41 KiB) Viewed 2194 times
-
- Error.JPG (68.44 KiB) Viewed 2194 times
Re: Inteliisense for Nested modules
What are the permissions of the psm1 file you tried to import? It is strange that the import failed. Also, what is your PowerShell execution Policy set to?
You use the NestedModules element of the psd1 file to reference the path of the nested module to be loaded. PowerShell will look in the paths specified in the $env:PSModulePath environment variable when searching for available modules on a system. Therefore, this requires that the Nested module's path be relative to a location in the $env:PSModulePath.
You use the NestedModules element of the psd1 file to reference the path of the nested module to be loaded. PowerShell will look in the paths specified in the $env:PSModulePath environment variable when searching for available modules on a system. Therefore, this requires that the Nested module's path be relative to a location in the $env:PSModulePath.
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- KeHE Distributors
- Posts: 9
- Last visit: Sat Apr 29, 2023 10:45 am
Re: intellisense for Nested modules
I have full rights to the file. I created and placed it into the folder.
As to the nestmodule, when including a folder path as I have, powershell seems to including looking in a path relative to the module itself. It might try the $env:PSModulePath as part of a search order but it does seem to find it when its local to the module.
To be clear, Powershell does execute the code as expected and works properly. It sounds like Powershell Studio however does not attempt to import the module from the nestedmodules element if the sub module path is relative to the module itself and not located in the $env:PSModulePath?
As to the nestmodule, when including a folder path as I have, powershell seems to including looking in a path relative to the module itself. It might try the $env:PSModulePath as part of a search order but it does seem to find it when its local to the module.
To be clear, Powershell does execute the code as expected and works properly. It sounds like Powershell Studio however does not attempt to import the module from the nestedmodules element if the sub module path is relative to the module itself and not located in the $env:PSModulePath?
Last edited by KeHE Distributors on Thu May 28, 2020 12:04 pm, edited 1 time in total.
- KeHE Distributors
- Posts: 9
- Last visit: Sat Apr 29, 2023 10:45 am
Re: intellisense for Nested modules
I created a sample project using a sub-folder of the project to hold the nested module.
You can see in the studio, the function from the sub-module is labeled as unknown.
When the project runs though, powershell successfully locates and execute the sub module function.
Note: I tried to import the sub module to the cache in PS Studio and it succeeded with this example but the function from the sub module still shows as unknown in the editor.
You can see in the studio, the function from the sub-module is labeled as unknown.
When the project runs though, powershell successfully locates and execute the sub module function.
Note: I tried to import the sub module to the cache in PS Studio and it succeeded with this example but the function from the sub module still shows as unknown in the editor.
Re: Inteliisense for Nested modules
We are currently investigating this and will get back to you with more information.
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Inteliisense for Nested modules
From the example you provided, I was able to get intellisense working with your nested modules by doing the following:
1. Update the values for ModuleList and NestedModules in the psd1 to the following:
I was not able to run Test-Module.ps1 until I updated this.
2. Open the cache editor and make sure to have the version of PowerShell you are working with selected: Import the nested module and locate the nested module in the SubModule folder. Make sure you can see the module in the list and is checked.
Close the cache editor.
3. In PowerShell Studio, reload the cache: The module should now be visible from the Object Browser panel: The intellisense for the nested module should now be working.
1. Update the values for ModuleList and NestedModules in the psd1 to the following:
- @('.\SubModules\MySubmodule.psm1')
2. Open the cache editor and make sure to have the version of PowerShell you are working with selected: Import the nested module and locate the nested module in the SubModule folder. Make sure you can see the module in the list and is checked.
Close the cache editor.
3. In PowerShell Studio, reload the cache: The module should now be visible from the Object Browser panel: The intellisense for the nested module should now be working.
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.