Extracting text between characters

Hi Guys-

I need some help trying to extract text between two strings in a text file.  Basically I am using curl to pull information from our ticketing system and dumping it into a text file.  Here is part of the text file:

No\n\nTerminating Employee Monitor Asset Tag: \n\nTerminating Employee Workstation Asset Tag: \n\nEnable Auto Forwarding: Yes\n\nEmail Account for Forwarding:

For starters, I would like to pull the value Yes from "Enable Auto Forwarding: Yes" section.  Is there an easy way to do this with Powershell?

July 9th, 2015 8:41pm

Hi,

Here's something you can play with:

$str = 'No\n\nTerminating Employee Monitor Asset Tag: \n\nTerminating Employee Workstation Asset Tag: \n\nEnable Auto Forwarding: Yes\n\nEmail Account for Forwarding:'

$str -split '\\n\\n' |
    Where { $_ -like 'Enable Auto Forwarding:*' } | % {
     
        ($_ -split ':')[-1].Trim() |
            Where { $_ -ne '' }

}

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 8:55pm

Also:

if($str -match '\\n\\nEnable Auto Forwarding:(.*)\\n\\n'){
    $matches[1]
}else{
    Write-Host 'string not found' -fore red
}

July 9th, 2015 10:34pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics