Add-NoteProperty.ps1

<#PSScriptInfo
 
.VERSION 1.0
 
.GUID 4dde74a9-25db-4ee0-b061-edff00069b56
 
.AUTHOR Mateusz Kortas
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
.PRIVATEDATA
 
.DESCRIPTION
 Adds new note property to each object in pipeline.
 
#>



function Add-NoteProperty([Parameter(mandatory=$true)][string]$name, [Parameter(mandatory=$true)][System.Management.Automation.ScriptBlock]$value, [Parameter(ValueFromPipeline = $true,mandatory=$true)]$object) {
<#
.SYNOPSIS
 
Adds new note property to each object in pipeline.
 
.DESCRIPTION
 
Adds new note property to each object in pipeline.
Takes property name and value expression.
 
.PARAMETER Name
Specifies property name.
 
.PARAMETER Value
Script block which evaluated should return property value.
Use $_ variable to refer to current object in pipeline.
 
.INPUTS
 
Object(s) which you want to add new property to.
 
.OUTPUTS
 
Object(s) with added property.
 
.EXAMPLE
 
PS> Get-ChildItem -file | Add-NoteProperty sizeInMB { $_.length / 1MB } | select Name, sizeInMB
Name sizeInMB
---- --------
file.txt 49,4375
#>

    process {
        $object | add-member noteProperty $name ($object | % $value) -passthru
    }
    
}

sal anp Add-NoteProperty