• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1153
  • Last Modified:

Powershell - Show progress with import-csv

Hi,

Is there any way when importing a CSV file via powershel (import-csv) l i can display the progress via the
write-progress cmdlet.

Thanks,

Ward
0
whorsfall
Asked:
whorsfall
1 Solution
 
tolinromeCommented:
Does this help?
http://mrhodes.net/category/powershell/

About halfway down the page under the heading "Adding 285 Contoso Users with Pictures to your Development Environment Active Directory"
0
 
whorsfallAuthor Commented:
Hi,

Thanks for that. Um not really this code give progress after the csv has been imported. I am after during.

Thanks,

Ward
0
 
footechCommented:
There's no real way to display progress for this.  You could display something like which line number it is on, but to display something like a percent complete, you need to know what the end point is, and you don't know that until you've read in the entire file, so it's a chicken and the egg problem.  Here's an example of displaying the line number.
Import-CSV file.csv | % -begin {$i=0} -process { Write-Progress -activity "Importing file" -currentOperation "Reading line $i" -PercentComplete -1; $i++ }

Open in new window

0
 
QlemoC++ DeveloperCommented:
Using Import-CSV with a pipe, like
import-csv file.csv | % { <# processing code #> }

Open in new window

should get rid of the need for a progress indicator. The import is done row by row, and the current row is processed immediately. Usually the processing takes more time than the import, and hence is the more interesting and time consuming part. In this scenario, a progress indicator could be shown for the loop part, and we are back to http:#a40241044.
0

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now