# Foreach issues - only treating last domain on list

**URL:** <https://forums.powershell.org/t/foreach-issues-only-treating-last-domain-on-list/14536>\
**Category:** PowerShell Help\
**Created:** [June 15, 2020, 1:47am UTC](https://forums.powershell.org/t/foreach-issues-only-treating-last-domain-on-list/14536 "2020-06-15T01:47:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonatantwn](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@jonatantwn](https://forums.powershell.org/u/jonatantwn)\
**Post date:** [June 15, 2020, 1:47am UTC](https://forums.powershell.org/t/foreach-issues-only-treating-last-domain-on-list/14536/1 "2020-06-15T01:47:04Z")

</div>

Hi Powershell!

I am working on trying to make a Powershell / WinSCP script that can do the following:

Consider a list of domains

Delete a list of the same files, from each of these domains

Upload new data to another location on these same domains.

It sort of works by now, but, for some reason my foreach loop does not seem to quite get me.  
It seems to be only taking the last domain on the list, which is testmappe2.dk

The ouput (written to host) is:

Removing of file testmappe2.dk/pluginfil/\* succeeded  
Removing of file testmappe2.dk/mappe/\* succeeded  
Uploading to C:\Users\Dern\Desktop\REPLACEME\* testmappe2.dk/\* …  
Uploading to C:\Users\Dern\Desktop\REPLACEME\* testmappe2.dk/\* …  
Error: Exception setting “SessionLogPath”: “Object is disposed”

Is seems to entirely skip testmappe.dk, which is the first one.

Also, can anyone enlighten me on why i get this exception error “object is disposed”?

I really hope someone can help me the last bit here! 🙂

Link to code: [https://gist.github.com/Jonatantwn/cf5a17a80327adcb6a25e11524a766c0](https://gist.github.com/Jonatantwn/cf5a17a80327adcb6a25e11524a766c0)

Best regards  
Jonatan

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/foreach-issues-only-treating-last-domain-on-list/14536/2 "2024-05-16T20:29:21Z")

</div>


