title: Scripting a URL validity check from a text file list
body: <p>I am trying to modify the PowerShell script I have found on <a href="http://elegantcode.com/2010/11/10/powershell-url-checker-check-if-a-list-of-urls-is-valid/" rel="nofollow">ElegantCode.Com</a>. I want to change it to specify a large text file of HTTP links, rather than naming the links as a parameter individually. </p>
  
  <p>Once the script parses the file, I want it to pipe or echo out only the links that are valid back to a new file. </p>
  
  <p>I am falling at the first hurdle and can't even figure out how I pass the input file in as a parameter.</p>
  
  <p>Direct link for the script is <a href="https://github.com/staxmanade/DevMachineSetup/raw/master/GlobalScripts/Check-Url.ps1" rel="nofollow">here</a></p>
  
  <pre><code>    BEGIN {
      }
      PROCESS {
  
  $url = $_;
  
  $urlIsValid = $false
  try
  {
      $request = [System.Net.WebRequest]::Create($url)
      $request.Method = 'HEAD'
      $response = $request.GetResponse()
      $httpStatus = $response.StatusCode
      $urlIsValid = ($httpStatus -eq 'OK')
      $tryError = $null
      $response.Close()
  }
  catch [System.Exception] {
      $httpStatus = $null
      $tryError = $_.Exception
      $urlIsValid = $false;
  }
  
  $x = new-object Object | `
          add-member -membertype NoteProperty -name IsValid -Value $urlIsvalid -PassThru | `
          add-member -membertype NoteProperty -name Url -Value $_ -PassThru | `
          add-member -membertype NoteProperty -name HttpStatus -Value $httpStatus -PassThru | `
          add-member -membertype NoteProperty -name Error -Value $tryError -PassThru
  $x 
         }
        } 
        END { 
        }
  </code></pre>