
Powershell에서 다음과 같이 동적 함수를 정의했습니다.
> function test { dir -r -fil *.vbproj | ft directory, name }
test
그런 다음 해당 함수를 입력하고 실행하여 다른 명령으로 파이프하는 등의 작업을 수행 할 수 있습니다 . 매우 편리합니다.
명령의 정의를 얻을 수 있는 방법이 있나요? 내 함수에 대한 코드를 에코아웃할 수 있나요 test
? (내 역사를 내가 정의한 곳으로 되돌아갈 필요 없이?)
답변1
다음과 같은 함수의 경우 test
:
$function:test
또는 함수 이름에 하이픈(예: test-function
)이 포함된 경우:
${function:test-function}
또는:
(Get-Command test).Definition
답변2
(Get-Command Test).Definition
그것이 내가 일반적으로 정의를 얻는 방법입니다.
답변3
이 두 가지 접근 방식 모두 로컬 ${function:myFn}
로 (Get-Command myFn).Definition
생성된 함수에만 작동합니다.
Get-EventLog
(예) 와 같은 기본 함수의 정의도 볼 수 있습니다 . 와 더불어CommandMetadata
그리고ProxyCommand
의 명령System.Management.Automation
네임스페이스는 다음과 같습니다.
using namespace System.Management.Automation
$cmd = Get-Command Get-EventLog
$meta = New-Object CommandMetadata($cmd)
$src = [ProxyCommand]::Create($meta)
$src | Write-Output