title: Logging output of user disable and group removal - Powershell no Quest
body: <p>I have some existing code that I've pieced together from my google searches.</p>
  
  <p>Hi All,</p>
  
  <p>I spent some time googling to find the code needed and this is what I have below.
  What I'm wanting to do is log the groups being removed from a user either.</p>
  
  <p>a) Into a local text (.log) file
  or
  b) Into the users "Notes" field.</p>
  
  <p>I've found code on how to do logging if I use quest addin, but cannot fathom how to make it fit WITHOUT using quest.</p>
  
  <p>Doing this as a learning + work functional task to make it speedier to disable users.</p>
  
  <pre><code>Import-Module activedirectory -ErrorAction silentlycontinue
  Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin -ErrorAction silentlycontinue
  $username = read-host "Username"
  $users= get-aduser $username
  
  Function RemoveMemberships
  {
  param([string]$SAMAccountName) 
  $user = Get-ADUser $SAMAccountName -properties memberof
  
  $userGroups | %{get-adgroup $_ | Remove-ADGroupMember -confirm:$false -member    $SAMAccountName}
  $userGroups | %{get-adgroup $_ | Remove-ADGroupMember -confirm:$false -member    $SAMAccountName}    $userGroups = $user.memberof
  $userGroups = $null
  }
  
  $users | %{RemoveMemberships $_.SAMAccountName}
  
  Move-ADObject $users -TargetPath "OU=Disabled Users,DC=contoso,DC=com" -PassThru | Disable-ADAccount
  </code></pre>
  
  <p>edit: The inclusion of the Exchange PSSnapin is for enhancing with disabling on GAL. I have code, but didn't include it in this.</p>