?
Solved

way to query the result set of invoke-sql?

Posted on 2013-12-26
3
Medium Priority
?
397 Views
Last Modified: 2013-12-30
I have  a result set from invoke-sql that I've modified so that I no longer need any record that has a field where $CSV.Path="IGNORE". I want to somehow filter this result set so that the records that contain Path="IGNORE" are not exported to a CSV file.
I was wondering if there was a way to invoke-sql on the modified $CSV or maybe a way to filter the ignored records from being exported? Any other ideas?
thanks!
I've tried .REMOVE and .DELETE, but it seems to error saying $CSV is a fixed object and somebody else told me $CSV is meant to be read-only even thought I can modified the data it returns.

#Read the SQL table
$CSV = Invoke-Sqlcmd -Query $Query
#modify the data and set $CSV.Path to "IGNORE" for obsolete records
...
#export the results to a CSV file
#Need some way to delete, or filter out, records set to be ignored.
$CSV | export-csv -path $sf -NoTypeInformation
0
Comment
Question by:johnj_01201
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Author Comment

by:johnj_01201
ID: 39740161
Powershell 3+

I was able to find a workaround on the following web page, but I would still like to do before or while exporting the file the first time.
The work around is to export the file with the field E3Path="IGNORE", use Import-CSV with a where-object, and then export-csv to save the results again.
$CSV | export-csv -path $sf -NoTypeInformation
$tempC = Import-csv -path $sf | Where-Object {$_.E3Path -ne 'IGNORE'}
$tempC | export-csv -path $sf -NoTypeInformation


http://www.powershellmagazine.com/2012/12/04/skipping-empty-csv-objects/

COOL! Now I can programmatically delete records that I flag from invoke-sql results!!!
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 39745333
Doesn't this work?
$CSV | ? { $_.E3Path -ne 'IGNORE' } |  export-csv -path $sf -NoType

Open in new window

BTW - path or E3Path ?
0
 
LVL 1

Author Closing Comment

by:johnj_01201
ID: 39746195
Perfect! Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question