Add columns to csv file

michael lustig 356 Reputation points

Hello everyone

I am trying to add columns to existing file.

I am import id from csv file..and I want to add 3 columns from active directory.

Someone can help me?


Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,008 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,416 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 31,256 Reputation points Microsoft Vendor


    The Add-Member cmdlet can add properties to an object for you.

    It could be like this

    Import-CSV D:\id.csv |  
    ForEach-Object {  
      $obj = Get-ADUser -Filter "name -eq $($" -Properties column1,column2,column3  |Select-Object column1,column2,column3    
      $_ |   
      Add-Member -MemberType NoteProperty -Name column1 -Value $obj.column1 -PassThru |  
      Add-Member -MemberType NoteProperty -Name column2 -Value $obj.column2 -PassThru |  
      Add-Member -MemberType NoteProperty -Name column3 -Value $obj.column3 -PassThru  
    } |  
    Export-CSV D:\result.csv -NoTypeInformation  

    Best Regards,
    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments