Using Invoke-WebRequest in Windows PowerShell

I'm very new to PowerShell scripting, but I'm trying to write a PowerShell script that will periodically check the computer's public IP address and then write it to a log file.  The website returns the IP address.  But when I use...
Invoke-WebRequest -Uri

Open in new window

...I end up with a bunch of extraneous text that I don't need.  I'd like to pipe the output to some grep-like command that will just get the IP address, and nothing else.  I've Googled around, and looked at some promising leads, but nothing seems to work for me.  Also, the response time from the command is sometimes quick, but sometimes it takes 20 seconds or more to get the output.  Not sure why that's happening.

Any suggestions would be much appreciated.  Thanks.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

$ip = Invoke-WebRequest -Uri
$ip.content -replace "[^\d\.]" 

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
That should work that way for that simple purpose, but I wouldn't use intermediate vars for values you never will use again:
(Invoke-WebRequest -Uri -replace '^\D+'

Open in new window

chernavskyAuthor Commented:
Perfect!  Thanks so much for the quick response.
chernavskyAuthor Commented:
Qlemo, thanks for the modified version.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.