Load-Module equivalient in PowerShell v1
For reasons of script portability, I need to dynamically load snap-ins in a PowerShell script. This is easily accomplished in PowerShell v2 with the Load-Module
function. I need to run this particular script on a machine where I, for various reasons, do not want to install PowerShell v2, but hav开发者_C百科e v1.
Is there a Load-Module
equivalent in PowerShell v1?
Do you mean Import-Module
? If so, then it depends on how the module is defined. If it is a snapin DLL, then the snapin would need to be installed on the V1 machine and then you would use Add-PSSnapin
. If it is in .psm1
file, then you would need to rename the file to .ps1
and then you could try to dot source it e.g. . .\mymodule.ps1
. However if it uses any v2 feature like Export-ModuleMember, you will need to comment those out. And v1 wouldn't know what to do with a .psd1
file.
Import-Module
loads modules, and modules are a V2 only feature.
PowerShell V1 had "Snap-ins", written in a .NET language (C#, VB, ...) but not PowerShell script and loaded into a session with Add-PSSnapin
(snap-ins are also supported in V2, but modules have a superset of snap-in capabilities so stick with modules unless it is impossible to upgrade to V2).
精彩评论