Solved

replacing csv headers and RemedyBMC export

Posted on 2011-09-13
2
554 Views
Last Modified: 2012-05-12
Hello EE,

I have a csv export from Remedy BMC (ticket tracking system) and I want to run some logic on some of the data columns in the export using psh. I am in the first stages of the task, step one is to remove the column headers and replace them with new headers. I have done this many times before using the replace parameter but this Remedy csv file is not cooperating, the headers do not change. I suspect it is the meta characters used in the column headers. Is that possible? and how do I replace the headers with "new headers" . See script below
$file = gc "C:\Documents and Settings\user\My Documents\WindowsPowerShell\augmetrics.csv" 
$existingheaders = $file[0] 
$newheaders = "`"Site`""+",`"Incident`""+ ",`"ID`""+",`"LastName`""+",`"FirstName `""+",`"ServiceType`""+",`"Summary`""+",`"Notes`""+",`"Submitter`""+",`"Assignee`""+",`"ReportedDate`""+",`"ClosedDate`""+",`"Status`""+",`"StatusReasonHidden`""+",`"OperationCatTier1`""+",`"OperationCatTier2`""+",`"OperationCatTier3`""+",`"ProductCatTier1`""+",`"ProductCatTier2`""+",`"ProductCatTier3`""+",`"Category`""+",`"ResolutionClosureSource`""+",`"ResolutionMethod`""+",`"Email`""+",`"ReportedSource`""+",`"LastModifiedDate`""+",`"LastModifiedBy`""
$file = $file -replace "$existingheaders","$newheaders"
$file | set-content  "C:\Documents and Settings\user\My Documents\WindowsPowerShell\augmetrics.csv" 
$a = import-csv "C:\Documents and Settings\user\My Documents\WindowsPowerShell\augmetrics.csv"  

Open in new window

Here is the variable output of "existing headers" and "new headers"
$existingheaders
"Site+","Incident ID*+","Last Name*+","First Name*+","Service Type*","Summary*","Notes","Submitter*","Assignee+","Reported Date+","Closed Date","Status*","Status_Reason_Hi
dden","Operational Categorization Tier 1","Operational Categorization Tier 2","Operational Categorization Tier 3","Product Categorization Tier 1","Product Categorization T
ier 2","Product Categorization Tier 3","Priority*","Resolution","Closure Source","Resolution Method","Internet E-mail(1000000048)","Reported Source","Last Modified Date","
Last Modified By"

Open in new window

$newheaders
"Site","Incident","ID","LastName","FirstName ","ServiceType","Summary","Notes","Submitter","Assignee","ReportedDate","ClosedDate","Status","StatusReasonHidden","OperationC
atTier1","OperationCatTier2","OperationCatTier3","ProductCatTier1","ProductCatTier2","ProductCatTier3","Category","ResolutionClosureSource","ResolutionMethod","Email","Rep
ortedSource","LastModifiedDate","LastModifiedBy"
 

Open in new window

0
Comment
Question by:davesnb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
Learnctx earned 500 total points
ID: 36533382
Rather than using the replace switch, it looks like you just want to replace the first line outright. So why not just set the first line to whatever you want regardless of what is currently there.
$file = gc $filelocation
$file[0]="`"Site`",`"Incident`",`"ID`",`"LastName`",`"FirstName `",`"ServiceType`",`"Summary`",`"Notes`",`"Submitter`",`"Assignee`",`"ReportedDate`",`"ClosedDate`",`"Status`",`"StatusReasonHidden`",`"OperationC
atTier1`",`"OperationCatTier2`",`"OperationCatTier3`",`"ProductCatTier1`",`"ProductCatTier2`",`"ProductCatTier3`",`"Category`",`"ResolutionClosureSource`",`"ResolutionMethod`",`"Email`",`"Rep
ortedSource`",`"LastModifiedDate`",`"LastModifiedBy`""
$file | Set-Content $filelocation

Open in new window

0
 

Author Closing Comment

by:davesnb
ID: 36535625
yup, that did it, thanks for simplifying that for me.
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question