Powershell apply verbosity at a global level

末鹿安然 提交于 2019-12-09 05:55:11

问题


Imagine if you have a script containing a single line of code like

ni -type file foobar.txt

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.


回答1:


Use $PSDefaultParameterValues:

$PSDefaultParameterValues['New-Item:Verbose'] = $true

Set that in the Global scope, and then the default value of -Verbose for the New-Item cmdlet will be $True.

You can use wildcards for the cmdletsyou want to affect:

$PSDefaultParameterValues['New-*:Verbose'] = $true

Will set it for all New-* cmdlets.

$PSDefaultParameterValues['*:Verbose'] = $true

will set it for all cmdlets.



来源:https://stackoverflow.com/questions/28763707/powershell-apply-verbosity-at-a-global-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!