What's the difference between Add-PsSnapIn and Import-Module

Justin R. picture Justin R. · Feb 18, 2011 · Viewed 28.3k times · Source

Powershell has two means for importing additional cmdlets into a session, Add-PsSnapIn and Import-Module. The docs are not at all clear regarding when one would chose one over the other. Does anybody know the difference between these?

Answer

Andy Schneider picture Andy Schneider · Feb 18, 2011

Modules came about in PowerShell V2. V2 can still load Snapins though, if necessary. The big difference is that modules can be deployed using Xcopy. There is no need to register anything. To deploy a Snapin, an installer would have to hack the registry, which would require elevated priveleges. To load a module, you simply have to use the Import-Module command.

Modules can have a lot more metadata using a Module Manifest as well, which can specify all kinds of things that might be useful for the end user to know, including version, dependencies on other modules, and which powershell hosts can run the module.

All that being said, if you are writing a binary module in C# or VB, you still use the same PSSnapin base class.

To get more information, check out

PS > help about_modules