I am trying to loop the list through the function that i made. What I want to do with the loop is that the variable: "$huidige_folder" inside the function is filled with one location at a time that is in the list, loop and continue with the next location in the list
- So first item in the list: "C:\Users\Nick\Desktop\Test1". It uses this location in the function
- Then C:\Users\Nick\Desktop\Test2". It uses this location in the function
- Then C:\Users\Nick\Desktop\Test3". It uses this location in the function
But when i run the code it will only run the function for the first item in the list. That works and it does what i want. But after that it stops and doenst run the funtion for the other 2 items in the list.
What am i doing wrong?
$path_dagelijkse_controle = "C:\Users\Nick\Desktop\Test1",
"C:\Users\Nick\Desktop\Test2",
"C:\Users\Nick\Desktop\Test3"
function Dagcontrole_folders_maken {($huidige_folder)
$Dagelijkse_controle = "Dagelijkse controle"
$datum_vandaag = $(Get-Date).toString('yyyy-MM-dd')
$jaar = $datum_vandaag.Substring(0,4)
$maand = $datum_vandaag.substring(5, 2)
$dag = (get-date).DayOfWeek
$path_jaar = Get-Item -Path "$huidige_folder\**" -Include *$jaar*
$path_maand = Get-Item -Path "$huidige_folder\$jaar\**" -Include *$maand*
$folder_maand = Get-Date -UFormat "%m - %B"
if ($path_jaar) {
Write-Output "Do Nothing"
}
Else {
md -Path "$huidige_folder\$jaar"
}
if ($path_maand) {
md -Path "$huidige_folder\$jaar\$folder_maand\Dagelijks\$datum_vandaag"
}
Else {
md -Path "$huidige_folder\$jaar\$folder_maand" # Makes the month folder
md -Path "$huidige_folder\$jaar\$folder_maand\Dagelijks\$datum_vandaag" # Makes a folder with current date inside the month folder
}
}
Foreach ($i in $path_dagelijkse_controle) {
Dagcontrole_folders_maken($i)
}
function Dagcontrole_folders_maken {($huidige_folder)tofunction Dagcontrole_folders_maken ($huidige_folder) {md .. -Force.