Solved

replacing csv headers and RemedyBMC export

Posted on 2011-09-13
2
546 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
A brief introduction to what I consider to be the best editor for PowerShell.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now