title: select distinct items from a column in powershell
body: <p>If I issue following command in PowerShell, I get a lot of rows back. </p>
  
  <pre><code>PS C:\Users\benh&gt; get-command
  
  CommandType     Name                               ModuleName                         Definition
  -----------     ----                               ----------                         ----------
  Cmdlet          Get-Variable                       Microsoft.PowerShell.Utility       Get-Variable...
  Cmdlet          Get-WebAppDomain                   WebAdministration                  Get-WebAppDomain...
  Cmdlet          Get-WebApplication                 WebAdministration                  Get-WebApplication...
  Cmdlet          Get-WebAppPoolState                WebAdministration                  Get-WebAppPoolState...
  ...
  Cmdlet          Get-WinEvent                       Microsoft.PowerShell.Diagnostics   Get-WinEvent...
  Cmdlet          Get-WmiObject                      Microsoft.PowerShell.Management    Get-WmiObject...
  Cmdlet          Get-WSManCredSSP                   Microsoft.WSMan.Management         Get-WSManCredSSP...
  Cmdlet          Get-WSManInstance                  Microsoft.WSMan.Management         Get-WSManInstance...
  Cmdlet          Group-Object                       Microsoft.PowerShell.Utility       Group-Object...
  Cmdlet          Import-Alias                       Microsoft.PowerShell.Utility       Import-Alias...
  Cmdlet          Import-Clixml                      Microsoft.PowerShell.Utility       Import-Clixml...
  Cmdlet          Import-Counter                     Microsoft.PowerShell.Diagnostics   Import-Counter...
  Cmdlet          Import-Csv                         Microsoft.PowerShell.Utility       Import-Csv...
  Cmdlet          Import-LocalizedData               Microsoft.PowerShell.Utility       Import-LocalizedData...
  Cmdlet          Import-Module                      Microsoft.PowerShell.Core          ...
  </code></pre>
  
  <p>What I <em>want</em> to do is get all the distinct ModuleNames returned by Get-Command. How can I do this with PowerShell? </p>
  
  <p>In pseudo-C#:</p>
  
  <pre><code>PowerShell.Exec("Get-Command").Select(a=&gt; a.ModuleName).Distinct();
  </code></pre>
  
  <p>Thanks in advance!</p>