Weird Error Importing Module in Deployment Script

Howdy all!

I’m getting a strange (to me) error when tryin to run a post deployment script with a 3rd party PowerShell module:

2022-09-03 14:01:29.824 -07:00 [ERR] Error: Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=6.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\MipSdkRedist\22.2.0\MipSdkRedist.psm1: line 1
at <ScriptBlock>, C:\Scripts\PostDeplyScript.ps1: line 23

The script fails when it tries to import the MilestonePSTools module (avail in the msft psgallery). That module also tries to import a helper module MipSdkRedist, also installed from the psgallery. Both modules are the same version, and there aren’t any old lingering version installed either.

If I manually import the module in a powershell session it works just fine, it just fails when the Certify tools tries to load it.

Is the Certify tool running the script in some type of “stricter” way that would be causing the error?

I tried tweaking a few things in the script and eventually got this error, but I don’t remember what I did to get it. I’m sure I could reproduce it if needed though:

2022-09-03 14:33:58.695 -07:00 [ERR] Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MipSdkRedist\22.2.0\MipSdkRedist.psd1'.
Cannot verify the Microsoft .NET Framework version 4.7.0 because it is not included in the list of permitted versions.
Populating RepositorySourceLocation property for module MipSdkRedist.
Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MipSdkRedist\22.2.0\MipSdkRedist.psm1'.
Importing variable 'MipSdkPath

I also tried running powershell as local system to see if it would import and it does.

Interesting, I just tried reverting back through old version of their module and if I go as far back as v20.3.0 it loaded, the 3 or so version after it all fail… I’ll see if I can reach out to the author of the module, but I’m still curious as to why it loads in an interactive powershell prompt and ISE but not in the way Certify calls it.

Thanks, Certify The Web will by default run the powershell script within it’s own process using a Powershell “runspace”, so it doesn’t launch the powershell cli. You do also have the option of “Launch New Process” (under Task Parameters) which in turn calls the powershel cli instead of running the script in the same process, that is likely to behave differently so you could try that.

What version of .net do you have installed?