I have a PowerShell function (out()
). When I want to get a result from pipeline into an image
, it takes the last object from the pipeline. For example: I want to show all objects in (gps
):
function out {
[cmdletbinding()]
param(
[parameter(
Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[string[]]
$n
)
Process {
$dirname = Get-Location | Select-Object -ExpandProperty Path
$filename = $(Get-Date -f "yyyy-mm-dd--hh-mm-ss-tt") + "--image.png"
$ImagePath = $dirname + "\" + $filename
ForEach ($input in $n) {
#PUT Your Image:
$basefilename = "D:\ZalansDB\imgs\main\bg_D.jpg"
$bmp = [System.Drawing.Bitmap]::FromFile("$basefilename")
$font = new-object System.Drawing.Font ('Microsoft Sans Serif',16)
$fcolors = [System.Drawing.Brushes]
$graphics = [System.Drawing.Graphics]::FromImage($bmp)
$graphics.DrawString($input,$font,$fcolors::White,30,40)
$filename = $ImagePath
$graphics.Dispose()
$bmp.Save($filename)
}
Invoke-Item $filename
}
}
Get-Process | Select-Object -First 2 | out
Result:
I want to show First 2 prcoess objects into my image