Combine two CSV's - Add CSV as another Column

后端 未结 2 1683
清酒与你
清酒与你 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
    

提交回复
热议问题