Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 有可能有辅助模块吗?_Powershell_Powershell 3.0_Powershell Module - Fatal编程技术网

Powershell 有可能有辅助模块吗?

Powershell 有可能有辅助模块吗?,powershell,powershell-3.0,powershell-module,Powershell,Powershell 3.0,Powershell Module,我在PowerShell中拥有许多高级功能,这些功能处理版本号,这是配置模块的核心部分 当用户导入配置模块时,这些功能应该对他们可用。我可以将所有功能复制到配置模块,但是如果它像helper模块一样保留,那么组织起来会非常好 最终用户应仅导入主配置模块,但该辅助模块应包含在该模块中。有没有办法实现这一点?您可以通过创建另一个PS模块路径并将它们放置在那里,使它们都可以作为cmdlet使用-这将在每个PS会话中对所有用户都可用。他们所要做的就是导入模块,所有功能都将可用 在模块内部,您可以在其中包

我在PowerShell中拥有许多高级功能,这些功能处理版本号,这是配置模块的核心部分

当用户导入配置模块时,这些功能应该对他们可用。我可以将所有功能复制到配置模块,但是如果它像helper模块一样保留,那么组织起来会非常好


最终用户应仅导入主配置模块,但该辅助模块应包含在该模块中。有没有办法实现这一点?

您可以通过创建另一个PS模块路径并将它们放置在那里,使它们都可以作为cmdlet使用-这将在每个PS会话中对所有用户都可用。他们所要做的就是导入模块,所有功能都将可用

在模块内部,您可以在其中包含与.psm1文件名相同的文件夹,例如
Modules/Configuration/Configuration.psm1
&
Modules/Helper/Helper.psm1

if (!(Test-Path $Profile.AllUsersAllHosts)) {
  $profile_new1 = New-Item -Type File -Path $Profile.AllUsersAllHosts -Force
  Add-Content $profile_new1 '$env:PSModulePath = $env:PSModulePath + ";C:\Temp\Modules"'
} else {
  $profile_exist = Get-Item $Profile.AllUsersAllHosts
  Add-Content $profile_exist '$env:PSModulePath = $env:PSModulePath + ";C:\Temp\Modules"'
}

您可以将助手模块指定为数据库中的“嵌套模块”

@{
ModuleToProcess='Configuration.psm1'
ModuleVersion='1.0'
GUID='7ec463d6-de22-40bb-a505-1efcb3b22b73'
作者='Ansgar Wiechers'
Description='配置模块'
PowerShellVersion='2.0'
FunctionsToExport='*'
CmdletsToExport='*'
VariablesToExport='*'
AliasesToExport='*'
NestedModules='Helper'
}
助手模块实际上不必嵌套。您可以将两个模块作为单个模块放置:

WindowsPowerShell
`-模块
+-配置
|+-Configuration.psd1
|`-Configuration.psm1
`-助手
+-Helper.psd1
`-Helper.psm1

您可以创建某种链接,即当导入主模块时,主模块内的代码将以静默方式导入辅助模块。