import same.csv | For Each {

Welcome Forums General PowerShell Q&A import same.csv | For Each {

This topic contains 2 replies, has 2 voices, and was last updated by

4 years, 8 months ago.

  • Author
  • #16240

    Points: 0
    Rank: Member

    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.


  • #16243

    Points: 0
    Rank: Member

    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
  • #16247

    Points: 0
    Rank: Member

    Perfect thankyou..

The topic ‘import same.csv | For Each {’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort