Solved

way to query the result set of invoke-sql?

Posted on 2013-12-26
3
388 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
  • 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 69

Accepted Solution

by:
Qlemo earned 500 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now