The header describes the data for element 8 as
 Code:
Domain Info: Hostname;Connection;Primary;Search List **, *** 

This lists the hostname, the Connection-Specific DNS Domain, the Primary DNS Domain, and the domain-name search list. The first $_WorkArray[8]= line sets the hostname. The next reads a reg value and appends to $_WorkArray[8]. There's a third reference farther on that adds two more values to the list.

This value can be complicated - I could have returned an array of arrays, but this often makes things too complicated.. instead, I chose to return a list that consists of values.
You can use $DomainInfo=Split($WorkArray[8], ';') to create an array containing the hostname, connection, primary, and search values. Be aware that the last item - search - can contain multiple domain names, separated by spaces. This would generally not be used to determine domain location or membership. By using this command, you could reference the connection domain as $DomainInfo[1]

The way things should work - if everything is properly configured in the network - is:
Computer name is HOSTNAME.PRIMARY_DOMAIN (elements 0 & 2) - UNLESS "connection" is defined.
If "Connection" is defined (usually due to two or more active NICs, including a VPN connection) the computer name is HOSTNAME.CONNECTION_DOMAIN when communicating through the specific connection. Thus, a computer could have multiple identities in a complex network.
The last field - Search List - is used when the local computer tries to identify non-qualified hostnames.. for example, if you "PING THATHOST", it first appends the primary domain or connection-specific domain if appropriate to the outbound interface.. if there's no reply, it appends each of the domain names in the search list until it gets a reply or gives up.

This illustrates why the data returns different values for internal and external in your example.. the external does not have a connection-specific domain defined, only a primary domain.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D