title: Edit a script I found to import a list of adusers, grab their info and export back to another csv
body: <p>All I am needing assistance with a project.  My goal is to use powershell to search for a user and report back what groups they belong to.  </p>
  
  <p>I took the script <a href="http://community.spiceworks.com/scripts/show/1872-get-user-group-memberships" rel="nofollow">http://community.spiceworks.com/scripts/show/1872-get-user-group-memberships</a> to meet my initial needs.  </p>
  
  <pre><code>Param (
      [Parameter(Mandatory=$true,ValueFromPipeLine=$true)]
      [Alias("ID","Users","Name")]
      [string[]]$User
  )
  Begin {
      Try { Import-Module ActiveDirectory -ErrorAction Stop }
      Catch { Write-Host "Unable to load Active Directory module, is RSAT installed?"; Break }
  }
  
  Process {
      ForEach ($U in $User)
      {   $UN = Get-ADUser $U -Properties MemberOf
          $Groups = ForEach ($Group in ($UN.MemberOf))
          {   (Get-ADGroup $Group).Name
          } 
          $Groups = $Groups | Sort
          ForEach ($Group in $Groups)
          {   New-Object PSObject -Property @{
                  Name = $UN.Name
                  Group = $Group
              } |  export-csv "c:\grouptest.csv" -append
          } 
      } 
  } 
  </code></pre>
  
  <p>I was even able to get it to export the results. By adding the export-csv command.  Here is where I am running into an issue.  I do not know what to change to it grab the input from a csv and then export those results to a different csv.</p>
  
  <p>SO I want to add the command $UserList=IMPORT-CSV C:\Userlist.csv </p>
  
  <p>I tried this.  </p>
  
  <pre><code>Begin {
      Try { Import-Module ActiveDirectory -ErrorAction Stop }
      Catch { Write-Host "Unable to load Active Directory module, is RSAT installed?"; Break }
  }
  
  Process {
  $UserList=IMPORT-CSV C:\Userlist.csv
      ForEach ($U in $UserList)
      {   $UN = Get-ADUser $U -Properties MemberOf
          $Groups = ForEach ($Group in ($UN.MemberOf))
          {   (Get-ADGroup $Group).Name
          } 
          $Groups = $Groups | Sort
          ForEach ($Group in $Groups)
          {   New-Object PSObject -Property @{
                  Name = $UN.Name
                  Group = $Group
              } |  export-csv "c:\grouptest.csv" -append
          } 
      } 
  } 
  </code></pre>
  
  <p>But I keep getting an error.  It looks like it is trying to combine the first user with all the other users to make a name. </p>
  
  <p>Any help would be appericated. : ) </p>