Looping

<p class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">I have written a script that's purpose is to list all files in a directory from a list of computers that are imported from a .txt file and it will compress the files to a network path. I am not sure if I have written it correctly, hoping you can look at it and let me know if there is a better way.</p>
<p class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">Script looks like this:</p> <p class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">$destination = \\networkpath</p> <p class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">$machines = (Get-Content "\\networkpath\machines.txt")</p> <p class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">foreach ($machine in $machines) { $sourcefiles = gci "\\$machine\C$\localpath" }</p> <p class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr">foreach ($sourcefile in $sourcefiles) { Compress-Archive -Path "\\$machine\C$\localpath" -Destinationpath "$Destination\$Sourcefile.zip" -CompresionLevel Optimal -Verbose }</p>

The script works for one machine (the last one in the text file) so it looks like it just isn’t looping, probably because of this double foreach loop I am using. I tried piping the output of $sourcefiles to a compress-archive but this doesn’t zip the files individually.

Any ideas where I went wrong here would be appreciated!