Page 4 of 4

Re: Forms, text boxes and get-gpo

Posted: Fri May 10, 2019 10:51 am
by Tnt48185
Something a little closer to home that says basically the same thing: https://www.sapien.com/blog/2012/05/16/ ... ive-forms/

Re: Forms, text boxes and get-gpo

Posted: Fri May 10, 2019 11:00 am
by jvierra
Here is how to build your function so it can be easily tested and debugged in a console and then directly used in a form:

Code: Select all

$Console = $true
function logit {
    Param (
        $msg
    )
    if($Console){
        Write-Host $msg
    }else{
        $TxtBox.Lines += $msg
        $txtbox.Select($TxtBox.Text.Length, 0)
        $txtbox.ScrollToCaret()
    }
}

function Search-GpoXml{
    Param(
        [string]$SearchTerm,
        [array]$LookupXML
    )
    
    $allgpos = Get-GPO -All
    
    foreach ($gpo in $allgpos) {
        
        logit "Checking $($gpo.DisplayName) for $Searchterm"
        $path = "\\$($gpo.DomainName)\SYSVOL\$($gpo.DomainName)\Policies\{$($gpo.Id)}\*"
        $xmlpaths = Get-ChildItem $path  -Include $LookupXML -Recurse -Force | ForEach-Object { $_.fullname }
        foreach ($xmlfile in $xmlpaths) {
            logit "Parsing $xmlfile for $Searchterm"
            Start-Sleep 10
            $Searching = Get-Content $xmlfile -OutBuffer 1000
            foreach ($line in $Searching) {
                if ($line -like "*$Searchterm*") {
                    logit "Found in $GPODisp"
                    [PSCustomObject]@{
                        GPOName    = $GPO.DisplayName
                        TargetPath = $xmlfile
                        Entry      = $line
                    }
                }
            }
        }
    }
}

$aResults = Search-GpoXml -SearchTerm $searchterm -Look_XML $look_Xml

Re: Forms, text boxes and get-gpo

Posted: Fri May 10, 2019 11:22 am
by jvierra
Tnt48185 wrote:
Fri May 10, 2019 10:49 am
yeah... so, this pretty much sums up what I am seeing, why I am seeing it and what I need to do to fix it: https://stackoverflow.com/questions/352 ... uting-loop
No idea what you are referring to. Your issue is just one of coding and logic. Once you understand my code this will become obvious. The multiline textbox will update in real time using my code. Constantly rewriting the "Text" property will no work as you expect.

This has nothing to do with responsive forms. That is a completely different issue.

Adding my changes to your complete form displays all lines output into a scrollable textbox that tracks the last line added.