Get Information from File

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
luckydead
Posts: 1
Last visit: Fri May 10, 2019 4:41 am

Get Information from File

Post by luckydead »

Hello,
I'm new to powershell and I have one task to make at home.
Can someone really help me out with this because I cannot do it myself , that's why I will ask for some help.

What i want to have :
1. When open powershell file ( To start by asking "Drag or drop the file" or put location to the file
2. Only to open .csv files format
3. When open the file to get from the file this lines. (Here is example a few lines inside the file)

Example.csv :

Code: Select all

A0003979305I606	560BLSA14_C418_1A			20190508	55450	20190508	60008	300SB601
A0003979030I606	560BLSA14_VG20_1A			20190508	60122	20190508	60415	300SB601
A0003979320I606	560BLSA14_VG20_1A			20190508	60500	20190508	60909	300SB601
Or simply columns are like this:
Capture.PNG
Capture.PNG (11.35 KiB) Viewed 2000 times
[img]

File Example.csv
GuideLog_20190508.csv
(9.29 KiB) Downloaded 120 times
What i really need to do when open the file .csv
1. To get information from columns only : A , E , F, H , I
2. To save the information in another file (Default ./result.csv)
3. To make a little change in columns
Example: 20190508 55450 20190508 60008 300SB601 (first row)
To be saved inside the file like this:
2019.05.08 05:54:50 AM 06:00:08 AM 300SB601
Also to be added 1 new column that will count the results from 06:00:08 - 05:54:50 (this is the time from start and finish) so we will get how much time needed to finish result (05:18)

And result inside the file result.csv to be like this:
Capture2.PNG
Capture2.PNG (5.11 KiB) Viewed 2000 times
Can someone really help me about this , i know its big work and i'm sorry that i cannot make it myself.
Hope there is some nice person that can help me out.
Thank you very much.

Here is simply what I have for start:

Code: Select all

clear-host
write-host "Please Drag and Drop your CSV in the console Window and press enter"
$input  = read-host "Source"
clear-host

write-host "Please enter your export path"
write-host "The default output location is your desktop [$($env:userprofile)]" -ForegroundColor Yellow
write-host "Leave the input blank for the default location and just press ENTER" -ForegroundColor Yellow

$output = read-host "Output Location"
$name=($env:UserName).tolower()
if(-not($ouput) -or (test-path $ouput)){$output = "C:\Users\$name\desktop"}

try{
    import-csv $input -ErrorAction Stop | Export-Csv $output -Delimiter "," -ErrorAction Stop
}
catch{
    write-warning "Please contact support and provide the following error message"
    $error[0]
    write-host " Support email: myemail " -ForegroundColor Blue -BackgroundColor White
    read-host "Press ENTER to exit"
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get Information from File

Post by jvierra »

You seem to be asking for someone to write a script for you. Custom script writing is beyond the scope of most technical forums.

I suggest that a good place to start would be to learn basic PowerShell. This will help you to ask your question in an understandable way and get you started on writing your own scrips.

Here are some learning resources to help you get started.

https://www.youtube.com/user/SAPIENTech ... _polymer=1

https://mva.microsoft.com/en-us/trainin ... 2304984382

You can also use the PowerShell help to get more information on how to use specific CmdLets:

help import-csy -online
help Select-Object -online

Good luck.
This topic is 4 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked