title: Find specific sentence in a web page using powershell
body: <p>I need to use powershell to resolve IP addresses via whois. My company filters port 43 and WHOIS queries so the workaround I have to use here is to ask powershell to use a website such as <a href="https://who.is" rel="noreferrer">https://who.is</a>, read the http stream and look for the Organisation Name matching the IP address.</p>
  
  <p>So far I have managed to get the webpage read into powershell (example here with a WHOIS on yahoo.com) which is <a href="https://who.is/whois-ip/ip-address/206.190.36.45" rel="noreferrer">https://who.is/whois-ip/ip-address/206.190.36.45</a></p>
  
  <p>So here is my snippet:</p>
  
  <pre><code>$url=Invoke-WebRequest https://who.is/whois-ip/ip-address/206.190.36.45
  </code></pre>
  
  <p>now if I do :</p>
  
  <pre><code>$url.gettype()
  IsPublic IsSerial Name                                     BaseType
  -------- -------- ----                                     --------
  True     False    HtmlWebResponseObject                    Microsoft.PowerShell.Commands.WebResponseObject
  </code></pre>
  
  <p>I see this object has several properties:</p>
  
  <pre><code>Name              MemberType Definition
  ----              ---------- ----------
  Equals            Method     bool Equals(System.Object obj)
  GetHashCode       Method     int GetHashCode()
  GetType           Method     type GetType()
  ToString          Method     string ToString()
  AllElements       Property   Microsoft.PowerShell.Commands.WebCmdletElementCollection AllElements {get;}
  BaseResponse      Property   System.Net.WebResponse BaseResponse {get;set;}
  Content           Property   string Content {get;}
  Forms             Property   Microsoft.PowerShell.Commands.FormObjectCollection Forms {get;}
  Headers           Property   System.Collections.Generic.Dictionary[string,string] Headers {get;}
  Images            Property   Microsoft.PowerShell.Commands.WebCmdletElementCollection Images {get;}
  InputFields       Property   Microsoft.PowerShell.Commands.WebCmdletElementCollection InputFields {get;}
  Links             Property   Microsoft.PowerShell.Commands.WebCmdletElementCollection Links {get;}
  ParsedHtml        Property   mshtml.IHTMLDocument2 ParsedHtml {get;}
  RawContent        Property   string RawContent {get;}
  RawContentLength  Property   long RawContentLength {get;}
  RawContentStream  Property   System.IO.MemoryStream RawContentStream {get;}
  Scripts           Property   Microsoft.PowerShell.Commands.WebCmdletElementCollection Scripts {get;}
  StatusCode        Property   int StatusCode {get;}
  StatusDescription Property   string StatusDescription {get;}
  </code></pre>
  
  <p>but every time I try commands like </p>
  
  <pre><code>$url.ToString() | select-string "OrgName"
  </code></pre>
  
  <p>Powershell returns the whole HTML code because it interprets the text string as a whole. I found a workaround dumping the output into a file and then read the file through an object (so every line is an element of an array) but I have hundreds of IPs to check so that's not very optimal to create a file all the time.</p>
  
  <p>I would like to know how I could read the content of the web page <a href="https://who.is/whois-ip/ip-address/206.190.36.45" rel="noreferrer">https://who.is/whois-ip/ip-address/206.190.36.45</a> and get the line that says :
  OrgName:        Yahoo! Broadcast Services, Inc.</p>
  
  <p>and just that line only.</p>
  
  <p>Thanks very much for your help! :)</p>