la11111
la11111

Reputation: 361

SyncRoot property in Powershell

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?

Upvotes: 2

Views: 4983

Answers (1)

CB.
CB.

Reputation: 60958

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

Upvotes: 1

Related Questions