Link to home
Start Free TrialLog in
Avatar of ndalmolin_13
ndalmolin_13Flag for United States of America

asked on

Help extracting text from a string

Hello Powershell Gurus,

Here is my powershell question for the day.  If I run the following command:

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName fs01 | Select-Object dnsserversearchorder

I get the following output (which is correct):

dnsserversearchorder                                                                                
--------------------                                                                                
{172.16.1.19, 172.16.1.20}  

I ran the get-member on the Get-WmiObject -Class Win32_NetworkAdapterConfiguration command and learned that the dnsserversearchorder property is a string.  How can I extract the two IP addresses from the string?

Thanks in advance.

Regards,
Nick
Avatar of rwskas
rwskas
Flag of United States of America image

You can use the Split function if it is a string
$string.Split(",")

Split on the comma and you will split the string into (2) IP addresses
Avatar of ndalmolin_13

ASKER

How would I do this?

I tried the following:

$dns = Get-Wmiobject -Class Win32_NetworkAdapterConfiguration -ComputerName fs01 | Select-Object dnsserversearchorder
$dns.split(",")

I received an error stating:

Method invocation failed because [System.Object[]] doesn't contain a method named 'split'.
At :line:2 char:10
+ $dns.split <<<< (",")
ASKER CERTIFIED SOLUTION
Avatar of rwskas
rwskas
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Glad I could help!