Powershell Filter Data and Copy Data to new .csv file
-
Hmmm.. I don't know how to post code here.$csvFile = ".\etc.csv" #dummy file. Change it to whereevery your file is at. $csvImport = Import-Csv $csvFile # Create Array for Exporting out data $csvArray = "" #this clear for testing purpose. But it works in production environment as well.. so I didn't bother to remove it. $csvArray = [System.Collections.ArrayList]@() # Entry count $lineCounter = 1 # Foreach Loop Foreach ($csvImportedItem in $csvImport){ $lineCounter++ #this let me know which line in the entry is the problem. $importedName = $csvImportedItem.Name $importedID = $csvImportedItem.ID $importedDept = $csvImportedItem.Department $importedNote = $csvImportedItem.Note if($importedNote -eq "C"){ $csvArray += $csvImportedItem "[$lineCounter] $importedName $importedID $importedDept $importedNote`n" #For outputing result. Testing purpose $csvImportedItem #For outputing result. Testing purpose } } $csvArray #For outputing result before exporting to new CSV #$csvArray | Export-Csv $NEWPATH -NoTypeInformation #destinate new path.
Name ID Department Note Caroline Bates 10035 Sales A Danny Harrison 11523 Customer Service B Armando Kelley 16423 Sales C Dorothy Colon 10245 HR B Joanna Sutton 19853 Accounting C Neat!
-
This site uses Markdown: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
To post code, you use three ``` before and after your code. Single line or above and below your block of code.
-
@tim_g
Thanks! site bookmarked -
If there is any possibility to copy the new content of the data from. csv to smtp mail by powershell???
-
@tim_g said in Powershell Filter Data and Copy Data to new .csv file:
This site uses Markdown: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
To post code, you use three ``` before and after your code. Single line or above and below your block of code.
This git hub is for?
-
You mean send mail using whatever the data in the CSV is?
$SmtpServer = "smtp.com" $SmtpServerPort = "25 or 587" $SmtpFrom = "[email protected]" $SmtpTo = "[email protected]" $SmtpBody = "$csvArray" $SmtpSubject = "Subject" Send-MailMessage -SmtpServer $SmtpServer -Port $SmtpServerPort -From $SmtpFrom -To $SmtpTo -subject $SmtpSubject -body $SmtpBody
-
@stess said in Powershell Filter Data and Copy Data to new .csv file:
You mean send mail using whatever the data in the CSV is?
$SmtpServer = "smtp.com" $SmtpServerPort = "25 or 587" $SmtpFrom = "[email protected]" $SmtpTo = "[email protected]" $SmtpBody = "$csvArray" $SmtpSubject = "Subject" Send-MailMessage -SmtpServer $SmtpServer -Port $SmtpServerPort -From $SmtpFrom -To $SmtpTo -subject $SmtpSubject -body $SmtpBody
Thank you so much
-
@lakshmana
You should look more into technet articles. There are plenty of guide, tips and tricks, etc. -
@stess said in Powershell Filter Data and Copy Data to new .csv file:
Hmmm.. I don't know how to post code here.$csvFile = ".\etc.csv" #dummy file. Change it to whereevery your file is at. $csvImport = Import-Csv $csvFile # Create Array for Exporting out data $csvArray = "" #this clear for testing purpose. But it works in production environment as well.. so I didn't bother to remove it. $csvArray = [System.Collections.ArrayList]@() # Entry count $lineCounter = 1 # Foreach Loop Foreach ($csvImportedItem in $csvImport){ $lineCounter++ #this let me know which line in the entry is the problem. $importedName = $csvImportedItem.Name $importedID = $csvImportedItem.ID $importedDept = $csvImportedItem.Department $importedNote = $csvImportedItem.Note if($importedNote -eq "C"){ $csvArray += $csvImportedItem "[$lineCounter] $importedName $importedID $importedDept $importedNote`n" #For outputing result. Testing purpose $csvImportedItem #For outputing result. Testing purpose } } $csvArray #For outputing result before exporting to new CSV #$csvArray | Export-Csv $NEWPATH -NoTypeInformation #destinate new path.
Name ID Department Note Caroline Bates 10035 Sales A Danny Harrison 11523 Customer Service B Armando Kelley 16423 Sales C Dorothy Colon 10245 HR B Joanna Sutton 19853 Accounting C Neat!
if there "ticket id" and "Assigned date" is there in heading means??
-
@lakshmana said in Powershell Filter Data and Copy Data to new .csv file:
@stess said in Powershell Filter Data and Copy Data to new .csv file:
Hmmm.. I don't know how to post code here.$csvFile = ".\etc.csv" #dummy file. Change it to whereevery your file is at. $csvImport = Import-Csv $csvFile # Create Array for Exporting out data $csvArray = "" #this clear for testing purpose. But it works in production environment as well.. so I didn't bother to remove it. $csvArray = [System.Collections.ArrayList]@() # Entry count $lineCounter = 1 # Foreach Loop Foreach ($csvImportedItem in $csvImport){ $lineCounter++ #this let me know which line in the entry is the problem. $importedName = $csvImportedItem.Name $importedID = $csvImportedItem.ID $importedDept = $csvImportedItem.Department $importedNote = $csvImportedItem.Note if($importedNote -eq "C"){ $csvArray += $csvImportedItem "[$lineCounter] $importedName $importedID $importedDept $importedNote`n" #For outputing result. Testing purpose $csvImportedItem #For outputing result. Testing purpose } } $csvArray #For outputing result before exporting to new CSV #$csvArray | Export-Csv $NEWPATH -NoTypeInformation #destinate new path.
Name ID Department Note Caroline Bates 10035 Sales A Danny Harrison 11523 Customer Service B Armando Kelley 16423 Sales C Dorothy Colon 10245 HR B Joanna Sutton 19853 Accounting C Neat!
if there "ticket id" and "Assigned date" is there in heading means??
use " "
So$importedID = $csvImportedItem.ID
becomes
$importedID = $csvImportedItem."ticket id"
Keep the variable simple and easy to understand.
-
@stess i get error as "Warning: one or more headers were not specified. Defaults names starting with H have been used in place of any missing headers"
there is no data copied here to. csv