Default value of parameter is not used in function

后端 未结 4 1223
孤城傲影
孤城傲影 2021-01-01 07:46

I have a very basic PowerShell script:

Param(
    [string]$MyWord
)

function myfunc([string] $MyWord) {
    Write-Host \"$MyWord\"
}
myfunc @PSBoundParamete         


        
4条回答
  •  情书的邮戳
    2021-01-01 08:39

    If you want to use "Param" enclose it in the function like this:

    function myfunc {
    
        Param(
            [string]$MyWord='hi'
        )
    
        Write-Host "$MyWord" 
    }
    

提交回复
热议问题