PowerShell 7 Tutorials for Beginners #8 : ForEach (Loops)

Поділитися
Вставка
  • Опубліковано 7 лют 2025
  • In this video I will go over using a ForEach Loop in PowerShell 7.2 , we will see what a loop is and compare it against writing out each line out. We will also see 3 different ways to initiate a foreach loop in PowerShell and why it is very useful to use loops in programming/scripting.
    Tags:
    PowerShell, jackedprogrammer, powershell 7, how to install powershell 7, powershell 7 on vs code, visual studio code

КОМЕНТАРІ • 18

  • @OwlPharaoh7
    @OwlPharaoh7 6 днів тому

    thank you so much. i'm learning powesrshell so i can write scripts for cyversecurity tasks. this is awesome content

  • @Jon-rp4st
    @Jon-rp4st 2 роки тому +2

    I think there is no one better than you on UA-cam!
    Thank you so much!

  • @NigelStroopwafel
    @NigelStroopwafel Рік тому

    I love the format of your videos. I've been learning PowerShell for a few months and your teaching style works so much better than other courses I've learned from. After watching your other videos, I was able to understand how to create the first foreach loop before you explained it. Keep up the good work and thank you!

  • @ghostingalong
    @ghostingalong 2 роки тому +3

    I’m appreciative of these for sure

  • @mrliuquantong4943
    @mrliuquantong4943 10 місяців тому

    This is the best I have ever seen on youtube these years!!

  • @Jomster777
    @Jomster777 5 місяців тому

    Really big help on these tutorial videos. Thanks! I've now also learned how to delete multiple folders with the ForEach method as well.

  • @richardgarrow9260
    @richardgarrow9260 2 роки тому

    Another great learning video thanks Jack

  • @davidflint6917
    @davidflint6917 2 роки тому +1

    I tend to use the second method over the first, as that allows begin, process, end

  • @oussamahernandez6503
    @oussamahernandez6503 7 днів тому

    Thanks

  • @BitPazzo
    @BitPazzo 2 роки тому +3

    Top youtuber!!! 👋 👋

  • @ВикторЛарионов-й3к
    @ВикторЛарионов-й3к 11 місяців тому

    Top youtuber!!!

  • @henrymdominguez
    @henrymdominguez 2 роки тому

    Could you do a future video on a foreach loop that includes if else statements and PnPBatch? I've been scouring the internet for help with a script I'm writing to no avail.

  • @XwolfBane18
    @XwolfBane18 2 роки тому

    Hi Jack I have a question I have folder I want to synce for 15 users in sharepoint site , I have there username and password how do I go about scripting from my machine to make sure that folder is there when they sign into a device I’m new to script but I want to learn how to do it any guide would be appreciated

  • @dmitryepikhin2784
    @dmitryepikhin2784 Рік тому

    I don't speak English well, sorry, I use a Google translator.
    I didn't understand where the $name came from here: foreach($name in $folderNames){... Tell me, please, what is $name means? I mean, we didn't set it as a variable before.

    • @okeriesenbeck1936
      @okeriesenbeck1936 2 місяці тому

      the $name is a temporary variable that is assigned to the element of the array at which the foreach-loop is currently at, for example if the array is @(1,2,3), in the first iteration of the loop $name is assigned to 1, in the second iteration $name is assigned to 2 and so on

  • @lonedruid3360
    @lonedruid3360 Рік тому +1

    I tested it and shows first one is the fastest
    #Fastest (1.13s)
    foreach($no in 1..1000000){$no}
    # (4.5s)
    (1..1000000).ForEach( {$_} )
    #slowest (9s)
    1..1000000 | ForEach-Object { $_ }
    i used measure-command to test it.

    • @jackedprogrammer
      @jackedprogrammer  Рік тому +1

      This is correct, if I were to make this again i would be recommeding the foreach($x in $array) as the fastest, measure-command is super useful good catch! :)

  • @netor-3y4
    @netor-3y4 Рік тому +1

    $filePath="C:\Scripts\8 - ForEach\Data\FolderNames.txt"
    $foldersPath."C:\Scripts\8 - ForEach\Data\Share"
    $folderNames=Get-Content -Path $filePath
    foreach($name in $folderNames){
    if((Test-Path -Path "$foldersPath\$name") -eq $false){
    New-Item -Path "$foldersPath" -Name $name -ItemType Directory
    }else{ Write-OutputI"Folder exists"
    }
    }
    $folderNames | ForEach-Object -Process {
    if((Test-Path -Path "$foldersPath\$_") -eq $false){
    New-Item -Path "$foldersPath" -Name $_ -ItemType Directory
    }else{ Write-Output "Folder exists" }
    }
    $FolderNames.ForEach(
    {
    if((Test-Path -Path "$foldersPath\$_") -eq $false){
    New-Item -Path $foldersPath -Name $_ -ItemType Directory
    }else{
    Write-Output "Floder exit"
    }
    }
    )