Powershell Exchange 2013 Batch question

I work in a very large enterprise environment and we are moving users to Exchange 2013. The one issue that we need to automate is placing the primarysmtpaddress in a text file with the header emailaddress. What we have done is taken a large mass of users maybe 1,000 at a time and save them to different csv files with the header emailaddress. In the CSV file/excel we sort by name and create a column called batch. In there we place numbers 1-30 and keep starting over from 1-30 until we get to the 1,000th person. We then sort on that field and everything with 1 goes into a file with emailaddress as the header and populate this with just the primarysmtpaddress.We do this for everything that has a number 2, place this in a csv file with the header emailaddress with the primarysmtpaddress. We keep going on and on and on until we reach 30th which has the 1000 user. As you can see this is painful and long.  How can you get powershell to look inside of a csv file, grab all the number 1's place them into a separate csv file with the header emailaddress and move on until it gets to 30.  If someone has a better method please do share
techdriveAsked:
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.

SubsunCommented:
If i understand your requirement, then the following code should do it.. It will take the input file with columns headers "emailaddress" & "batch", then split the csv file like, all batch one will go to batch1.txt, batch two should go to batch2.txt etc..
Import-Csv C:\input.csv | Group Batch | %{
$File = "C:\batchfiles\Batch$($_.Name).txt"
 $_.Group | Select emailaddress | Export-Csv $File -nti
}

Open in new window

Test and let me know if you need any modifications..
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
techdriveAuthor Commented:
Perfect thanks
0
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.