Problem parsing log file using switch

Hi Im trying to parse a sequential log file using -switch -file Im
building up a variable with all the parameters of an event and then
adding the variable to an array once the event end line is reached in
the file. However each subsequent event seems to over write the entire
list. I step through the code and if i list out the $list variable it
just gives me the current values of the $event variable, even before
they have been written to $list Any help would be greatly appreciated.
Thanks


Code:
--------------------
    
  $list = @( )
  $Event = New-object -TypeName Pscustomobject 
  Add-Member -InputObject $Event -MemberType NoteProperty -Name ItemNumber    -Value $null
  Add-Member -InputObject $Event -MemberType NoteProperty -Name Start_date    -Value $null
  Add-Member -InputObject $Event -MemberType NoteProperty -Name Start_time    -Value $null
  Add-Member -InputObject $Event -MemberType NoteProperty -Name End_date        -Value $null
  Add-Member -InputObject $Event -MemberType NoteProperty -Name End_time        -Value $null
  Add-Member -InputObject $Event -MemberType NoteProperty -Name Event_Name    -Value $null
  
  switch -wildcard -file "LOG_file.txt"
  
  
  
  {
  
  "*'ItemNumber ID' `"[0-9]??????*" 
  { 
  $Event.ItemNumber = ($_ -split "`"")[1]
  #$ItemNumber
  }
  
  "*START*"
  {
  $Event.start_date =  ($_ -split " ")[0]
  $Event.start_time =  ($_ -split " ")[1]
  }
  
  "*NAME*"
  {
  $Event.Event_name = ($_ -split "`"")[1]
  }
  
  
  "*END*"
  {
  $Event.end_date =  ($_ -split " ")[0]
  $Event.end_time =  ($_ -split " ")[1]
  $Event.Event_name = $null
  $list += $event
  }
  }
  
  $event | ogv
  
--------------------


-- 
dubambman
0
dubambman
1/12/2010 12:16:34 PM
windows.powershell 690 articles. 0 followers. Follow

1 Replies
1042 Views

Similar Articles

[PageSpeed] 56

Your problem is not with "switch" but with $event. Look

## code to create $event and populate the list


 $list | % {$_.GetHashCode()}   ## determine uniqueness

nearly everything in .NET is a reference variable what you're doing is 
adding the same variable to the list M times.

What you need to do is create a new $event for each "switch" clause this 
will give you different object for each location in the array.


"dubambman" wrote:

> 
> Hi Im trying to parse a sequential log file using -switch -file Im
> building up a variable with all the parameters of an event and then
> adding the variable to an array once the event end line is reached in
> the file. However each subsequent event seems to over write the entire
> list. I step through the code and if i list out the $list variable it
> just gives me the current values of the $event variable, even before
> they have been written to $list Any help would be greatly appreciated.
> Thanks
> 
> 
> Code:
> --------------------
>     
>   $list = @( )
>   $Event = New-object -TypeName Pscustomobject 
>   Add-Member -InputObject $Event -MemberType NoteProperty -Name ItemNumber    -Value $null
>   Add-Member -InputObject $Event -MemberType NoteProperty -Name Start_date    -Value $null
>   Add-Member -InputObject $Event -MemberType NoteProperty -Name Start_time    -Value $null
>   Add-Member -InputObject $Event -MemberType NoteProperty -Name End_date        -Value $null
>   Add-Member -InputObject $Event -MemberType NoteProperty -Name End_time        -Value $null
>   Add-Member -InputObject $Event -MemberType NoteProperty -Name Event_Name    -Value $null
>   
>   switch -wildcard -file "LOG_file.txt"
>   
>   
>   
>   {
>   
>   "*'ItemNumber ID' `"[0-9]??????*" 
>   { 
>   $Event.ItemNumber = ($_ -split "`"")[1]
>   #$ItemNumber
>   }
>   
>   "*START*"
>   {
>   $Event.start_date =  ($_ -split " ")[0]
>   $Event.start_time =  ($_ -split " ")[1]
>   }
>   
>   "*NAME*"
>   {
>   $Event.Event_name = ($_ -split "`"")[1]
>   }
>   
>   
>   "*END*"
>   {
>   $Event.end_date =  ($_ -split " ")[0]
>   $Event.end_time =  ($_ -split " ")[1]
>   $Event.Event_name = $null
>   $list += $event
>   }
>   }
>   
>   $event | ogv
>   
> --------------------
> 
> 
> -- 
> dubambman
> .
> 
0
Utf
1/12/2010 10:40:01 PM
Reply:

Similar Artilces:

Highlighted word wont DEL when I use Bakspc only in office/word
When I highlight a word in and hit the Backspace key it will not delete the word, this is only in outlook and word , however I can delete using the backspace key using one key stroke at a time. In Tools > Options > Edit, check "Typing replaces selection". (In Word 2007 this option is at Office button > Word Options > Advanced.) -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. backspace key not working correctly wrote: > When I ...

File size #11
I have read the other discussions on file sizes but they do not seem to address my problem. I have an Excel file that is 12mb large with low-res jpegs in it. This file also has merged cells to make it look pretty. Does Excel look at these merged cells as graphics? Is this why they are too big? I have run a macro to make sure that it goes to the last cell. How can I get the file smaller? How big are the graphics? If you remove them from the file, what is the size of the file and what is the size of the graphic files? To be sure you do not have extra formatting, if you open the file...

Autonumber created.. problems in the future?
I managed to create an autonumber in Microsoft CRM. I did this by making a field "Number"(in the database "New_Number") and I published it on the form. Then I went To the SQL server and I changed the field in the table to Identity Yes, Identity seed 1, Identity Increment 1. I locked the field on the form. It worked! I think that this is not supported by Microsoft. But has anybody got any idea which troubles i could get with this configuration? San ________________________________ Do you know all add-ons for Microsoft CRM? Visit http://www.pimpmycrm.com The biggest dange...

find action on log file
Hello there I want to use outside tool to find who made some update on table in my server I know that there are many tools for this. But can they do it on simple recovery model? Roy Goldhammer (royg@yahoo.com) writes: > I want to use outside tool to find who made some update on table in my > server > > I know that there are many tools for this. But can they do it on simple > recovery model? No. If you are using the simple recovery model, the contents of the log is wasted away everyonce in a while. Well, if the disk area has not been overwritten...

Maximum file sizes
Is there a recommended maximum file size for Excel 2000. PC spec 2Ghz P4 with 256 Mb Any advice appreciated Deus -------------- Does Not Exist Hi have a look at http://www.decisionmodels.com/memlimits.htm -- Regards Frank Kabel Frankfurt, Germany "Deus DNE" <deus.dne@ntlworld.com> schrieb im Newsbeitrag news:1561701c41d4f$358950f0$a001280a@phx.gbl... > Is there a recommended maximum file size for Excel 2000. > > PC spec 2Ghz P4 with 256 Mb > > Any advice appreciated > > Deus > -------------- > Does Not Exist ...

Problems with reallocations in the Advanced Budget
I am a using the Advanced Budget in Money and for years I have reallocated money between categories and months. recently when I updated my transactions all my real locations were wrong. Basically the money I allocated from March to February was not only back in February it reversed it and made it look like I sent Money from February to March so now any category that I have reallocated money (an that is most) is wrong. Does anyone know of a way to fix this, I have run the repair, but that did nothing. Microsoft Money Plus Premium Version 17.0.125.1415 I am so glad to see that I am...

How to repair a .dll file in IE8
Several days ago I noticed in my Dependency Walker that the IESHIMS.dll files has a yellow circle with a question mark on it. What does this mean and How do I repair it? OS: Windows Vista Home Premium Browser Internet Explorer 8 -- TW Hi, See the History tab on that dialog. A web search for ieshims.dll files will also help you find a solution for that file. Regards. "TW" <TW@discussions.microsoft.com> wrote in message news:63E61463-D766-4ABC-B081-BFA8C04FB159@microsoft.com... > Several days ago I noticed in my Dependency Walker that the IESHIMS....

Using Relative path for XML data file?
Is there a way to specify a relative path to an XML data file imported into Excel 2003? I am writing a web app that generates report data as XML for the user to download to their local machine. This data is to be consumed by an Excel reporting spreadsheet, which contains display-formatted tables and charts that are mapped to various data fields in an XML Map, which is in turn linked to the xml data file they will download. The idea is the user only needs to download the data for updates, not the whole spreadsheet. However, since I cannot predict the path where the user will store their...

unsolicited entry in the folder "Temporary Internet Files"
Hello, I am working on a programme which browses web sites and runs under XP. The http download is as follows: pServer = Isession -> GetHttpConnection(strServerName, nPort); pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags); pFile->SendRequest(); pFile->QueryInfoStatusCode(dwStatusCode); if(dwStatusCode == 200) { pFile -> QueryInfo(HTTP_QUERY_LAST_MODIFIED, &sysT); status.lastMod = sysT; if(DBlastMod == status.lastMod) //URL content has not changed since the last visit ...

Excel button problem
Hi All I have a macro that copies a worksheet in the active workbook and puts it into a new workbook - then formats it and deletes any buttons on the worksheet. On the first click on the button the macro works ok. On the second click, it fails because the all assigned macros on all buttons in the active workbook changed from "mba" to "book1!mba". Book 1 doesn't exists (wasn't opened, wasn't saved, doesn't have the macros). I've never experienced this problem before?? Can anyone help to solve this problem? FYI The macro to do this is c...

Question -Problem
Has anybody ever seen an error message (0x800cccF6) message? I cannot configure my Outlook to retrieve Hotmail. Works with other profiles on this computer running winxp. Stan-The-Man-2006 wrote: > Has anybody ever seen an error message (0x800cccF6) message? I cannot > configure my Outlook to retrieve Hotmail. Works with other profiles > on this computer running winxp. If you have a free Hotmail account, note that it won't work anymore (even your other profiles will eventually have problems) - see http://www.slipstick.com/addins/services/online.htm#hotmail ...

AD Sync problem
Hello, One of my DC was disconnected from the network for quite a long time and cannot be synchronized with AD anymore. I have been trying to apply the http://support.microsoft.com/kb/325850/en-us procedure to reset the machine account password. After launching the command "netdom resetpwd /S: ....." I've got the following error message : "The machine account password for the local machine could not be reset. Echec d'ouverture de session : unknown user or incorrect password. The command failed to complete successfully." ANy idea to help me ? Man...

WCF Client serialization problem
I posted the problem on another forum, and to prevent duplicate posts, but get as many professionals as possible to look at it, I include the url in this post. Please help! http://stackoverflow.com/questions/2948657/migrating-webclient-to-wcf-wcf-client-serializes-parametername-of-method ...

Linking files 2 ways
I have a work book that is linked to another and vise versa. As thus: Workbook A is where the input of data is made; Workbook B has a link to the input from workbook A; Workbook A retrieves the altered data back as a link. Although this all works fine with both books open, I note that if I open workbook A by itself, that the data it retrieves from Workbook B is not updated . If However, both books are open, there's no problem. I thought linked books were updated automatically if the Update remote references has been selected?? But it appears that the second book is not updated until it ...

OL2007 not move big files from outbox to sent
Hi, We have 2 computers with separate email accounts on Roadrunner. One machine has XP with Outlook 2002-sp3 and works without any problems. The other has Outlook 2007 on Vista and has problems sending files over a meg or so in size. It seems to actually send the file but the file remains in the outbox folder and does not move it to the sent folder. I say it "seems" to send the file because some people complain of getting muliple copies and others don't seem to get them at all. If I hit send again (not set up for auto send) it seems to send the file again (why some ...

Problem with Range
Hello All, Using Windows & Excel XP. I have a worksheet that has times located in every other column, A1:A30, C1:C30, E1:E30. I then name the range "times". I want to find the count of times that are between 0:30:00 and 0:39:59 (30 and 39:59 minutes). I write the formula: =COUNTIF(times,">=" & TIME(0,30,0)) - COUNTIF(times,">=" & TIME(0,39,59)) but get the error #VALUE! I have tried writing a formula for times in one column and consecutive columns and it gives the correct count, it is just when the times in every other column that th...

outlook 97 and express email problems
Hi, I am currently on an IBM X21 laptop and is running windows 98 se with office 97 pro. I recently experienced some problems with outlook (illegal operations etc) and reinstalled office to fix the problem but since then I have not been able to send or recieve emails with outlook 97 and outlook express 6. I simply get an error message saying the host can't be found (but does exist and I can ping it successfully). Any suggestions on what I might do? I have tried creating new accounts in windows mail and outlook express, but I still get the same error. Thankyou in advance! Tim D...

Having problem with spoofing email
Our users just received multiple email from different users outside the company. In the To: line, it shows his user name correctly but when he print those email, the To: line was showing somebody else name on the print out. Is there a way to block this behavior? I'm using E2k3. For some reason our spam (postini) didn't pick up these emails. Thank you, Could you please post the message in raw format (including the mail headers) Petch wrote: > Our users just received multiple email from different users outside the > company. In the To: line, it shows his user name cor...

How to automate increasing the form cache registry/file etc...
I want to roll out a batch file to make a number of tweaks to CRM The body of it would go REGEDIT /S Kerberosefix.reg REGEDIT /S ForceFormreload.reg REGEDIT /S OutlookFix.reg It would also rename OSA.exe to OSA.bad Remove OSA.exe From the startup menu I need help finding a way to use my batch file to increase the Outlook Form cache from the default 4MB to 50 MB.. This makes CRm more stable and faster for communications. I dont want to manually do this, as it time consuming, are my end users would not be reliable in doing it themselves. I also want to make another batch file or button that...

Formula without using numbers after decimal in the answer
I have a formula that derives the answer from a figure with a decimal. I don't want to use the figures after the decimal. Is there a way to just use the whole number and omit the numbers after the decimal without having to manually key in all these numbers manually? Thanks, Mustang You can use the INT function. This 'rounds down' any number to th nearest integer, e.g. if A1=2.567, a formula in B2 of =INT(A1) return 2 HTH Bruc -- swatsp0 ----------------------------------------------------------------------- swatsp0p's Profile: http://www.excelforum.com/member.php?...

Disable Secure Sockets Layer on exchange server when using RPC over HTTP
Hi im trying to enable RPC over HTTP to enable users to establish contact to my Excahger server 2003 over the internet. Now, I dont want to use SSL (security not that important) and i am told by this article that i can disable SSL in windows registry. Quote: Note While RPC over HTTP does not require Secure Sockets Layer, you must modify the registry to enable RPC over HTTP if you do not want to use Secure Sockets Layer. Microsoft recommends that you enable and require Secure Sockets Layer for your RPC over HTTP communications. At this address: http://support.microsoft.com/?id=833401 But i ...

message delivery problems
Hello! There are several email address that when I send them an e-mail, they just sit in the Queue. I did message tracking and its telling me that "Message Routed and Queued for Remote Delivery". Can anyone suggest symptoms for this? Thank You! usually messages sitting in outgoing queue take time due to DNS related issues. Do you have issues performing NSlookups on any domains from your workstation? Can you perform the same NSlookups from the exchange server? From the exchange server, can you perform smtp communication directly to the mailserver that would receive the e...

using the journal on outlook
Once I link an email to the journal, can I still find that email in my mail box? I seem to be able to get to it only via the journal. If this is the way it is supposed to be, how do I remove it from the journal and get it back into my mail box? Am I just missing something? -- thanks, Independent Are you linking to the item or putting a copy into the journal item? Also, has the item been archived or not? "Independent" <Independent@discussions.microsoft.com> wrote in message news:868279F2-53C8-403A-97F5-604CEECD873C@microsoft.com... > Once I link an email to the journ...

CSV Files and VLOOKUP error
Does anyone know why VLOOKUP and Compare formulas don't work o information originating from a CSV file? I've tried copying an pasting values only (to leave behind any formatting), but it doesn' help. Through countless tests, I've narrowed it down to the CSV file bein the only possible cause -- Message posted from http://www.ExcelForum.com Hi ajpowers, Just a guess but the imported data may have leading or trailing spaces or are numbers stored as text. You could use the formula =A1=D1 to see if you get a true or false, where A1 is the lookup value and D1 ia the CVS valu...

Offline Synchronization Problem #2
I get the following error when I try going offline. The excelption is taken from Event Viewer of the Client Machine. Event Type: Error Event Source: MSCRMOfflineSync Event Category: None Event ID: 6000 Date: 3/25/2008 Time: 5:03:33 PM User: N/A Computer: WINXP Description: An error occurred during Offline Synchronization. Try going offline again, or restart Microsoft Outlook. saInsert failed for entity 'ActivityMimeAttachment', batchRows=0 with exception System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument li...