Windows 10: Powershell script to add a date to each row of a csv.

Discus and support Powershell script to add a date to each row of a csv. in Windows 10 Customization to solve the problem; Hi all, struggling to get a powershell script working so I'm wondering if somebody would be kind enough to help, hopefully it's something simple but my... Discussion in 'Windows 10 Customization' started by Killer_3669, Aug 18, 2019.

  1. Powershell script to add a date to each row of a csv.


    Hi all, struggling to get a powershell script working so I'm wondering if somebody would be kind enough to help, hopefully it's something simple but my experience with powershell isnt that great although I am learning heaps.


    I have a simple database (a csv file) called sample transactions.csv which has 5 cols as shown below, and I need to append the date to the end of each row which will make 6 cols.


    000002,1 ,0.00 ,PRN,http://www.msn.com/en-au/?pc=U453&ocid=U453DHP&osmkt=en-gb

    000002,2 ,0.00 ,PRN,http://www.msn.com/en-au/?pc=U453&ocid=U453DHP&osmkt=en-gb


    Below is my powershell script and is how I've done it so far and its outputs correctly on screen if I remove the:


    |Export-Csv -Path C:\Filepro\Exports\sample_transactions_inc_header_date.csv -NoTypeInformation


    but if I keep that line in, the file that's finally outputted only has a single line but unsure what I'm doing wrong, apart from that minor issue of it not working this is exactly what I need Powershell script to add a date to each row of a csv. :)



    powershell Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

    #
    #
    ######### Adding the headers #############
    Import-Csv C:\Filepro\Exports\sample_transactions.csv -Header A,B,C,D,E | sort A |Export-Csv -Path C:\Filepro\Exports\sample_transactions_inc_header.csv -NoTypeInformation
    #
    #
    ######### Adding date as another col F #############
    Import-Csv C:\Filepro\Exports\sample_transactions_inc_header.csv | foreach-object {
    $row = $_
    $row | add-member NoteProperty "F" (Get-Date -format "dd/MM/yyyy")
    $row |Export-Csv -Path C:\Filepro\Exports\sample_transactions_inc_header_date.csv -NoTypeInformation
    }
    ######## I'm missing something regarding the above line ##########
    #
    # $row |Export-Csv -Path C:\Filepro\Exports\sample_transactions_inc_header_date.csv -NoTypeInformation
    #
    ######## Removing the header row ###########
    Get-Content C:\Filepro\Exports\sample_transactions_inc_header_date.csv|select -Skip 1|Set-Content C:\Filepro\Exports\sample_transactions_header_removed.csv
    #
    #
    #########Adding Time Date to filename and saving #############
    Rename-Item -Path C:\Filepro\Exports\sample_transactions_header_removed.csv -newname C:\Filepro\Exports\FilePro_export_$(Get-Date -F yyyy-MM-dd_HH-mm).csv
    #
    #
    ########## Removing temp files #############
    Remove-Item –path C:\Filepro\Exports\sample_transactions_inc_header.csv

    Remove-Item –path C:\Filepro\Exports\sample_transactions_inc_header_date.csv



    Any help would be truly appreciated, cheers Rich

    :)
     
    Killer_3669, Aug 18, 2019
    #1
  2. ddelo Win User

    Export All Administrative Events to Excel


    To analyze events, from the Windows Event Viewer, there is a simple way to export all Administrative Events to Excel, with PowerShell.

    Exporting all Administrative Events to Excel is a simple two Step process, as described here:

    Step 1 - Create the Administrative Events View .xml file
    1. Open Eventviewer (%windir%\system32\eventvwr.msc)
    2. Navigate to: Event Viewer (Local) > Custom Views > Administrative Events
    3. In the “Actions” pane select “Filter Current Custom View”.
    4. Select the the XML tab.
    5. Press Ctrl+A to select all the XML code of the Custom View.
    6. Open a notepad, paste the selected code and save the file to your Desktop as AdmEvtView.xml


    Step 2 - Create the csv file with the events
    1. Download the ExportEvtCSV.zip file, which contains the script ExportEvtCSV.ps1 and unzip it, on your Desktop.
      It's not a fancy script, just basic PowerShell commands to create a csv file on the Desktop.
    2. In Windows Search, type “ISE” (without the quotes) to open “Windows PowerShell ISE” and Run as administrator
    3. To allow running the script, change the ExecutionPolicy, for this session. To do that, in the Console pane type:
      Code:
      Code:
      Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -force
    4. In the Windows PowerShell ISE, open and run the script: ExportEvtCSV.ps1
      The script will create a csv file with a name YYYYMMDD.HHMM.csv on the Desktop
    5. When done, open the newly created .csv file, format the columns as needed and optionally save it as .xlsx, if you wish.
    That’s it! You now have all the Administrative Events in Excel for filtering and further analysis. Powershell script to add a date to each row of a csv. :)

    Now to the more technical hard stuff... *Confused

    There is a reason for running the script from within PowerShell ISE!

    It would be great if everything was also working perfectly, when running the script from an elevated PowerShell too.

    We can run it from an elevated PowerShell, which means that you just follow the Step 1, as above but for the Step 2 instead of the ISE you run the script from an elevated PowerShell.

    The problem is that it will work only for anybody who has en-US format for the dates. Everyone else, who has another format (i.e. en-GB, fr-FR, el-GR etc.), the dates are not translated properly by Excel (although the script uses the –UseCulture switch) and remain as text in the en-US format.

    I'm not sure if this a bug of the "export-csv" cmdlet, but although it runs the way it supposed to from within the ISE, from PowerShell there is a problem with the dates format.
    As I haven’t found a way to overcome this obstacle, any suggestion from the PowerShell gurus of the forum (like my good friend Shawn @Brink, for instance), is welcome.
     
    ddelo, Aug 18, 2019
    #2
  3. PowerShell scripts not working with Call operator

    Hi,



    Thank you for writing to Microsoft Community Forums.



    I understand that you are facing issues while developing a PowerShell script using the Call operator. I would suggest you to refer the articles

    The Windows PowerShell ISE
    .



    However, as the issue is related to developing PowerShell scripts, I would suggest you to post your query on

    MSDN forums
    , where we have expertise and developers who are well equipped with the knowledge of developing PowerShell scripts in Windows.



    Regards,

    Prakhar Khare

    Microsoft Community – Moderator
     
    Prakhar_Khare, Aug 18, 2019
    #3
  4. Powershell script to add a date to each row of a csv.

    Powershell script to read coulumn 2 data from .csv file

    Due to the scope of your issue which relates to Scripting in Windows PowerShell, you would be best served redirecting this question to the dedicated Windows PowerShell forums on Technet.

    https://social.technet.microsoft.com/forums/en-...

    Sorry for the inconvenience of having to suggest the re-route, but Technet has a lot of experts there that know the ins and outs of enterprise issues; especially domain configurations for clients. So, they will be better able to assist you.
     
    Andre for Directly, Aug 18, 2019
    #4
Thema:

Powershell script to add a date to each row of a csv.

Loading...
  1. Powershell script to add a date to each row of a csv. - Similar Threads - Powershell script add

  2. PowerShell script

    in Windows 10 Support
    PowerShell script: The code below tests a series of IPs in a txt file.The result is as follows and is written in a txt file. 19.191.12.161 - online 19.191.12.162 - offline 19.191.12.163 - offline 19.191.12.164 - offline 19.191.12.165 - offline also see the scrennshot Code: $Output= @()$GetIP =...
  3. powershell scripts

    in AntiVirus, Firewalls and System Security
    powershell scripts: Hi, I have azure. Someone is somehow installing powershell scripts onto my computer that allows them to host my PC through P2P and UDP connections, well I think so anyway. I have only just found powershell script entry changes in my registry by accident. These criminals...
  4. powershell script

    in Windows 10 Customization
    powershell script: looking for a script to monitor for a folder, if there is a file in that folder send it as an email, once the email is sent out, confirm and then move the files to an archive folder. monitor c:\test\*.pdf No files, do not send email. Yes Files, send an email to someone at...
  5. CSV to XML script not showing data

    in Windows 10 Software and Apps
    CSV to XML script not showing data: Hello everyone, Firstly, I don't know if this thread belongs in Software and Apps, if it doesn't feel free to move it to the correct sub-forum so I know for later where to put problems like this. To the problem now... I have been trying to export a huge CSV file via...
  6. sorting columns in CSV file with powershell

    in Windows 10 Software and Apps
    sorting columns in CSV file with powershell: I have a csv file with 1600 lines from which top ten lines given below N,EQ,ADANIPORTS,ADANI PORT & SEZ LTD,384.5,385,387.8,375,376.75,792818726.1,2085488,Y, ,40850,452.35,350.45 N,EQ,ASIANPAINT,ASIAN PAINTS LIMITED,1394.75,1395,1411,1385.05,1393.5,1284559258,919355,Y,...
  7. Help needed for working with csv file in powershell

    in Windows 10 Software and Apps
    Help needed for working with csv file in powershell: I have a csv file, I need to extract a few columns from that file and create a csv file with those columns. My csv file is NBN.csv. I tried to extract a few columns in new order. I succeeded in that. But out put is not a csv file as shown below. [img] How to make the out...
  8. A Powershell Script for HandBrake

    in Windows 10 Software and Apps
    A Powershell Script for HandBrake: Here's the thing. My system is an age-old i3-530 overclocked to 3.5GHz coupled with GTX 1050 2GB. I have around 1.5TB of tutorial videos that I have to encode due to dearth in HDD space. I want to encode the videos while keeping the folder and subfolder structure intact....
  9. PowerShell Scripting - The Basics

    in Windows 10 Tutorials
    PowerShell Scripting - The Basics: How to: PowerShell Scripting - The Basics [img] Information A PowerShell script is a collection of commands and cmdlets to be run in logical order, previous lines in script determining values and variables in command lines thereafter. The principle is the same than in...
  10. PowerShell Script - Add to New Context Menu in Windows 10

    in Windows 10 Tutorials
    PowerShell Script - Add to New Context Menu in Windows 10: How to: PowerShell Script - Add to New Context Menu in Windows 10 [img] Information A .ps1 script file is a text file that contains one or more Windows PowerShell commands or expressions. A .ps1 file will open with Notepad by default. To run a .ps1 file with PowerShell,...

Users found this page by searching for:

  1. powershell format date row