• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

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

  • 3
1 Solution
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
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:

sirbountyAuthor Commented:
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?
sirbountyAuthor Commented:
I was able to get this to work by placing the properties declaration within the Process block...
sirbountyAuthor Commented:
Solved myself.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

WEBINAR: GDPR Implemented - Tips & Lessons Learned

Join the WatchGuard team on Thursday, March 29th as we recount some valuable lessons learned in weighing the needs of a business against the new regulatory environment, look ahead at the two months left before implementation, and help you understand the steps you can take today!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now