PoshCode Archive  Artifact [1a7d471e2b]

Artifact 1a7d471e2b44051b883910c7ae148fa10853ef707e3d636b9549103328d2192e:

  • File Invoke-ScriptBlock.ps1 — part of check-in [b0abba9373] at 2018-06-10 13:06:39 on branch trunk — From Windows PowerShell Cookbook (O’Reilly) by Lee Holmes (user: Lee Holmes size: 1038)

# encoding: ascii
# api: powershell
# title: Invoke-ScriptBlock.ps1
# description: From Windows PowerShell Cookbook (O’Reilly) by Lee Holmes
# version: 0.1
# type: script
# author: Lee Holmes
# license: CC0
# x-poshcode-id: 2185
# x-archived: 2016-05-17T10:50:10
# x-published: 2011-09-09T21:41:00
#
#
##############################################################################
##
## Invoke-ScriptBlock
##
## From Windows PowerShell, The Definitive Guide (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
##############################################################################

<#

.SYNOPSIS

Apply the given mapping command to each element of the input. (Note that
PowerShell includes this command natively, and calls it Foreach-Object)

.EXAMPLE

1,2,3 | Invoke-ScriptBlock { $_ * 2 }

#>

param(
    ## The scriptblock to apply to each incoming element
    [ScriptBlock] $MapCommand
)

begin
{
    Set-StrictMode -Version Latest
}
process
{
    & $mapCommand
}