2 Responses

  1. LucD
    LucD at |

    Nice post about a very useful feature!

    Another use case of the Alias attribute, is to “rename” property names when getting pipeline input into a function.

    The following snippet shows how you can go with the $Cores variable in your function, while the object you receive has a CoresPerSocket property.

    function Show-UseCase{
    [CmdletBinding()]
    Param(
    [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName)]
    [string]$Name,
    [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName)]
    [Alias(‘CoresPerSocket’)]
    [int]$Cores
    )

    Process{
    Write-Host “VM $($Name) has a $($Cores) core(s) CPU”
    }
    }

    Get-VM | Show-UseCase

    Reply
  2. The Snazzy Secret of PowerShell Parameter Aliases - How to Code .NET

    […] on July 12, 2017 submitted by /u/Net-Runner [link] [comments] Leave a […]

Share your point of view!