Wednesday

add new fields to csv file using powershell


$z = Import-Csv zerotrac.csv
$nums= Import-Csv allleetcode.csv
$md=@{}
#converting one csv into hashmap for quicker search
foreach($r in $nums){
    $md.add($r.frontendQuestionId,$r)
}

foreach($r in $z){
    $nr=$md[$r.id]
    if ($nr){
     $r | Add-Member -MemberType NoteProperty -Name "isPaidOnly" -Value $nr.isPaidOnly
     $r | Add-Member -MemberType NoteProperty -Name "difficulty" -Value $nr.difficulty
     $r | Add-Member -MemberType NoteProperty -Name "topicTags" -Value $nr.topicTags

}

}


$z | Export-Csv -Path "C:\temp\newzerotrac1.csv" -NoTypeInformation

No comments:

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...