0

Hi I'm trying to create a loop so that it continues to "do stuff" until a variable is hit.

what I'm trying to do is to loop through multiple disks and copy them, and then move to the next set of disks and copy those, hoever if there are no further sets then I would like to stop.

Example

if ($server -eq 1){
write-host "server 1"
}
if ($server -eq 2){
write-host "server 1"
write-host "server 2"
}
if ($server -eq 3){
write-host "server 1"
write-host "server 2"
write-host "server 3"
}
if ($server -eq 4){
write-host "server 1"
write-host "server 2"
write-host "server 3"
write-host "server 4"
}

server names would be substituted for disk names.

Is there a way to do if (server -eq 4) then it does server 1, server 2 and server 3.

The script is ending up with over 3000 lines, mostly repeated code.

Hope that makes sense

Thanks in advance :)

1
  • [1] if this is about disks ... please use DISKS instead of SERVER. you are really confusing things. [grin] ///// [2] how do you determine how many disks are in a set? right now you have each set increasing by one. Commented Jan 30, 2019 at 12:19

1 Answer 1

1

Use a loop like you suggest?

$servers = 4 #update with number of servers

for ($i=1; $i -le $servers; $i++) {
    Write-Host "server $i"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.