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
LVL 1
whorsfallAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.