I am trying to build a script, that accepts named arguments - but the script also has functions in it... This gives me a problem, that I cannot see how to fix. The script - c:\temp\example.ps1 - looks like:
function test
{
param($p1)
write-host $p1
}
param(
[parameter(mandatory=$false)]
[switch]$EnableOption,
[parameter(mandatory=$false)]
[string]$Hostname
)
test -p1 $Hostname
This gives me:
param : The term 'param' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Temp\example.ps1:7 char:1
+ param(
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (param:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
How do I fix this - so that named parameters can be used for functions - but also be used in the "main" script (getting the command line arguments when calling the script) ?