Page 1 of 2

Trouble Importing Modules

Posted: Tue Sep 11, 2018 12:38 pm
Product, version and build: PowerShell Studio 2018 v5.5.154
32 or 64 bit version of product: 64 BIT
Operating system: Windows 8.1 Pro
32 or 64 bit OS: 64

Please note: One of the modules (PWPS) I'm using is 32-bit only, so I'm viewing PowerShell Studio as "V5 - 32 Bit".

I'm having trouble importing two custom modules. They are for ProjectWise v8i.

The first module is PWPS. The installer is here: ... -and-links

It installs to this location on my computer:
C:\Program Files (x86)\Bentley\ProjectWise\bin\PowerShell\pwps

The second module is PWPS_DAB. It installs from PowerShell Gallery to this location:
C:\Program Files (x86)\WindowsPowerShell\Modules\pwps_dab

I was able to manually import both modules so they now show up in the Object Browser.

However, none of the cmdlets for PWPS show up, and in scripts they're just greyed out.

The cmdlets for PWPS_DAB show up and are highlighted in scripts, but the PWPS_DAB help doesn't work. If I right-click PWPS_DAB and select "Refresh Help", I get this error:
>> Refreshing: ERROR: The specified module 'pwps_dab' was not loaded because no valid module file was found in any module directory.

If I right-click a PWPS_DAB cmdlet and select "Show Help", the Help screen is just blank.

Importing files from either module is touch and go. Sometimes it works. Sometimes the PowerShell Cache Editor crashes. Sometimes I get this error (attached):
"Import failed. Please check permissions and script execution policy."

However, the script execution policy (attached) is unrestricted for both 32 bit and 64 bit.

Any of those can happen with the same file - the editor can crash the first time I try, give an error, then work.

Any help you can provide on fully importing these modules would be greatly appreciated.

Re: Trouble Importing Modules

Posted: Tue Sep 11, 2018 1:29 pm
by davidc
Please check for any event log entries if the CacheEdit64.exe crashes. That might give us an idea as to why it is crashing. Also try running the 32-bit version of the CacheEdit, since the module is x86 only:

C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2018\CacheBuilder32\CacheEdit.exe

As for the module help, the module must be in a discoverable location. In other words, it must be located in a $env:PSModulePath folder in order for the process to find it. You might also run into the x86 vs x64 issue here as well.

Does the module have any host restrictions? Sometimes that can prevent our caching process from loading the module.

Re: Trouble Importing Modules

Posted: Tue Sep 11, 2018 2:03 pm
No luck with the 32-bit version of the CacheEdit. It still crashed, and the "ImportV5_32bit.log" log is empty.

The console returns the location for $env:PSModulePath:
C:\Users\[user]\Documents\WindowsPowerShell\Modules;C:\Program Files (x86)\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Bentley\ProjectWise\bin

I'm not sure about the host restrictions - how would I check that?


Re: Trouble Importing Modules

Posted: Tue Sep 11, 2018 2:35 pm
by davidc
Were there any entries in the Windows Event Application log?

The restrictions would be in the manifest (psd1 file) of the module. It would have an entry for PowerShellHostName or PowerShellHostVersion. From what I see in the PowerShell Gallery the module doesn't have a host restriction. I suspect something in the module is causing the crash during the caching process.

Re: Trouble Importing Modules

Posted: Tue Sep 11, 2018 3:27 pm
Yep, there were! I've attached them for your review.

That explains it. I looked at the PWPS (i.e. the module that requires an installer, not the module from PowerShell Gallery) manifest (pwps.psd1), and I didn't see anything about a host restriction. What I did notice is its first line:

# Script module or binary module file associated with this manifest.

"pwps.dll" is, naturally, one of the files that I cannot import into the cache editor.

Meanwhile the PWPS_DAB's manifest (pwps_dab.psd1) first line is:

# Script module or binary module file associated with this manifest.

"pwps_dab.dll" is the file I had to import to the cache to make the PWPS_DAB cmdlets register in PowerShell Studio.

So if I can import "pwps.dll", the PWPS cmdlets will probably register in PowerShell Studio.

That at least narrows down where the problem is.

Re: Trouble Importing Modules

Posted: Wed Sep 12, 2018 7:11 am
by davidc
ModuleToProcess is an alias for RootModule in later versions of PowerShell, so that shouldn't be an issue.

As for the logs, I can't see the details in there but it looks like a .NET Runtime exception is occurring. I will have the team look at the module and test it on our end.

Re: Trouble Importing Modules

Posted: Wed Sep 12, 2018 9:12 am
by davidc
Looks like the first module requires their product to be installed, so we weren't able to test it.

As for the pwps_dab module, we found that importing the module returns two versions of the same module. One with 0.0 version and one with the correct version number. We are updating our caching process to accommodate this weird situation.
In addition, I noticed the module attempts to modify the host's settings and the runspace's threading model, which fails when you don't have a normal PowerShell host. Therefore, I suspect that the first module is attempting to do something similar and it results in the crash.

Re: Trouble Importing Modules

Posted: Wed Sep 12, 2018 2:38 pm
I've attached the log items as events this time - hopefully that will give you the full log information.

That explains a different problem I've run into.

If you try to import the modules in a script run from PowerShell Studio, you get an error (attached). If you run the original script directly from Windows PowerShell ISE it runs fine (attached).

I've been getting around it by commenting out the import module commands from any script I run from PowerShell Studio and making sure my profile imports the modules. The scripts run fine then.

I was wondering why the modules showed up multiple times in the Cache Editor. I've attached a screenshot for your reference - PWPS shows up twice, PWPS_DAB three times.

I've also attached a screenshot of how the modules are displayed in Windows PowerShell ISE. PWPS is displayed once, but PWPS_DAB is displayed twice. Each instance of PWPS_DAB has different commands.


Re: Trouble Importing Modules

Posted: Wed Sep 12, 2018 3:36 pm
by davidc
Thank you for the full event log information. It helps us narrow down the problem. Can you try importing a different module and see if you also get an error?

The PWPS loading error is the same I mentioned before. The module attempts to modify the host object but the property it tries to access is not present in our host. I recommend reporting the issue the vendor. There are other ways of accessing the current runspace in PowerShell without using the host object.
Note: If you change the ErrorAction it should continue to load the module but there could be other issues.

As for the CacheEditor, it lists all the cache modules on disc. Which means you will have modules listed that are not installed locally. In regards to the PWPS module, it returns two modules objects when imported. That is why you see two copies with different version numbers. This is something we will address in the next service build.

Because these modules require the console, I recommend using the Run Script in Console (Ctrl + F8) command instead.

Re: Trouble Importing Modules

Posted: Wed Sep 12, 2018 4:07 pm
I tried installing the PowerShell Get module from the PowerShell Gallery: ... lGet/1.6.7

I had installed an older version of PowerShell Get without any problems. I had a lot of problems getting PowerShell Studio to install the new version. I think it finally has, but the cache crashes or throws an error if I try to manually import either psd1 file. I've attached the events.