0
我想打印出我的腳本收到的所有參數(名稱/值),用於診斷目的。但我不想一一列舉 - 這太無聊了,維護也變得複雜了。有沒有辦法迭代params列表並打印它們的值?打印每個參數名稱及其值
我想打印出我的腳本收到的所有參數(名稱/值),用於診斷目的。但我不想一一列舉 - 這太無聊了,維護也變得複雜了。有沒有辦法迭代params列表並打印它們的值?打印每個參數名稱及其值
自動變量$ PSBoundParamters應該給你。
從獲取幫助參閱about_Automatic_Variables
$PSBoundParameters
Contains a dictionary of the parameters that are passed to a script
or function and their current values. This variable has a value only
in a scope where parameters are declared, such as a script or function.
You can use it to display or change the current values of parameters
or to pass parameter values to another script or function.
For example:
function Test {
param($a, $b)
# Display the parameters in dictionary format.
$PSBoundParameters
# Call the Test1 function with $a and $b.
test1 @PSBoundParameters
}
$ PARAMS = $ PSBoundParameters 的foreach($的keyValue在$ params.GetEnumerator()){ \t日誌「$($ keyValue.Key)= $($的keyValue .Value)「 } – gsb