Tuesday, September 27, 2011

Another Text Parsing with PowerShell

Here's a quick function example with Text Parsing in it.   :)

So when you want to just get the IP from the IPConfig , you run get-MyIP

Function get-MyIP
{
        param($outputstring)
        Process {
                If ($outputstring=ipconfig |where-object {$_-match "ipv4"} |foreach-object {$_.Split(":")[1].Trim()})
                                {
                    "Ip address : $outputstring"
                 } else {
                    "Unable to retrieve your IP"
                    }
                 }
}


As you may have noticed,  its a rather simple function .. your output look like this

PS C:\scripting> get-MyIP
Ip address : 192.168.1.6

Well, I'll be playing with more Text Parsing and share what I think are interesting .. :)

No comments:

Post a Comment