title: Creating log file in powershell
body: <p>I have a powershell program that checks if the site is responding and retrieves data and put it inside a file using invoke-webrequest function. I want to log the response status (200 or either way) of the request with the current date and time of the request. Below is a working script. The only problem is I don't know how to concatenate my datetime variable and my status variable (separated by a space) in a single line in the log file.</p>
  
  <pre><code>    $Logfile = "D:\PROJECTS\mylog.log"
      Function LogWrite
      {
         Param ([string]$logstring)
  
         Add-content $Logfile -value $logstring
      }
      $datetime = get-date
  
      $x = invoke-webrequest -Uri http://somesite/form/Download?uid=$number"&amp;"sdate=$startdate"&amp;"edate=$enddate -OutFile D:\PROJECTS\Timekeeping\build_src\$Branch-$enddate.dat -PassThru
      if($x.StatusCode -eq 200){
          LogWrite $datetime
          LogWrite $x.StatusCode
      }else{
          LogWrite $datetime
          LogWrite $x.StatusCode
      }
  </code></pre>
  
  <p>The result of my mylog.log is:</p>
  
  <pre><code>    08/24/2016 18:43:27 its alive!
      08/24/2016 18:43:27 
      200
  </code></pre>
  
  <p>I want it to be like </p>
  
  <pre><code>    08/24/2016 18:43:27 its alive!
      08/24/2016 18:43:27 200
  </code></pre>
  
  <p>I tried </p>
  
  <pre><code>    LogWrite $datetime+$x.StatusCode
  </code></pre>
  
  <p>and </p>
  
  <pre><code>    LogWrite $datetime+" "+$x.StatusCode
  </code></pre>
  
  <p>But to no avail.</p>