The "check-result" function used to be an if else to check wether $result contained any data. If it contained any data I wrote a warning and a break. Else would write that the AD computer name is valid.

My problem is, that I'm stuck if one of the verifications is positive. It will report that the AD computer name is already in use and the script just stops. Well I guess that's the "break" in my IF ELSE.

I'm not sure but I believe I have to put the tests into a loop....but I don't know in what kind of loop. It get even more tricky – to me at least – that the AD computer name must be iterated again if a verifications turnes out positive.

The error is in your while loop declaration. You attempt to call function Iterate-ADAccount but that must be done within the curly braces { }. A do/while loop isn't the best choice you just need a while loop. Here's a trimmed down version and I'm just assuming your method for finding the number inside the name string works. I have not tested it myself and since your original code doesn't show how you populate all the name arrays I didn't bother either.