0

Here what I want to do is get the list of the folders that have files which has the value of ErrorCode > 0.

This is what I have done till now.

$fileNames = Get-ChildItem -Path $scriptPath -Recurse -Include *.data
$FoldersToRename = @() #initialize as array
foreach ($file in $fileNames) {
    If (Get-Content $file | %{$_ -match '"ErrorCode": 0'}) 
{
 echo "matched"   
}

Now I have .data file which are being searched by this program. It contains an object with a value of "ErrorCode":value. I want to perform some operations only if that value is greater than zero.

How do I solve this?

1

1 Answer 1

1

One way to do it is like this:

Get-ChildItem -Path $scriptPath -Filter *.data | 
    ForEach-Object {
        if((Get-Content -Path $_.FullName -Raw) -match '"ErrorCode": [1-9]\d*') {
            "Matched"
        }
}
Sign up to request clarification or add additional context in comments.

1 Comment

This works for me after adjusting the regex to account for white space between the errorcode and it's value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.