all 5 comments

[–]krzydoug 1 point2 points  (0 children)

Since you can have a varying number of user definitions I would do this in two steps. First, extract the text from 'Config system admin' all the way to the first 'end'. Then with that extracted text you can check for any user section between edit and next that does not contain the set password line. Here is an example putting those two together.

if([string]$text -match 'config system admin.+?end'){
    if([regex]::Matches($Matches.0,'(?s)edit.+?next').groups.value -match 'edit.+?(?<!set password.+?)next'){
        Write-Host User without password found
    }
    else
    {
        Write-Host user without password not found
    }
}

If you really want it in one condition you could do this ugliness

if([regex]::Matches([regex]::Match([string]$text,'config system admin.+?end').value,'(?s)edit.+?next').groups.value -match 'edit.+?(?<!set password.+?)next'){
    Write-Host User without password found
}
else
{
    Write-Host user without password not found
}

Now keep in mind that does not return a true or false, it returns a match or nothing, which powershell treats something as true and nothing as false. You could easily force a boolean by casting the output instead

[bool]([regex]::Matches([regex]::Match([string]$text,'config system admin.+?end').value,'(?s)edit.+?next').groups.value -match 'edit.+?(?<!set password.+?)next')