I can define that function in 1 step

If you are like me, you’re starting to develop a lot of aliases and custom functions. The thing is, I can’t always remember what every function or alias does. Fortunately, that is pretty easy to discover.For example, I have an alias called du

CommandType Name Definition
———– —- ———-
Alias       du Get-DiskUsage

But what did I create for Get-DiskUsage? Piping the Get-Alias command through Get-Member gives me this:
PS S:\ > get-alias du|gm
   TypeName: System.Management.Automation.AliasInfo

Name                  MemberType     Definition
—-                  ———-     ———-
Equals                Method         System.Boolean Equals(Object obj)
GetHashCode           Method         System.Int32 GetHashCode()
GetType               Method         System.Type GetType()
get_CommandType       Method         System.Management.Automation.CommandTyp..
get_Definition        Method         System.String get_Definition()
get_Description       Method         System.String get_Description()
get_Name              Method         System.String get_Name()
get_Options           Method         System.Management.Automation.ScopedItem..
get_ReferencedCommand Method         System.Management.Automation.CommandInf..
get_ResolvedCommand   Method         System.Management.Automation.CommandInf..
set_Description       Method         System.Void set_Description(String value)
set_Options           Method         System.Void set_Options(ScopedItemOptio..
ToString              Method         System.String ToString()
CommandType           Property       System.Management.Automation.CommandTyp..
Definition            Property       System.String Definition {get;}
Description           Property       System.String Description {get;set;}
Name                  Property       System.String Name {get;}
Options               Property       System.Management.Automation.ScopedItem..
ReferencedCommand     Property       System.Management.Automation.CommandInf..
ResolvedCommand       Property       System.Management.Automation.CommandInf..
ResolvedCommandName   ScriptProperty System.Object ResolvedCommandName {get=..

 Ahhhh. I think Resolvedcommand might get me what I need. So I try this:

PS S:\ > (get-alias du).ResolvedCommand
CommandType Name          Definition
———– —-          ———-
Function    Get-DiskUsage param( [string]$computer = “…

Yes. I can see the definition but it is trunctated. Easily fixed with a little formatting. (code formatting in the blog leaves a little to be desired but you get the idea.)

PS S:\ > (get-alias du).ResolvedCommand |format-list

Name : Get-DiskUsage
CommandType : Function
Definition : param( [string]$computer = “.” , [switch]$all) $size = @{ l = “Size (MB)”; e = { $_.size/1mb}; f = “{0:N}”}
 $free = @{ l = “free (MB)”; e = { $_.freespace/1mb}; f = “{0:N}”}$perc = @{ l = “percent”; e = { 100.0 * ([double]$_.freespace/[double]$_.size)}; f=”{0:f}” }$name = @{ e = “name”; f = “{0,-20}” }
$fields = $name,$size,$free,$perc

# in case the user wants to see more than just local drives$filter = “DriveType = ‘3’”if ( $all ) { $filter = “” }

# go do the work by getting the information from the appropriate
# computer, and send it to format-table with the appropriate# fields and formatting infoget-wmiobject -class win32_logicaldisk -filter $filter -comp $computer |format-table $fields -auto

If I only want to see the definition I can use an expression like this:
(get-alias du).ResolvedCommand.Definition

Now I can see the full function definition. Now that I know the shortcut, I can try it out on another alias:

PS S:\ > (get-alias fs).resolvedcommand.definitionparam([string]$Computer) $results=Get-WmiObject -class win32_logicaldisk -computername $Computer| `where {$_.drivetype -eq 3} | select DeviceID,VolumeName,Size,FreeSpace

foreach ($drive in $results) {$obj = New-Object System.Object$sz=”{0:N2}” -f (($drive.Size)/1MB)$fs=”{0:N2}” -f (($drive.Freespace)/1MB)

Add-Member -inputobject $obj -membertype NoteProperty -Name DeviceID -value$drive.DeviceID
Add-Member -inputobject $obj -membertype NoteProperty -Name VolumeName -value $drive.VolumeName
Add-Member -inputobject $obj -membertype NoteProperty -Name SizeMB -value $sz
Add-Member -inputobject $obj -membertype NoteProperty -Name FreespaceMB -value $fsWrite-Output $obj}

Terrific. Now with a single line I can get complete alias definition.