I have a text file Information.txt which has values like:-
Name Type IP
abc elite 10.0.0.1
def gold 10.0.0.2
ghi silver 10.0.0.3
$global:Content = get-content Information.txt Function ExtractIP($String) { $IPregex=(?<Address>((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)) If ($String -Match $IPregex) {$Matches.Address} } IPAddress
{ Foreach($line in $Content) { $Ip = ExtractIP($line).Trim(); $Name = $line.Replace($Ip,' ').Trim(); $Type = $line.Replace($Name,' ').Trim(); $IpCheck=Test-Connection -Computername $Name-count 1 -ErrorAction Silentlycontinue | Select IPV4Address
}
}
IPAddress
When i run the above code, Instead of pinging the server "abc", it pings abc-elite. By using the regex expression, I can isolate the Ip address, but how do I isolate name and Type?
FOr ex:-
Name Type IP
------- ------ ------
abc elite 10.0.0.1
I want to get the IP address by using regexexpression, replace the IP address with white space, read the servername and ping it. How do I get only Name and replace Type and IP address with white spaces.
- Edited by Koz0s Wednesday, January 29, 2014 2:47 PM