0
点赞
收藏
分享

微信扫一扫

powershell_查看powershell函数源代码(环境变量/别名)/将函数作为参数

查看powershell源代码

reference

  • 魔法accelerate​​Viewing PowerShell Function Contents | PDQ.com​​
  • ​​Types - PowerShell | Microsoft Docs​​
  • ​​powershell - Pass function as a parameter - Stack Overflow​​

通用方案

function showSrcCode
{
param(
[parameter(Mandatory = $true)]
# [scriptblock] $command
$command
)
Get-Command $command | Select-Object -ExpandProperty ScriptBlock
}

调用示例

PS C:\Users\cxxu> showSrcCode -command newjunction

param(
$Path,
$Target
)
sudo New-Item -Verbose -ItemType junction -Path $Path -Target $Target

对于某个函数

​$function:<functionName>​

$function: 调用示例

PS C:\Users\cxxu> $Function:newJunction

param(
$Path,
$Target
)
sudo New-Item -Verbose -ItemType junction -Path $Path -Target $Target

环境变量

​$env:<environmentName>​

别名

​$alias:<AliasName>​


举报

相关推荐

数组作为函数参数

0 条评论