foreach stopped working after upgrading to powershell 4
32 views
Skip to first unread message
Justin Marshall
unread,
Mar 24, 2015, 11:41:40 AM3/24/15
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I had built a script that compared the registry of 2 servers and i'm having a very wierd issue with foreach. My script works perfectly fine in powershell 2 (i even tested by running with -version 2) but after uprading to powershell 4 it stopped working. What it does it retrieves the registry for a given path on a remote server and stores that to a variable then iterates on each property to compare. in powershell 4 the iteration variable becomes null yet the ISE tooltip shows there is data.
The $key | Get-Member returns nothing, the foreach never enters the loop on $Property as it believeles $key is null yet tooltip shows it has data... i'm completely stumped.
any help would be appreciated!
Justin Marshall
unread,
Mar 24, 2015, 11:56:41 AM3/24/15
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Just noticed a typo above it should be $key.property in the foreach, that is when it stops working
Justin Marshall
unread,
Apr 9, 2015, 6:01:54 PM4/9/15
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I eventually found a much better way to do this, i bleieve its because the object was retrieved remotely and the sub proeprties were not captured properly - something i've noticed previously.
I solve this by putting all the logic into a function and passing the function to the remote server.
hopefully this helps someone in the future as it took a lot of digging to figure out how to pass a locally created function to a remote server without dumping the whole thing as a text script block.