Powershell功能的默认参数不起作用

时间:2016-12-07 15:15:30

标签: powershell

我在我创建的模块中有一个功能:

   function New-MyAppDeployment {
   param
   (
        [string]$ConfigPath = "C:\Projects\MyApp\Environments",
        [string]$EnvName,
        [string]$EnvironmentFile
   )
   # Do some things with the above parameters
   if(!$EnvironmentFile)
   {
       $envFilename = $EnvName + ".json";
       $EnvironmentFile = Join-Path $ConfigPath $envFilename

   }

   $settings = Get-Content -Raw -Path $EnvironmentFile | ConvertFrom-Json

   return $settings    
   }
   Export-ModuleMember -function New-MyAppDeployment

然后我这样称呼它:     Import-Module -Force $ PSScriptRoot \ myapp.psm1        $ newSettings = New-MyAppDeployment -EnvName" dev"

但是当我在函数内部时,$ConfigPath总是设置为空字符串。

任何可能导致此问题的想法?

1 个答案:

答案 0 :(得分:0)

似乎已经纠正了自己。也许重新启动ISE可以解决问题,但现在$ConfigPath在单步执行代码时具有正确的值。

相关问题