Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

replacing csv headers and RemedyBMC export

Posted on 2011-09-13
2
Medium Priority
?
555 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

688 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