Foreach loops in PowerShell, how to use them and which one to use when

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024

Комментарии • 7

  • @PetterTech
    @PetterTech  2 года назад +2

    I recently found a love for the foreach method, but the foreach statement is still my go to loop.
    Which type of loop is your favorite?

  • @ricmikricmik
    @ricmikricmik 2 года назад +2

    10/10

  • @freshmaker4o
    @freshmaker4o 5 месяцев назад

    Nice video. I was wondering what are your observations on ForEach-Object - Parallel {}

    • @PetterTech
      @PetterTech  5 месяцев назад +1

      I have actually never found a good, practical use case for it. Not that there isn’t any, it’s just that I personally haven’t come across scenarios where I’d use it.
      So I don’t really have any observations on it yet

    • @freshmaker4o
      @freshmaker4o 5 месяцев назад

      @@PetterTech Thanks for the replay. I've been playing around with all versions of the loop for copying files, and I've tried several different approaches, jobs and what not and the simple foreach () {} seems to be the fastest solution, in my case at least

  • @lowceski
    @lowceski 6 месяцев назад

    Can we loop through ip addresses

    • @PetterTech
      @PetterTech  6 месяцев назад

      Certainly! Depends on how the ip adresses you want to loop through are stored, but if you wanted to do a simple ping sweep you could do something like this:
      10.13.37.1..255 | foreach {ping 10.13.37.$_ -c 2}