Forms, text boxes and get-gpo

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
Tnt48185
Posts: 17
Last visit: Mon May 13, 2019 7:38 am

Re: Forms, text boxes and get-gpo

Post by Tnt48185 »

Something a little closer to home that says basically the same thing: https://www.sapien.com/blog/2012/05/16/ ... ive-forms/
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Forms, text boxes and get-gpo

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Forms, text boxes and get-gpo

Post 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.
This topic is 4 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked