Quantcast
Channel: PowerShell: Import-Module or Add-Type for .NET assemblies? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

PowerShell: Import-Module or Add-Type for .NET assemblies?

$
0
0

I'm using PowerShell 5.1, Windows 10 x64.

Which of these 2 cmdlets should I use to load .NET assemblies (in particular .NET Framework 4+ assemblies) into PowerShell? What's the core difference between them? I want to load assemblies for accessing types, creating objects, calling methods, etc.

I haven't found any explicit statements in the documentation. These cmdlets are described like they are completely different things. MSDN documentation for Import-Module doesn't even contain examples for .dll assemblies loading -- only PowerShell modules. However Import-Module works with .NET Framework assemblies (.dll only, though): I can perfectly work with types from the imported assemblies, their referenced assemblies are resolved and loaded too. Why is that?

In other words, from my experience I haven't yet found any differences between these 2 assemblies importing methods (at least for .NET Framework 4 .dll assemblies).

This old blog post: Using .NET Framework Assemblies in Windows PowerShell even uses Reflection.Assembly.LoadWithPartialName! I believe this is because they load an assembly from the GAC and do not want to specify full path to it (I may be wrong, though).

For my assemblies I know full path to them, so I can specify it in both Import-Module and Add-Type. Again, what's the difference and what should I use?

Thanks!


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images