using module ...
您可以在使用命令加载模块后访问枚举。
例如:
我的模块.psm1
enum MyPriority {
Low = 0
Medium = 1
high = 2
}
function Set-Priority {
param(
[Parameter(HelpMessage = 'Priority')] [MyPriority] $priority
)
Write-Host $Priority
}
Export-ModuleMember -function Set-Priority
制作:
New-ModuleManifest MyModule.psd1 -RootModule 'MyModule.psm1' -FunctionsToExport '*'
然后在Powershell中...
Import-Module .\MyModule\MyModule.psd1
PS C:\Scripts\MyModule> [MyPriority] $p = [MyPriority ]::High
Unable to find type [MyPriority].
At line:1 char:1
+ [MyPriority] $p = [MyPriority ]::High
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (MyPriority:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
PS C:\Scripts\MyModule> using module .\MyModule.psd1
PS C:\Scripts\MyModule> [MyPriority] $p = [MyPriority ]::High
PS C:\Scripts\MyModule> $p
high