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?
Add-PSSnapin adds the snap-in only to the current session. To add the snap-in to all Windows PowerShell sessions, add it to your Windows PowerShell profile. For more information, see about_Profiles. You can add any snap-in that has been registered using the Microsoft . NET Framework install utility.
Description. The Get-PSSnapin cmdlet gets the Windows PowerShell snap-ins that have been added to the current session or that have been registered on the system. This cmdlet lists the snap-ins in the order in which they are detected. Get-PSSnapin gets only registered snap-ins.
Description. The Import-Module cmdlet adds one or more modules to the current session. Starting in PowerShell 3.0, installed modules are automatically imported to the session when you use any commands or providers in the module. However, you can still use the Import-Module command to import a module.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With