0

We have a PowerShell snapin that requires version 3.0 of PowerShell to function. So we used the following file element in a WiX (3.8) file:

        <File Id="MySnapin.dll" 
              Name="MySnapin.dll" 
              Assembly=".net" 
              KeyPath="yes" 
              Vital="no" 
              Checksum="yes" 
              DiskId="1" 
              Source="$(var.FilesPath)\Bin\MySnapin.dll" 
              AssemblyApplication="MySnapin.dll">
           <ps:SnapIn Id="MySnapin" 
                      Description="This is a PowerShell snap-in" 
                      Vendor="My Company Inc." 
                      RequiredPowerShellVersion="3.0">
                <ps:FormatsFile FileId="MySnapin.format.ps1xml" />
           </ps:SnapIn>
        </File>

However, when installing this the snapin cannot be found in powershell (Get-PSSnapIn -Registered). When examining the registry it turns out that the snapin has been registered in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\PowerShell\3\PowerShellSnapIns\MySnapin. But when running installutil.exe on the DLL, the registration ends up in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\PowerShellSnapIns\MySnapin, and powershell finds it properly. Is this a bug in WiX Toolset, or am I doing something wrong here?

Where are the registrations really supposed to go?

2
  • 1
    Sounds like it could be a bug, but is there a reason you are using a snap-in over a module? Snap-ins are generally only used now when you need to support older versions of PowerShell. Commented Sep 9, 2014 at 22:53
  • The reason for using a SnapIn is very simple; I wasn't aware of the possibility to use modules for cmdlets until just recently. Switching to a module instead seems to be a good workaround for this problem. Commented Sep 10, 2014 at 4:55

1 Answer 1

2

Yea this sounds like a bug, so you might want to report it to the WiX maintainers, but there is better way.

The recommended way to add cmdlets and functions is through PowerShell Modules. Snap-ins are the older way to extend PowerShell and while still supported are not recommended. If you do not need to support adding your cmdlets to older versions of PowerShell use a module.

Modules are somewhat easier to deploy than snap-ins. Basically you can put them anywhere, however if you want users to be able to load them by name they need to exist on the PSModulePath environment variable. Your installer would add your files and update the PSModulePath variable to include a Modules folder from your install folder. Then users will simply be able to call Import-Module MyModule to load them. Also, see the documentation on PSModulePath.

This blog post contains a detailed walkthrough of how to write a WiX installer to do this. It also has instructions on how to check that the required PowerShell version is installed. Basically, you are going to check the under both those registry keys you mentioned for the PowerShellEngine\PowerShellVersion value.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the information. Indeed the modules are much nicer to use than the SnapIns, so we will convert our solution to use these instead. Will submit a bug report to the WiX team nevertheless.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.