【发布时间】:2019-01-11 00:37:54
【问题描述】:
我在模块中定义了一个枚举类型。加载模块后,如何将其导出为可从外部访问?
enum fruits {
apple
pie
}
function new-fruit {
Param(
[fruits]$myfruit
)
write-host $myfruit
}
我的高级函数采用枚举而不是 ValidateSet,如果枚举可用,它会起作用,但如果它不可用,则会失败。
更新: 将其分离为 ps1 并对其进行点源 (ScriptsToProcess) 是可行的,但我希望有一种更清洁的方法。
【问题讨论】:
-
见how to export a class in powershell v5 module - 导入后添加
using module moduleName -
@wOxxOm
The using module command imports the module and also loads the class definitionsdocs.microsoft.com/en-us/powershell/module/…
标签: powershell enums powershell-5.0 powershell-cmdlet powershell-module