您是否知道如何从cmdlet中查找调用cmdlet的别名?我试过这个,但它不起作用:
Function Write-Verbose {
[CmdletBinding()]
param($val)
$CommandName = $Test.MyInvocation.line -replace '(^.+? ).*','$1'
Write-host "$val Called with '$CommandName' alias"
}
Set-Alias WB Write-Verbose -Scope global
WB "goodbye"
答案 0 :(得分:0)
您可以从$MyInvocation.InvocatioName
Function Write-Verbose {
[CmdletBinding()]
param($val)
Write-host "$val Called with $($MyInvocation.InvocationName) alias"
}
Set-Alias WB Write-Verbose -Scope global
WB "goodbye"
返回:
再见与WB别名一起调用