Last active
July 7, 2024 00:08
-
-
Save indented-automation/3bc6418afb184c1d6153c3fa76d6ebdc to your computer and use it in GitHub Desktop.
View the source for a command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-CommandSource { | |
param ( | |
[Parameter(Mandatory)] | |
[String]$Name | |
) | |
try { | |
$commandInfo = Get-Command $Name | |
if ($commandInfo -is [System.Management.Automation.AliasInfo]) { | |
$commandInfo = $commandInfo.ResolvedCommand | |
} | |
if ($commandInfo -is [System.Management.Automation.CmdletInfo]) { | |
$assembly = $commandInfo.ImplementingType.Assembly.Location | |
$type = $commandInfo.ImplementingType.FullName | |
if (Get-Command dnspy -ErrorAction SilentlyContinue) { | |
dnspy $assembly --select T:$type | |
} elseif (Get-Command ilspy -ErrorAction SilentlyContinue) { | |
ilspy $assembly /navigateTo:T:$type | |
} else { | |
throw 'No decompiler present' | |
} | |
} else { | |
$commandInfo.Definition | |
} | |
} catch { | |
$pscmdlet.ThrowTerminatingError($_) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment