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.
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
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
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.