我正在创建一个脚本模块并使用清单来导出脚本成员并设置其他模块属性.我已经跟踪了我发现的每个示例清单,甚至使用New-ModuleManifest来创建具有我想要的属性的基线清单,我仍然无法获得我想要导出到实际导出的变量.
这里的目的是在清单中执行所有声明,而不必Export-ModuleMember在模块脚本中使用.
这是脚本模块:
#
# Widget.psm1
#
[System.Random]$rGen = New-Object System.Random;
[string]$WidgetBaseName = $null;
[string]$WidgetColor = "Blue";
function Get-WidgetName
{
param
(
[Parameter(Mandatory=$true)]
[string]$widgetName,
[switch]$appendRandomNumber
)
if (![string]::IsNullOrEmpty($WidgetBaseName))
{
$widgetName = $WidgetBaseName + $widgetName;
}
if ($appendRandomNumber)
{
return [string]::Format("{0}{1:D4}", $widgetName, $rGen.Next(10000));
}
else
{
return $widgetName;
}
}
function Get-WidgetBlessing()
{
return [string]::Format("A thousand blessings upon your {0} widget!", $WidgetColor);
}
Run Code Online (Sandbox Code Playgroud)
这是显而易见的:
#
# Widget.psd1
#
@{
# Script module or binary module file associated with this …Run Code Online (Sandbox Code Playgroud)