2

This question is regarding the function forward_dns from the following blog: http://powershellmasters.blogspot.com/2009/04/nslookup-and-powershell.html

So say I have a piece of code in powershell that looks like this:

$cmd = "nslookup google.com " + $NameserverIPAddress;
$result = Invoke-Expression ($cmd);

This snippet uses the nslookup DOS command to do a DNS lookup. Since it's a DOS command, the object returned by Invoke-Expression is basically an array of strings, one for each line of output.

In the example function, in order to retrieve line 4 of the output, the original author uses the following syntax:

$result.SyncRoot[3];

I found that this also works just fine:

$result[3];

What is the purpose of SyncRoot in this context?

la11111
  • 361
  • 5
  • 10

1 Answers1

1

There is no purpose in this example. SyncRoot property is a way to treat in a safe manner ( generally with a lock in .net) arrays handled by more that one thread. see here and here

CB.
  • 58,865
  • 9
  • 159
  • 159
  • great, thanks! That's kind of what I thought. A bit useless in powershell, since as far as I'm aware, Powershell doesn't support threads... There's a way better way to do what this guy was trying to do anyway. – la11111 Apr 20 '12 at 18:49