title: Powershell with exchange-- How do I append all verbose output to a file
body: <p>I am trying to add some logging into my script.  Any advice would be much appreciated. To start out- I'd like to add an error log when something goes amiss.</p>
  
  <p>For instance when a user cannot be found the following error throws:</p>
  
  <p>The operation couldn't be performed because object 'asdfa' couldn't be found on 'HQ-DC-6.domain.com'.
      + CategoryInfo          : NotSpecified: (0:Int32) [Set-RemoteMailbox], ManagementObjectNotFoundException
      + FullyQualifiedErrorId : 47285FC7,Microsoft.Exchange.Management.RecipientTasks.SetRemoteMailbox
      + PSComputerName        : hq-cas2.domain.com</p>
  
  <p>==============================</p>
  
  <pre><code>$users = ForEach ($user in $(Get-Content 'C:\Users\test\Documents\Powershell Scripts\OffboardUsers.txt')) {
  
  $tmpname = Get-RemoteMailbox -Identity $user | Select-Object -ExpandProperty Name
  $tmpDisplayName = Get-RemoteMailbox -Identity $user | Select-Object -ExpandProperty DisplayName
  
  Set-RemoteMailbox -Identity $user -Name ("_" + "$tmpname") &gt;&gt; error.log
  Set-RemoteMailbox -Identity $user -DisplayName ("_" + "$tmpDisplayName") &gt;&gt; error.log
  Set-RemoteMailbox -Identity $user -HiddenFromAddressListsEnabled $true &gt;&gt; error.log
  
  }
  </code></pre>