Import-Module MSI Error

May 16, 2014 at 5:04 PM
Edited May 16, 2014 at 5:07 PM
Heath,
I'm seeing the following error when trying to import the MSI module.

PS C:\Users\nelmer.HRO> import-module MSI
Import-Module : You must provide a value expression on the right-hand side of the '-' operator.
At line:1 char:14
  • import-module <<<< MSI
    • CategoryInfo : InvalidOperation: (:) [Import-Module], ParseException
    • FullyQualifiedErrorId : FormatXmlUpateException,Microsoft.PowerShell.Commands.ImportModuleCommand
My co-worker Kirk (who recently spoke at the powershell summit https://www.youtube.com/watch?v=xihN15LKvCs&app=desktop) helped me delve into the cause. Turns out that you have "-shr" bit shifting logic in the XML files which is only available in PowerShell 3.0. So, is the dependency still PS2 or is it now PS3?

We fixed it by adding the code below to the PSM1 file which we found here: http://huddledmasses.org/powershell-needs-shift-operators/

(Added before "export-modulemember...) line.
Add-Type @"
public static class BitShift
{
public static int Right(int x, int count) { return x >> count; }
public static uint Right(uint x, int count) { return x >> count; }
public static long Right(long x, int count) { return x >> count; }
public static ulong Right(ulong x, int count) { return x >> count; }
public static int Left(int x, int count) { return x << count; }
public static uint Left(uint x, int count) { return x << count; }
public static long Left(long x, int count) { return x << count; }
public static ulong Left(ulong x, int count) { return x << count; }
}
"@

Then changed the MSI.types.ps1xml file to replace the "-shr" lines with the following:
[Microsoft.Deployment.WindowsInstaller.TransformValidations] ([BitShift]::Right([int] $this.PSBase.Validations, 16))
[Microsoft.Deployment.WindowsInstaller.TransformValidations] ([BitShift]::Right($this.CharacterCount, 16))

Now it imports successfully! ;)

Thanks for the tool heath! We plan to use it for MSI/Patch validation at build time and in test!

Thanks
Nick
Coordinator
May 28, 2014 at 1:33 AM
Thanks. I found that a while back myself and fixed it in for an upcoming release, but my spare time has been spent more on http://github.com/wix lately. I'm making headway, though, and am shooting for another week or two.

Sorry I didn't see this, but feel free to file a bug next time. I'm always glad to get feedback about how to fix something or make some scenario better! :)