小编use*_*801的帖子

我列出要在我的powershell模块清单中导出的变量实际上并不是导出的

我正在创建一个脚本模块并使用清单来导出脚本成员并设置其他模块属性.我已经跟踪了我发现的每个示例清单,甚至使用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)

variables powershell module export manifest

7
推荐指数
1
解决办法
2544
查看次数

标签 统计

export ×1

manifest ×1

module ×1

powershell ×1

variables ×1