none
PowerShell write to a CSV like Database? RRS feed

  • Question

  • Hi,

    Is there a simple way using PowerShell writing to a CVS like Database (a human readable – best would be csv).

    It just has to be a simple Table like

    Date, Topic1, Topic2, Topic3, Topic4, Topic5
    
    2014-10-04, Yes, No, Yes, Maybe, 1
    
    2014-10-05, Yes, No, No, Maybe, 2
    
    2014-10-05, Yes, No, No, Maybe, 2

    The Problem is that I don’t have the values in the rows at once.

    I want to say db.add($date, “Topic1”, “Value”);

    -- > the Value is set in the column Topic1 on the line $date.

    If Line does not exist, it should be created. If Line is already existing, only the field of topic1 should be updated (others should not be changed).

     

    I also need some reading methods … to get all results of a day or all of a column.

    Is there something in PowerShell that helps me doing this in an elegant and comfortable way?


    Sunday, October 5, 2014 11:14 PM

Answers

  • First you need  to learn what a CSV file is and second you need to learn how to write a simple script. No one is going to write it for you. We will answer specific questions.  If you follow the links posted for you then you will see some basic ideas of how to start.  It is up to you to learn the next steps.

    Start here to get some of the basics: http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

    I recommd looking at Import-Csv and Export-Csv

    $csv=Impiort-Csv file.csv
    $csv[0].Date='2014-10-5'
    $csv| Export-Csv file.csv


    ¯\_(ツ)_/¯

    Wednesday, October 8, 2014 1:31 AM

All replies

  • There is no need to be helpless. Search.

    http://www.google.com/search?q=powershell+create+csv+output

    First result is the documentation for the export-csv cmdlet:

    http://technet.microsoft.com/en-us/library/hh849932.aspx


    -- Bill Stewart [Bill_Stewart]

    Monday, October 6, 2014 1:15 AM
    Moderator
  • This seems to be a different thing.

    This is a "simple" csv output of objects ...

    Not a databas like access for cvs files ..
    I also need to add/change data to a line allready writen, as there are no objects. Also the data does not come at once to create a object I than could output.

    Or do I miss a special option?

    Tuesday, October 7, 2014 10:54 PM
  • First you need  to learn what a CSV file is and second you need to learn how to write a simple script. No one is going to write it for you. We will answer specific questions.  If you follow the links posted for you then you will see some basic ideas of how to start.  It is up to you to learn the next steps.

    Start here to get some of the basics: http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx

    I recommd looking at Import-Csv and Export-Csv

    $csv=Impiort-Csv file.csv
    $csv[0].Date='2014-10-5'
    $csv| Export-Csv file.csv


    ¯\_(ツ)_/¯

    Wednesday, October 8, 2014 1:31 AM
  • The answer is that export-csv outputs objects to a CSV file. It is up to you to retrieve and/or construct the objects you need and then output them in the manner you desire. If you're not familiar with how PowerShell works with objects, then this is a great time to learn.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, October 8, 2014 2:16 PM
    Moderator