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

preview_player
Показать описание
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
Рекомендации по теме
Комментарии
Автор

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

OwlPharaoh
Автор

I think there is no one better than you on Youtube!
Thank you so much!

Jon-rpst
Автор

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!

NigelStroopwafel
Автор

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

mrliuquantong
Автор

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

Jomster
Автор

Another great learning video thanks Jack

richardgarrow
Автор

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

davidflint
Автор

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.

henrymdominguez
Автор

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

XwolfBane
Автор

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.

dmitryepikhin
Автор

I tested it and shows first one is the fastest

#Fastest (1.13s)
foreach($no in

# (4.5s)
{$_} )

#slowest (9s)
| ForEach-Object { $_ }

i used measure-command to test it.

lonedruid
Автор

$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"

}
}
)

netor-y
visit shbcf.ru