import same.csv | For Each {

Hi All,

I am using this command quiet a few times in my new user script

import same.csv | For Each {

And basically for each loop I am doing some particular stuff i.e. create user account, create mailbox, add to groups, create home folder etc etc.

I was just wondering if I am able to simply do all the work in a single loop rather than having multiple?

I will test this out now, but need some advice.


Yep, you can put multiple commands and pipelines inside the ForEach block. Typically I’ll assign the value of $_ to another variable and then go from there:

Import-Csv same.csv |
ForEach-Object {
    $csvRecord = $_

    # Statement one with $csvRecord

    # Statement two with $csvRecord

    # and so on

Perfect thankyou…