In a Cmdlet, how can I detect if the Debug flag is set?

前端 未结 4 455
暗喜
暗喜 2020-12-19 13:09

I\'m writing a PowerShell Cmdlet and using WriteDebug, but I want to write an object which requires an extra API call, and I\'d rather not make that call when debugging is t

4条回答
  •  长情又很酷
    2020-12-19 13:40

    Try this:

    $Debug = $psboundparameters.debug.ispresent
    
    
    if ($Debug){
      Write-Debug(string.Format("Name : {0}", api.GetName(myobj))
      }
    

提交回复
热议问题