Parsing a text file to get certain settings

I’ve been looking at all the posts on parsing files and I can seem to figure out how to do this? I have a file on all my servers that I would like to search for certain values, below is a piece of the text file:

So I need to get the Policy LockoutDuration with the computer setting 10080

I know that there are fixlets doing this at a Local Policy level but I need to validate GPO settings, I just run gpresults on each local server to get this information.

GPO: DMAD-ServerHardening-Comp
Policy: LockoutDuration
Computer Setting: 10080

Any help or advice is greatly appreciated

It’s not really intuitive to do this and I struggled for quite a while with multi-line parsing, but I think this will get what you need:

q: ((previous lines of it;it;next lines of it) of lines whose (it starts with "Policy: LockoutDuration") of it) of file "c:\temp\test.txt"

Given a file with multiple policies in it, that should give you just
GPO: DMAD-ServerHardening-Comp
Policy: LockoutDuration
Computer Setting: 10080

If you’re just looking for the number, you could use

q: ((following text of first ":" of next line of it as trimmed string) of lines whose (it starts with "Policy: LockoutDuration") of it) of file "c:\temp\test.txt"
A: 10080
1 Like

I am not sure what I am doing wrong but it was just a cut and paste into the Fixlet Debugger and I don’t get the values

q: ((following text of first “:” of next line of it as trimmed string) of lines whose (it starts with “Policy: LockoutDuration”) of it) of file “d:\GPO.txt”
T: 2.743 ms

q: ((previous lines of it;it;next lines of it) of lines whose (it starts with “Policy: LockoutDuration”) of it) of file “d:\GPO.txt”
T: 2.728 ms

I did use this for another text file I had to parse and it worked great, thank you, this one would be awesome if I could get it to work.

Perhaps the example of the source file is not sufficient for the relevance?

It is pretty lengthy, I just cut out one section of it.

The lines are separate lines and laid out exactly like you specified in the original?

Account Policies
----------------
GPO: DMAD-ServerHardening-Comp
Policy: LockoutDuration
Computer Setting: 10080

        GPO: DMAD-ServerHardening-Comp
            Policy:            MaximumPasswordAge
            Computer Setting:  45

        GPO: DMAD-ServerHardening-Comp
            Policy:            MinimumPasswordAge
            Computer Setting:  7

        GPO: DMAD-ServerHardening-Comp
            Policy:            ResetLockoutCount
            Computer Setting:  1440

        GPO: DMAD-ServerHardening-Comp
            Policy:            LockoutBadCount
            Computer Setting:  6

        GPO: DMAD-ServerHardening-Comp
            Policy:            PasswordHistorySize
            Computer Setting:  8

        GPO: DMAD-ServerHardening-Comp
            Policy:            MinimumPasswordLength
            Computer Setting:  6

Actually each section of it starts with:
Account Policies
----------------
Audit Policy
------------

etc…

Underneath the Policy is:

ugh, they are dashes -----

So because the the file format is different then you probably need:

q: ((previous lines of it;it;next lines of it) of lines whose (it starts with "Policy:" and it contains "LockoutDuration") of it) of file "c:\temp\test.txt"

Ok, so I think the problem is that “GPO:” is not at the start of the line - there are spaces before it. You can automatically trim the leading/trailing spaces casting “as trimmed string”. So try

q: ((previous line of it as trimmed string;it as trimmed string;next line of it as trimmed string) of lines whose (it as trimmed string starts with "Policy: LockoutDuration") of it) of file "d:\GPO.txt"

The important part in the comparison is whose (it as trimmed string starts with "Policy: LockoutDuration") of it ; the casting in the results is just for our readability.