Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

replacing csv headers and RemedyBMC export

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

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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 anti-spam), the admin…
Screencast - Getting to Know the Pipeline

885 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