Powershell 在全球范围内应用冗长 [英] Powershell apply verbosity at a global level
问题描述
想象一下,如果你有一个包含一行代码的脚本,比如
Imagine if you have a script containing a single line of code like
ni -type file foobar.txt
-verbose 标志未提供给 ni 命令.如果我要运行此脚本以强制详细程度,是否可以在全局 PSSession 级别设置详细程度?我问的原因是我有一组大约 60 个相互依赖的脚本,这些脚本都没有对它们发出的任何命令提供详细信息,我希望在调用主入口点 powershell 脚本时查看整个输出.
where the -verbose flag is not supplied to the ni command. Is there a way to set the Verbosity at a global PSSession level if I were to run this script to force verbosity? The reason I ask is that I have a group of about 60 scripts which are interdependent and none of these supply -verbose to any commands they issue and I'd like to see the entire output when I call the main entry point powershell script.
推荐答案
Use $PSDefaultParameterValues
:
$PSDefaultParameterValues['New-Item:Verbose'] = $true
在全局范围内设置它,然后 New-Item cmdlet 的 -Verbose 的默认值将为 $True.
Set that in the Global scope, and then the default value of -Verbose for the New-Item cmdlet will be $True.
您可以对要影响的 cmdlet 使用通配符:
You can use wildcards for the cmdletsyou want to affect:
$PSDefaultParameterValues['New-*:Verbose'] = $true
将为所有 New-* cmdlet 设置它.
Will set it for all New-* cmdlets.
$PSDefaultParameterValues['*:Verbose'] = $true
将为所有 cmdlet 设置它.
will set it for all cmdlets.
这篇关于Powershell 在全球范围内应用冗长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!