2014-04-10 2 views
0

진단을 위해 스크립트에서받은 모든 매개 변수 (이름/값)를 인쇄하고 싶습니다. 그러나 나는 하나씩 지명하고 싶지 않습니다 - 그것은 너무 지루하고 유지 보수를 복잡하게 만듭니다. 매개 변수 목록을 반복하고 값을 인쇄하는 방법이 있습니까?각 매개 변수 이름과 해당 값을 인쇄하십시오.

답변

4

자동 변수 $ PSBoundParamters가 제공해야합니다. GET-도움말에서

$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 
    } 
+0

$ PARAMS = $ PSBoundParameters 의 foreach ($ params.GetEnumerator에서 $ 키 값()) { \t 로그 "$ ($ keyValue.Key) = $를 (은 about_Automatic_Variables $ 키 값 .Value) " } – gsb

관련 문제