Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Need help writing an expression to parse data

  •  11-22-2010, 12:50 AM

    Need help writing an expression to parse data

    I'm using PowerShell 2.0 and need some help parsing performance counter data. Below are a couple sample lines I'm trying to parse:

    \\minint-q4haegq\logicaldisk(harddiskvolume1)\% free space
    \\minint-q4haegq\system\processes  

    What I'd like to do is break the above to lines into the following field lists. At a high level this data can be split by the "\".

    MachineName = \\minint-q4haegq
    ObjectName = logicaldisk
    CounterName = % free space
    InstanceName = harddiskvolume1 (this is all the data between "()", not including them)

    MachineName = \\minint-q4haegq
    ObjectName = system
    CounterName = processes
    InstanceName =  

     

    Some notes about the data:

    ·        There will always be data for MachineName, ObjectName, andCounterName.

    ·        I know how to search for the MachineName because that value isknown. However, what comes after the other "\" is completelyvariable.

    ·        After the MachineName data comes the ObjectName. Sometimes itcontains data between parentheses “()”. When it does, this data should bepulled out as the InstanceName.

    ·        The parentheses and data between (when they exist) them shouldnever be included in the ObjectName.

    ·        There are many instances where there are no parentheses. In thiscase InstanceName will be blank.

    ·        The data after the last “\” will always be Countername 

     I'm a newbie to regular expressions so if this has already been posted somewhere just point me in the right direction.

    Thanks.

     

    Nick 

     

    .

     

View Complete Thread