title: Formatting output from Invoke-WebRequest in Powershell
body: <h2>Information</h2>
  
  <p>So what I am looking to do is scrape my local intranet where our HR team upload new starter information and be able to either hold that information in a usable format, or export it to a CSV to then be used by another script.</p>
  
  <p>Currently our service desk team manually go looking at this intranet page, and create the users based on the information our HR team enter one by one.</p>
  
  <p>Naturally, this is a very time consuming task that could be easily automated. Unfortunately, our HR team are not open for any changes to the process at the current time due to other work they are focusing on. Internal politics stuff, so sadly they can't be convinced.</p>
  
  <p>Now, I have managed to use <code>Invoke-WebRequest</code> and get the content of the page but the formatting is awful. It returns as a load of HTML and I'm iterating through multiple steps of splitting and string replacing which just doesn't feel optimal to me and I feel like there is a better way to get the results I want.</p>
  
  <h2>Current Script</h2>
  
  <pre><code>$webRequest = Invoke-WebRequest -Uri "http://intranet-site/HR/NewStarterList.php?action=ItToComp" -Headers @{"Header Info here"} -UseDefaultCredentials
  
  $content = $webRequest.Content
  
  $initialReplace = $content -replace '(?&lt;=&lt;).*?(?=&gt;)', ' '
  $split = $initialReplace -split "&lt; &gt;&lt; &gt;&lt; &gt;"
  $split = $split -split "&lt; &gt;&lt; &gt;"
  $split = $split -replace '&lt; &gt;',""
  $split = $split[5..$($split.count)]
  </code></pre>
  
  <p>As you can see, this is not really ideal, and I'm wondering if there is a better way to grab just the information I need from the page.</p>
  
  <p>The initial content returns as below (I have shortened and replaced any names to make it easy on the eye)</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;New Starter List&lt;/title&gt;
  &lt;link rel="STYLESHEET" type="text/css" href="/common/StyleSheet/Reports.css" /&gt; &lt;style&gt; TD  {font-family: Verdana; font-size: 8pt; border-left: solid 0px black; border-right: solid 0px black;}    &lt;/style&gt;
  &lt;script type="text/javascript" src="../../../cgi-bin/calendar/tableH.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;img src="/common/images/logo.gif" border="0"&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;b&gt;&lt;span style="font-size: 12pt; font-variant: small-caps; "&gt;New Starter List&lt;/span&gt;&lt;/b&gt;
  &lt;br&gt;Logged In As &amp;quot;UserName&amp;quot;&lt;br&gt;
  &lt;br&gt;
  &lt;tableonMouseOver="javascript:trackTableHighlight(this.event,'FFFF66');"onMouseOut="javascript:highlightTableRow(0);" border="4" frame="border" width="80%" rules="none" cellspacing="6%" cellpadding="6%"&gt;
  &lt;th align="left"&gt;Date Started&lt;/th&gt;
  &lt;th align="left"&gt;Name&lt;/th&gt;
  &lt;th align="left"&gt;Initials&lt;/th&gt;
  &lt;th align="left"&gt;Department&lt;/th&gt;
  &lt;th align="left"&gt;Contact&lt;/th&gt;
  &lt;th align="left"&gt;IT Completed?&lt;/th&gt;
  &lt;th align="left"&gt;Supervisor Completed?&lt;/th&gt;
  &lt;tr colspan="6"&gt;&lt;td  align="left"&gt;25 Sep 2019&lt;/td&gt;
  &lt;td  align="left"&gt;&lt;a href="NewStarterInfo.php?id=3117"&gt;Joe Bloggs&lt;/a&gt;&lt;/td&gt;
  &lt;td  align="left"&gt;JXBL&lt;/td&gt;
  &lt;td  align="left"&gt;Team A&lt;/td&gt;
  &lt;td  align="left"&gt;Manager 1&lt;/td&gt;
  &lt;td  align="left"&gt;No&lt;/td&gt;
  &lt;td  align="left"&gt;Yes&lt;/td&gt;&lt;/tr&gt;
  &lt;tr colspan="6"&gt;&lt;td  align="left"&gt;08 Jul 2019&lt;/td&gt;
  &lt;td  align="left"&gt;&lt;a href="NewStarterInfo.php?id=3149"&gt;Harry Bloggs&lt;/a&gt;&lt;/td&gt;
  &lt;td  align="left"&gt;HXBL&lt;/td&gt;
  &lt;td  align="left"&gt;Team B&lt;/td&gt;
  &lt;td  align="left"&gt;Manager 2&lt;/td&gt;
  &lt;td  align="left"&gt;No&lt;/td&gt;
  &lt;td  align="left"&gt;Yes&lt;/td&gt;&lt;/tr&gt;
  &lt;th align="left" colspan="7"&gt;72 starters&lt;/th&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>After I run my splits and replaces, It looks like below (again, names changed)</p>
  
  <pre><code>25 Sep 2019
  Joe Bloggs
  JXBL
  Team 1
  Manager 1
  No
  Yes
  08 Jul 2019
  Harry Bloggs
  HXBL
  Team 2
  Manager 2
  No
  Yes
  72 starters
  </code></pre>
  
  <p>The idea is then to be able to run with this information to automate our on-boarding process.</p>
  
  <p>I feel like I am missing something obvious, like there is a neater or more efficient way to do this, as this is the first time I'm using <code>Invoke-WebRequest</code> and finding it troublesome as it is anyway.</p>
  
  <h2>Expected Results</h2>
  
  <p>What I want is preferably an array of users with properties for each bit of info, like a CSV or a PSObject.</p>
  
  <p>So when I call a variable holding the info, I want it to return something like the below:</p>
  
  <pre><code>Name              : Joe Bloggs
  Initials          : JXBL
  Department        : Team 1
  Manager           : Manager 1
  IT                : No
  Supervisor        : No
  
  StartDate         : 08 Jul 2019
  Name              : Harry Smith
  Initials          : HXSM
  Department        : Team 2
  Manager           : Manager 2
  IT                : Yes
  Supervisor        : No
  </code></pre>
  
  <h2>Similar Questions</h2>
  
  <p>I only saw one question that looked like it may cover what I wanted, but it ended up being about needing a "try-catch" loop.
  <a href="https://stackoverflow.com/questions/54429748/how-to-change-output-of-invoke-webrequest">Similar Question Link</a></p>
  
  <p>Please let me know if you need any further information, or if you have any questions.</p>
  
  <p>Thanks in advance for the help.</p>
  
  <h2>EDIT</h2>
  
  <p>Added in an expected results bit, as I realized this was missing.</p>