From Drafts post Feb 2019. Published April '25
So I have the following code:
function Send-ToITGlue {
[CmdletBinding()]
param (
# Data Object to Send to ITglue
[Parameter(ValueFromPipeline)]
[object[]]
$Data
)
begin {
$api__output_data = @()
}
process {
$traits = $Data.attributes.traits
$dhcpScopeName = $traits.'dhcp-scope-name'
$dhcpServer = $traits.'dhcp-server'
$id = [long]( Find-ITGlueRecord $dhcpScopeName $dhcpServer )
Write-Host "ID $id"
if ( $id -gt 0 ) {
Write-Host "Updating scope $dhcpScopeName"
$api__output_data += (Set-ITGlueFlexibleAssets -id $id -data $_)
} else {
Write-Host "Adding scope $dhcpScopeName"
$api__output_data += (New-ITGlueFlexibleAssets -data $_)
}
}
end {
Write-Host "End"
$api__output_data
}
}
In the above code I am taking -Data as input from the pipeline in Powershell meaning that the data is passed via a previous command
Format-NetshOutput | Send-ToITGlue
But what I have discovered is that when you send something from the piple line and then use the input variable in the pipeline. You are actually using the whole object but each time it goes through the loop
0 Comments