Skip to content

Instantly share code, notes, and snippets.

@indented-automation
Last active July 7, 2024 00:08
Show Gist options
  • Save indented-automation/3bc6418afb184c1d6153c3fa76d6ebdc to your computer and use it in GitHub Desktop.
Save indented-automation/3bc6418afb184c1d6153c3fa76d6ebdc to your computer and use it in GitHub Desktop.
View the source for a command
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