Creating a GUI for a powershell script

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Jay Adams Jay Adams 5 months, 2 weeks ago.

  • Author
    Posts
  • #59697
    Profile photo of Jeff Scharfenberg
    Jeff Scharfenberg
    Participant

    I have this powershell script I got which connects to remote machines and shows me everything that's in their programs list.

    Function Get-RemoteProgram {
    
        [CmdletBinding(SupportsShouldProcess=$true)]
        param(
            [Parameter(ValueFromPipeline              =$true,
                       ValueFromPipelineByPropertyName=$true,
                       Position=0
            )]
            [string[]]
                $ComputerName = $env:COMPUTERNAME,
            [Parameter(Position=0)]
            [string[]]
                $Property,
            [switch]
                $ExcludeSimilar,
            [int]
                $SimilarWord
        )
    
        begin {
            $RegistryLocation = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\',
                                'SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\'
            $HashProperty = @{}
            $SelectProperty = @('ProgramName','ComputerName')
            if ($Property) {
                $SelectProperty += $Property
            }
        }
    
        process {
            foreach ($Computer in $ComputerName) {
                $RegBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer)
                $RegistryLocation | ForEach-Object {
                    $CurrentReg = $_
                    if ($RegBase) {
                        $CurrentRegKey = $RegBase.OpenSubKey($CurrentReg)
                        if ($CurrentRegKey) {
                            $CurrentRegKey.GetSubKeyNames() | ForEach-Object {
                                if ($Property) {
                                    foreach ($CurrentProperty in $Property) {
                                        $HashProperty.$CurrentProperty = ($RegBase.OpenSubKey("$CurrentReg$_")).GetValue($CurrentProperty)
                                    }
                                }
                                $HashProperty.ComputerName = $Computer
                                $HashProperty.ProgramName = ($DisplayName = ($RegBase.OpenSubKey("$CurrentReg$_")).GetValue('DisplayName'))
                                if ($DisplayName) {
                                    New-Object -TypeName PSCustomObject -Property $HashProperty |
                                    Select-Object -Property $SelectProperty
                                } 
                            }
                        }
                    }
                } | ForEach-Object -Begin {
                    if ($SimilarWord) {
                        $Regex = [regex]"(^(.+?\s){$SimilarWord}).*$|(.*)"
                    } else {
                        $Regex = [regex]"(^(.+?\s){3}).*$|(.*)"
                    }
                    [System.Collections.ArrayList]$Array = @()
                } -Process {
                    if ($ExcludeSimilar) {
                        $null = $Array.Add($_)
                    } else {
                        $_
                    }
                } -End {
                    if ($ExcludeSimilar) {
                        $Array | Select-Object -Property *,@{
                            name       = 'GroupedName'
                            expression = {
                                ($_.ProgramName -split $Regex)[1]
                            }
                        } |
                        Group-Object -Property 'GroupedName' | ForEach-Object {
                            $_.Group[0] | Select-Object -Property * -ExcludeProperty GroupedName
                        }
                    }
                }
            }
        }
    }
    

    It's quite nice to run through machines in real time to see if programs are install, etc.
    After importing the module, I use Get-RemoteProgram -Computer COMPUTERNAME | sort Programname
    then everything comes up nicely, if the machine is online.

    I'm wondering if there is any way to get this into a GUI so I could just have something open to type in the computer names and press search or something. Rather than hitting up, then changing COMPUTERNAME over and over. Something to just save time.

    Any ideas on how to do this?

    Thanks

  • #59703
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    Stephen Owen's series on GUI tool making will take you through turning a simple script into a GUI based application:

  • #59707
    Profile photo of Jay Adams
    Jay Adams
    Participant

    Take a look at System Frontier. You can easily wire up your command-line arguments to user input fields and a web form will be dynamically generated for you. No HTML code needed. Plus you get RBAC so the user doesn't have to have admin rights to run it.

You must be logged in to reply to this topic.