Combine two CSV's - Add CSV as another Column

后端 未结 2 1682
清酒与你
清酒与你 2021-01-28 20:42

I am trying to join together two csv\'s. One of the CSVs contain the column I want to add to the other but when the csv is exported the column added is blank.

$csv1

相关标签:
2条回答
  • 2021-01-28 21:21

    here you go:

    $csv1 = Import-Csv -Path ".\VLAN.csv"
    $csv2 = Import-Csv -Path ".\Hostname.csv"
    
    $arr = @()
    #If($csv1.count -eq $csv2.count){
        for($i=0; $i -lt $csv1.Count; $i++){
            $temp = New-Object psobject
            $temp | Add-Member -MemberType NoteProperty -Name VLAN -Value $csv1[$i].Vlan
            $temp | Add-Member -MemberType NoteProperty -Name HOST -Value $csv2[$i].Host
            $arr+=$temp
        }
    #}
    
    $arr | Export-Csv combined.csv -NoTypeInformation
    
    0 讨论(0)
  • 2021-01-28 21:32

    $csv1 | Join $csv2

    Results

    VLAN Host
    ---- ----
    1    NETMAN
    2    ADMIN
    3    CLIENT
    
    0 讨论(0)
提交回复
热议问题