I'm still very noob at scripting and I've got to do some scripting in PS which I'm also just recently discovering.

Based on things previously found on stack, I've written this tiny script that checks if machines are online **and** then tries to copy a folder **and** apply proper user rights.

What I would like is to automate it a bit more :

-If I get the error message for all machines, I want the script to start again from the beginning.

-If I get a success message for at least 1 machine, I want the script to stop at the end of its loop and print the successful machine name.

Ideally I also would like the script to remove the successful machine from the txt file at the end of the loop, before starting again.

here's the code

```
$computers=Get-Content c:\listemachines.txt

$source = "C:\Folder"
$destination = "c$\Folder"

ForEach ($COMPUTER in ($computers))
        {if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
        {write-host "Cannot reach $computer is offline" -f red}  #error message

else    {
        if ((Test-Path -Path \\$computer\$destination)){
        TRY{
        Copy-Item $source -Destination \\$computer\$destination -force -Recurse -ErrorAction Stop
        Write-Host "Successfully copied on $computer" -BackgroundColor Green
        Get-Acl -Path C:\Folder | Set-Acl -Path "\\$computer\$destination"
        Write-Host "Successfully copied ACL on $computer" -BackgroundColor Green
        }
        Catch {$error[0].exception.message}
        }
        }
        }

```

thanks alot for your help, this website is amazing !