title: How to use obtained credentials in powershell to find groups of the Authenticated user?
body: <p>I wrote a script, which on execution asks for credentials; it goes like this;</p>
  
  <pre><code>$cred = Get-Credential #Read credentials
  $username = $cred.username
  $password = $cred.GetNetworkCredential().password
  $CurrentDomain = "LDAP://" + ([ADSI] "" ).distinguishedName
  $domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,    $UserName, $Password)
  
  if ($domain.name -eq $null)
  {
      [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
      [System.Windows.Forms.MessageBox]::Show("Authentication failed - please verify your username and password.")
      exit
  }
  else
  {
      [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
      [System.Windows.Forms.MessageBox]::Show("Authentication Success")
  
      $Groups = [System.Security.Principal.WindowsIdentity]::GetCurrent().Groups
  </code></pre>
  
  <p>-> I recognized my mistake later, the last line collects the groups of user who is logged into the windows machine.I need the groups of the person who authenticated via script; how to change this and obtain the groups for the person who authenticated into script rather the one using windows authentication?</p>
  
  <p>Please do let me know of any questions or clarifications.</p>