title: How to log output to file
body: <p>powershell newb here. I am having some difficulty trying log my output to a file. I have tried two tactics, both of which do not work for me. The first is using the Start/Stop-Transcript cmdlet. This works great in testing on my local machine, but doesn't seem to work at all in a script that I deploy to workstations.</p>
  
  <pre><code>$path1 = Test-Path ($env:ProgramFiles + "\Sophos\Sophos Anti-Virus\SavService.exe")
  $path2 = Test-Path (${env:ProgramFiles(x86)} + "\Sophos\Sophos Anti-Virus\SavService.exe")
  $shareloc = '\\SERVER1\NETLOGON\SophosPackages\SophosInstall_wFW_Silent.exe'
  $logpath = '\\SERVER1\NETLOGON\si_sophos_log.txt'
  
  
  if (($path1 -eq $true) -or ($path2 -eq $true)) {} ELSE {
  &amp; $shareloc
  Start-Transcript -Append -Path $logpath | Out-Null
  Write-Output ""
  Get-Date
  Write-Output "Sophos has been installed on `"$env:COMPUTERNAME`""
  Write-Output ""
  Stop-Transcript
  }
  </code></pre>
  
  <p>The way I would prefer to do it, is using:  <code>| Out-File -Append -FilePath $logpath</code>
  I think this would be the preferred method because it would catch any error that might occur in the log, as apposed to Start-Transcript. When I try to use this method however, I get an error at the pipeline <code>"An empty pipeline element is not allowed."</code></p>
  
  <pre><code>$path1 = Test-Path ($env:ProgramFiles + "\Sophos\Sophos Anti-Virus\SavService.exe")
  $path2 = Test-Path (${env:ProgramFiles(x86)} + "\Sophos\Sophos Anti-Virus\SavService.exe")
  $shareloc = '\\SERVER1\NETLOGON\SophosPackages\SophosInstall_wFW_Silent.exe'
  $logpath = '\\SERVER1\NETLOGON\si_sophos_log.txt'
  
  
  if (($path1 -eq $true) -or ($path2 -eq $true)) {} ELSE {
  &amp; $shareloc
  Write-Output ""
  Get-Date
  Write-Output "Sophos has been installed on `"$env:COMPUTERNAME`""
  Write-Output ""
  } | Out-File -Append -FilePath $logpath
  </code></pre>
  
  <p>Thank you in advance for any assistance!</p>