title: Export all users NOT in AAD security group with PowerShell?
body: <p>I need to export all users who are not a member of a certain security group to a CSV file, using PowerShell.</p>
  
  <p>Pretty straight forward, I know, but I can only find methods of exporting users who do meet certain criteria, not methods of exporting users who don't. I found one method that works but only with Active Directory.</p>
  
  <p>I'm currently using this to pull all users:</p>
  
  <pre><code>Get-MSOLUser -all | Where-Object { $_.isLicensed -eq "True"} | Select-Object UserPrincipalName | Export-Csv C:\365\users.csv
  </code></pre>
  
  <p>And am aiming to get something like this:</p>
  
  <pre><code>Get-MSOLUser -all | Where-Object { $_.isLicensed -eq "True", isNotMemberofGroup ""} | Select-Object UserPrincipalName | Export-Csv C:\365\users.csv
  </code></pre>
  
  <p>I am unsure how to add an additional condition that only pulls members that are not in a certain security group, using the following logic - dump upn to csv if user is licensed, and if user is not member of group xxx.</p>