header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

How to handle returned System.String object?
Last Post 18 Nov 2008 10:25 PM by MattG. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
MattGUser is Offline
New Member
New Member
Posts:20
Avatar

--
18 Nov 2008 05:07 PM  

I am executing the following command:

gwmi win32_networkadapterconfiguration|where {$_.IPAddress}|select dnsserversearchorder

On screen this comand returns the DNS Servers for IP enabled NIC in the following format:

{192.1.1.1, 192.1.1.2}

When I use export-csv the value listed in the column is System.String[]

2 things:

  1. How do I convert this value to a value that will output like what I see on the command line?
  2. How do I "Split" this value so that I can output each value into a DNS1 and DNS2 variable?

I have tried this unsuccessfully:

$dnsso = gwmi win32_networkadapterconfiguration|where {$_.IPAddress}|select dnsserversearchorder

echo $dnnso[0].Split(",")

It complain that Split is not a valid function of the type it is passed.

Thanks,

-MattG

halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
18 Nov 2008 06:42 PM  
Most of the IP fields return arrays of strings like this. To work with them you can index them (e.g. [0]), loop through them (e.g. $arr | foreach-object { $_ }, or you can force them to be output as a string:

PS > $a = 1,2,4
PS > $a
1
2
4
PS > "$a"
1,2,4
PS > $ofs=' '
PS > "$a"
1 2 4
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
MattGUser is Offline
New Member
New Member
Posts:20
Avatar

--
18 Nov 2008 10:25 PM  
Thanks Hal.

I was able to Split the DNSearchOrder field using the array index:
$field6 = @{Name="DNSServer1";Expression={$_.DNSServerSearchOrder[0]}}
$field7 = @{Name="DNSServer2";Expression={$_.DNSServerSearchOrder[1]}}

-MattG
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer