Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何提及powershell中所有函数调用的详细信息?_Powershell_Powershell 3.0 - Fatal编程技术网

如何提及powershell中所有函数调用的详细信息?

如何提及powershell中所有函数调用的详细信息?,powershell,powershell-3.0,Powershell,Powershell 3.0,我在一个模块中编写了许多powershell函数。 每个函数都有写详细信息 例如: function fun1{ # code Write-verbose "Useful information from fun1" } function fun2{ # code Write-verbose "Useful information from fun2" } 现在,当我使用函数时,我必须提到每个函数调用的详细信息 fun1 -params <paramvalue>

我在一个模块中编写了许多powershell函数。 每个函数都有写详细信息

例如:

function fun1{
  # code
  Write-verbose "Useful information from fun1"
}

function fun2{
  # code
  Write-verbose "Useful information from fun2"
}
现在,当我使用函数时,我必须提到每个函数调用的详细信息

fun1 -params <paramvalue> -verbose
fun2 -params <paramvalue> -verbose

是否有任何方法可以全局提及所有函数的详细信息?因此,我不必为每个函数都提到冗长。

正确的答案是添加

$VerbosePreference = 'Continue'
在代码之前,并将其设置回

$VerbosePreference = 'SilentlyContinue'
后来


但是,如果此信息是您默认需要的信息,您可能只想将其更改为写入主机或写入输出

另一种可能是添加-Verbose on write Verbose:


这样做并不会让调用者选择不查看信息,但会转到详细流,而不会转到标准输出或主机,因此如果这是您想要的,那么这可能会很有用。

要扩展其他两个答案,如果您希望它们默认为您的详细流,而不是其他的详细流,您只需在配置文件中使用$PSDefaultParameterValues[Myfunction2:verbose]=$true即可

。if-not$PSBoundParameters.ContainsKey'Verbose'。。。将解决此问题,但需要修改您的功能。
Write-verbose "Useful information from fun1" -Verbose