import same.csv | For Each {

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of A K P A K P 2 years, 5 months ago.

  • Author
    Posts
  • #16240
    Profile photo of A K P
    A K P
    Participant

    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.

    Thanks,
    AKP

  • #16243
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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
    Profile photo of A K P
    A K P
    Participant

    Perfect thankyou..

You must be logged in to reply to this topic.