Powershell applies verbosity globally

Imagine you have a script containing one line of code, for example

ni -type file foobar.txt 

where the -verbose flag is not provided to the ni command. Is there a way to install Verbosity at the global PSSession level if I have to run this script to force verbosity? The reason I ask is because I have a group of about 60 scenarios that are interdependent, and none of these supplies can be used for any commands that they issue, and I would like to see the whole output. when I call the main powershell script access point.

+5
source share
1 answer

Use $PSDefaultParameterValues :

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

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

You can use wildcards for cmdlets that you want to influence:

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

Installs it for all New- * cmdlets.

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

install it for all cmdlets.

+5
source

Source: https://habr.com/ru/post/1214321/


All Articles