title: PowerShell, Exception-Handling: Create custom logfile from Set-ADUser
body: <p>I'm trying to log errors in a custom logfile while making modifications to users from Active Directory.
  Here's the code:</p>
  
  <pre><code>Get-ADUser -LDAPFilter "(objectCategory=user)" -SearchScope Subtree -SearchBase $searchBase | Set-ADUser -PasswordNeverExpires 0
  </code></pre>
  
  <p>Is it possible to check, whether the Set-ADUser command was successful for every single user and to write a custom string into a custom logfile, when the command encounteres an error? (e.g. insufficient access rights). Since those errors seem to be non-terminating, I have no idea how to solve this with try/catch.</p>