Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 561
Justin R. Avatar asked Feb 18 '11 07:02

Justin R.


People also ask

What is ADD-PSSnapin?

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.

What is get PSSnapin?

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.

What is import module in PowerShell?

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.


1 Answers

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 
like image 127
Andy Schneider Avatar answered Sep 28 '22 01:09

Andy Schneider