Wednesday

powershell csv

    
Start-Transcript -Path result.csv
$oc = Import-Csv oldcats.csv
$nc = Import-Csv newcats.csv
#$doc=@{}
$dnc=@{}
$dncs=@{}
$found=@{}
#foreach($a in $oc){    
# $doc.Add($a.PrimaCatTypeName.ToLower())
#}

#approaching :D
#recipe_type_id,recipe_category_id,recipe_type_description
foreach($a in $nc){
  $k=$a.recipe_type_description.ToLower()
  $v="$($a.recipe_type_id),$($a.recipe_category_id), $($a.recipe_type_description)"
  if (-not $dnc.containsKey($k)){   $dnc.Add($k,$v ) }
  if (-not $dncs.containsKey($k+"s")){   $dncs.Add($k+"s",$v ) }
}

#printing oldcat results
foreach($a in $oc){
   $k=$a.PrimaCatTypeName.ToLower()
   $head="$($a.PrimaCatTypeId), `"$($a.PrimaCatTypeName)`","
  if ($dnc.containsKey($k)){           Write-Host  "$head $($dnc[$k])"  ; $found.Add($k,$k)  }
  elseif  ($dncs.containsKey($k)){     Write-Host  "$head $($dncs[$k])" ; $found.Add($k,$k)  }
  else {     Write-Host  $head    }

}


#printing new oldcat 
Write-Host ":::New cats not found:::"
foreach($a in $nc){
  $k=$a.recipe_type_description.ToLower()
  if (-not $found.containsKey($k) -and -not $found.containsKey($k+"s") ){
    $v="$($a.recipe_type_id),$($a.recipe_category_id), `"$($a.recipe_type_description)`""
    Write-Host  $v
  }
}
Stop-Transcript

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 ...