I am using powershell 5. I created an enum in different ps1 file and I like to load it in another ps1 that has CmdletBinding.
I tried the code below but didn't work. Is there any way to load the enum ps1 before the CmdletBinding?
. ".\GeneratorType.ps1"
[CmdletBinding()]
Param
(
[Parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName = $True,Mandatory=$False)]
[GeneratorType]$type = [GeneratorType]::All
)
Think of it like this: A PowerShell script is a self-contained ScriptBlock.
The [CmdletBinding()] attribute is part of the param-block. According to the language specification, a param-block must be the first part of the ScriptBlock if present.
So no, you cannot put anything before the CmdletBinding attribute.
What you can do, is to convert your GeneratorTypes.ps1 script to a module and use
#Requires -Modules
to make sure it's loaded when the param block is interpreted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With