Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Add-PSSnapin and Import-Module in PowerShell? [duplicate]

Possible Duplicate:
What’s the difference between Add-PsSnapIn and Import-Module

What is the difference between Add-PSSnapin and Import-Module in PowerShell?

At the end, both seem like they provide the same result.

Which one is the recommended approach?

like image 665
Samselvaprabu Avatar asked Jun 07 '12 05:06

Samselvaprabu


People also ask

What is ADD-PSSnapin?

Description. The Add-PSSnapin cmdlet adds registered Windows PowerShell snap-ins to the current session. After the snap-ins are added, you can use the cmdlets and providers that the snap-ins support in the current session.

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

PsSnapins are the old fashion way (existing inPowerShell V1) to add CmdLet or Providers (but still in use)

  • They need to be registered (with installutil.exe tool)
  • They are assemblies written in one of the .NET language

Modules are the new way (added in PowerShel V2) to add CmdLet or Providers

  • They just have to be joinable on the file system (see $env:psmodulepath)
  • They may be scripts written in PowerShell (for CmdLet only) or assemblies for CmdLet and Providers written with one of the .NET language
  • It exists a manifest form that allow to specify much information about the creator, but also the dependancies on PowerShell versions, Framework version or other modules or assemblies version.

    I think that you can use module unless you have to support existing PowerShell V1 computers.

like image 119
JPBlanc Avatar answered Nov 15 '22 01:11

JPBlanc