Hi all,
I'm currently working on some smaller school scripting projects for upcoming exams. However I can't seem to manage to run a certain part of a script X amount of times by a variable.
So far I have the code shown below:
(comment blocks are in Dutch but you can ignore those, it's for students to understand what it has to do)
#Dit script is te gebruiken om een X aantal OUs toe te voegen aan je domein.
#Het script vraagt hoeveel OUs je aan wilt maken, en de te gebruiken naam/descriptie voor het OU.
#Ik ben van plan deze later nog uit te breiden om zo meer opties toe te staan voor de installaties etc.
#De reden voor deze scripts is puur voor het gemak tijdens examens om het zo gemakkelijk voor alle opdrachten te kunnen gebruiken.
#Dit deel van het script is voor het verzamelen van informatie die in de commands gestopt wordt.
$repeatX = Read-Host -Prompt 'How many OUs should be made?'
#Dit deel van het script is om de taken uit te voeren met de informatie die eerder verkregen is.
Write-Host "Starting to make the OU..."
Do {
$OUnaam = Read-Host -Prompt 'Insert desired OU name'
$OUdescription = Read-Host -Prompt 'Insert desired OU description'
New-ADOrganizationalUnit "$OUnaam" -ProtectedFromAccidentalDeletion $False -Description "$OUdescription"
Write-Host "Adding OU..."
Write-Host "Amount of OUs left to be made: $($repeatX - 1)"
} Until ($repeatX -eq 0)
#Dit deel van het script is om aan te geven als er foutmeldingen zijn geweest tijdens de installatie.
Start-Sleep 1
Write-Host "
Was there an error in the script during installation? (Default is Nee)" -
$foutmelding = Read-Host " ( j / n) "
Switch ($foutmelding)
{
j {
Write-Host "Foutmelding gevonden...
Pauzeren voor 120 seconden om de foutmelding te lezen..."
Start-Sleep 120
}
n {
Write-Host "Geen foutmelding gevonden...
Script beeindigen..."
Start-Sleep 5
}
Default {
Write-Host "Geen foutmelding gevonden...
Script beeindigen..."
Start-Sleep 5
}
}
Write-Host "Einde van script: 'Nieuwe-OU-aanmaken-universeel' ..."As you can see, at the start of the script it'll ask the amount of OUs that have to be made using the $repeatX variable. However the Do/Until part doesn't work for me, I've spent several hours trying to fix it so far however not been able to make it fully work, it just keeps on repeating forever.
Hope any of you guys can help me solve this :)