Sunday, December 27, 2020

power shell script to export only some columns from csv file

 


This power shell script goes through the csv file and exports the column into a filename+out.csv



 Get-ChildItem -Path . -Recurse -Filter '*.csv' |

   ForEach{

   $out  = $PSItem.Name+"_out.csv"

       $PSItem |

       Select-Object -Property FullName,

       @{Name = 'FirstLineOfFile';Expression = {Get-Content -Path $PSItem.FullName -First 1}}

   Import-Csv $PSItem.FullName   | select Phone,HomePhone,Home_Phone,Phone_1,'Phone Home',PhoneNumber,HomePhoneNumber,'Phone Number'| Export-Csv -Path $out -NoTypeInformation

   }



No comments: