I'm having problems understanding how I can work with output I create in a script.
The main cause is that for this example:
$Output = @()
$Output += New-Object psobject -Property @{FirstName="Harry";LastName="Potter";Age=11}
$Output += New-Object psobject -Property @{FirstName="Hermione";LastName="Granger";Age=11}
$Output += New-Object psobject -Property @{FirstName="Ron";LastName="Weasley";Age=11}
$Output += New-Object psobject -Property @{FirstName="Ginny";LastName="Weasley";Age=10}
$Output += New-Object psobject -Property @{FirstName="Albus";LastName="Dumbledore";Age=150}
$Output += New-Object psobject -Property @{FirstName="Severus";LastName="Snape";Age=40}
Write-Output $Output
I could take the table I've created, and pipe into a new scripts' parameter.
Say I'm creating a new script like this
Param(
[Parameter(ValueFromPipeline=$true,Mandatory=$true,Position=1)]
$in
)
Write-Output $in
The first script is a.ps1 and the second is named b.ps1 I want to prompt:
.\a.ps1 | .\b.ps1
And get the full table printed:
Age LastName FirstName
--- -------- ---------
11 Potter Harry
11 Granger Hermione
11 Weasley Ron
10 Weasley Ginny
150 Dumbledore Albus
40 Snape Severus
This is the output of the a.ps1 script, but if I'll pipe it to b.ps1 script, il recieve:
Age LastName FirstName
--- -------- ---------
40 Snape Severus
I know that I'm doing something wrong, but what I want basicly is functionality similar to:
Get-Service | Stop-Service
Where the Stop-Service is an independant command that can accept parameters, but could also accept piped output from a different command and work fine as well.