Avatar of sirbounty
sirbountyFlag for United States of America asked on

powershell pipeline

I have a script that combines some data and creates an output object on each pass through the results.
I'm attempting to utilize some of the functionality from this out-sql script: http://blogs.technet.com/b/sqlthoughts/archive/2008/10/03/out-sql-powershell-function-export-pipeline-to-a-new-sql-server-table.aspx

But, it's failing.

In my script, I have a function, Get-Logs, that produces output in the following format:
foreach ($item in $datacollection){ 
            $obj = new-object psobject
            $obj | Add-Member NoteProperty EntryDate $item.startdate
            $obj | Add-Member NoteProperty Username $item.User
           #...etc, etc...
            write-output $obj

Open in new window


I call this function piping it to the out-sql function:
get-logs | out-sql

That results in
out-sql : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and
its properties do not match any of the parameters that take pipeline input.

I've event attempted a simple out-test function that attempts to create the $properties variable.  If I step into this function, $_ and $properties are both empty...  What am I missing?
function out-test {
  $properties = $_.psobject.properties
}

Open in new window

PowershellShell Scripting

Avatar of undefined
Last Comment
sirbounty

8/22/2022 - Mon
Raheman M. Abdul

What if you have tried the examples from that site link? Is that still the same error?

If you understand this, you get to know whats wrong in your code:
You might be not producing the input what the out-sql is waiting to accept from your code:

http://richardspowershellblog.wordpress.com/2011/06/01/powershell-basics-4-pipeline/
ASKER
sirbounty

the examples aren't quite applicable since I've modified the code somewhat.
Yet, as I said, even creating a test function to pipe the data to fails...
How can I ensure the function accepts the correct type of input?
ASKER CERTIFIED SOLUTION
sirbounty

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
sirbounty

Solved myself.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck