Module helps in creating and running WPF GUI based PowerShell Applications.
Original List of Potential Module Names to use:
PsWpfHelper WpfHelperForPS PsWpfUtils WpfUtilsForPS PsWpfLib PsXaml PsXamlHelper GuiMyPS - Collections of XAML & WPF Helper Functions to simplify creation of GUI based PowerShell Applications.
Decided on using: GuiMyPS - Module helps in creating and running WPF GUI based PowerShell Applications.
This is my PowerShell coding style requirements: Brace Styles use "K&R (Kernighan and Ritchie) style" Variables use CamelCase Operators and logical conditions use lowercase Statement Keywords use PascalCase Parameter names use PascalCase Functions should include Helpful Metadata and documentation sections which includes .NOTES as the last section before the Function Declaration NOTES section should set the Author: Brooks Vaughn and set Date to Date: to the current date as a string literal
Update the following function to comply with my coding style. Before presenting the results, fix the keywords in the result that do not comply with the coding style
Update the function to comply with my coding style. Before presenting the results, fix the keywords in the result that do not comply with the coding style
| Name | Version | PS Compatibility | Project Uri (GitHub) |
|---|---|---|---|
| GuiMyPS | 0.0.1 | 5.1 | https://github.com/BrooksV/GuiMyPS |
[PowerShell], [WPF], [XAML], [GUI]
Install-Module -Name GuiMyPS -Repository PSGallery -Scope CurrentUserTo load a local build of the module, use Import-Module as follows:
Import-Module -Name "C:\Git\GuiMyPS\dist\GuiMyPS\GuiMyPS.psd1" -Force -verbose- Tested with PowerShell 5.1 and 7.5x
- No known dependencies for usage
- VS Code and clone Brooks Vaughn's GuiMyPS Repository
- Module build process uses Manjunath Beli's ModuleTools module.
- Test scripts requires the Pester module and SQL Express
- Includes sample SQL Express database file used in test scripts
- Includes helper functions
The GuiMyPS Module was developed to support the loading of WPF (Windows Presentation Framework) XAML elements, locating elements, adding Click and other Event Handlers, and miscellaneous helper functions.
Used to prepare and load a XAML string, filepath, or XML Document returning the WPF [System.Windows.Window] form object
[System.Windows.Window]New-XamlWindow [-xaml] <Object> [-NoXRemoval] [-WhatIf] [-Confirm] [<CommonParameters>]Event handlers and code-behind logic is added to the Form Object after it's creation and before the .ShowDialog() method is called.
- For usage examples
- For examples, type: "Get-Help New-XamlWindow -Examples"
- For detailed information, type: "Get-Help New-XamlWindow -Detailed"
- For technical information, type: "Get-Help New-XamlWindow -Full"
- See WPF Guide for detailed information about WPF.
$form = New-XamlWindow -xaml $xamlString$form = New-XamlWindow -xaml MainWindows.xaml$form = New-XamlWindow -xaml [xml]$xaml- Fork the repository.
- Create a local branch for your changes.
- Make your changes and commit them.
- Push your changes to your fork.
- Create a pull request.
For detailed information on "How to Contribute", set up the development environment, and more, please refer to the Developer and Contributor Guide.
This includes details on:
- Setup
- Source Files used in the Module
- Module Build Process
- Publishing
GuiMyPSModule to GitHub - Code Review and Feedback
- Merge the Pull Request
- Cleanup
- Publishing
GuiMyPSModule to PowerShell Gallery
- Include Pester Tests
- Add comment-based help sections to all CmdLets and Functions
- Seek peer review and comments
- Integrate feedback
- Improve Documentation
- Create a comprehensive fully functional WPF PowerShell Application
Get-Command -Module "GuiMyPS" -Syntax
Add-ClickToEveryButton [-Element] <Object> [[-ClickHandler] <RoutedEventHandler>] [<CommonParameters>]
Add-ClickToEveryMenuItem [-MenuObj] <Object> [-Handler] <scriptblock> [<CommonParameters>]
Add-EventsToEveryCheckBox [-Element] <Object> [[-ClickHandler] <RoutedEventHandler>] [[-CheckedHandler] <RoutedEventHandler>] [[-UncheckedHandler] <RoutedEventHandler>] [[-PreviewMouseUpHandler] <MouseButtonEventHandler>] [-PreventSelectionScrolling] [<CommonParameters>]
Build-HandlerCode [-Elements] <Object[]> [-ControlType] <string> [<CommonParameters>]
Find-EveryControl [-ControlType] <Object> [-Element] <Object> [-ExcludeElement] [-UseVisualTreeHelper] [-IncludeAll] [<CommonParameters>]
Find-RootElement [-Element] <DependencyObject> [<CommonParameters>]
Format-XML [-xml] <xml> [[-indent] <Object>] [-FormatAttributes] [-IncludeXmlDeclaration] [<CommonParameters>]
Get-ControlContent [-Element] <Object> [<CommonParameters>]
Get-FileFromDialog [[-InitialFileName] <string>] [[-FileFilter] <string>] [[-TitleDialog] <string>] [-AllowMultiSelect] [-SaveAs] [<CommonParameters>]
Get-FormVariable [<CommonParameters>]
Get-ObjectPropertyDetail [-InputObject] <Object> [<CommonParameters>]
Get-UniqueFileName [[-Name] <string>] [-NoDate] [-AddTime] [-AddSeq] [<CommonParameters>]
New-Popup [-Message] <string> [-Title] <string> [[-Time] <int>] [[-Buttons] <string>] [[-Icon] <string>] [-WhatIf] [-Confirm] [<CommonParameters>]
New-XamlWindow [-xaml] <Object> [-NoXRemoval] [-WhatIf] [-Confirm] [<CommonParameters>]
Save-DataGridContent [-InputObject] <psobject> [[-Path] <string>] [[-SaveAs] <string>] [<CommonParameters>]
Save-DatasetToExcel [-InputObject] <psobject> [[-Path] <string>] [<CommonParameters>]
Set-Message [[-Resources] <Object>] [[-Message] <string>] [-Clear] [-NoNewline] [-NewlineBefore] [-NewlineAfter] [-WhatIf] [-Confirm] [<CommonParameters>]
- Add-ClickToEveryButton -- Adds a Click Event Handler to all buttons nested with the starting element
- Add-ClickToEveryMenuItem -- Adds a Click Event Handler to all MenuItems nested with the starting Menu Object / element
- Add-EventsToEveryCheckBox -- Adds a various Event Handlers to all CheckBoxes nested with the starting element
- Build-HandlerCode -- Generates the code for an Event Handler from a list of Elements
- Find-EveryControl -- Searches for and creates a list of elements found of a specific Control Type with options to list all controls
- Find-RootElement -- Transverse up the parent object tree looking for the root element which is the WPF form object
- Format-XML -- XML pretty formatter / printer
- Get-ControlContent -- An attempt to extract the display text for a control
- Get-FileFromDialog -- Windows Open and SaveAs FileDialog
- Get-FormVariable -- Lists the $WPF_* global variables that were created by New-XamlWindow when parsing the XAML x:Name="_elementName" names
- Get-ObjectPropertyDetail -- Dumpts the Property, Value, and Type of any PowerShell object
- Get-UniqueFileName -- Creates a Unique FileName that is TimeStamped and / or Sequence for any folder or file path
- New-Popup -- Fully functional Wscript.Shell Popup Message Box
- New-XamlWindow -- Main CmdLet that prepares and loads a WPF XAML string, filepath, or XML Document returning a WPF Form Object
- Save-DataGridContent -- Exports a DataGrid's content to Clipboard, CSV, or Excel file
- Save-DatasetToExcel -- Exports a DataSet content to an Excel file
- Set-Message -- Write messages to a XAML TextBox using a DispatcherTimer
The folder structure of the GuiMyPS module is based on best practices for PowerShell module development and was initially created using Manjunath Beli's ModuleTools module. Check out his Blog article that explains the core concepts of ModuleTools.
Install Manjunath Beli's ModuleTools module as the module build process uses ModuleTools
Find-Module -Name ModuleTools | Install-Module -Scope CurrentUser -VerboseThe the following ModuleTools CmdLets used in the build and maintenance process. They need to be executed from project root:
-
Get-MTProjectInfo -- returns HashTable of project configuration which can be used in pester tests or for general troubleshooting
-
Update-MTModuleVersion -- Increments GuiMyPS module version by modifying the values in
project.jsonor you can manually edit the json file. -
Invoke-MTBuild -- Run
Invoke-MTBuild -Verboseto build the module. The output will be saved in thedistfolder, ready for distribution. -
Invoke-MTTest -- Executes pester configuration (*.text.ps1) files in the
testsfolder -
To skip a test, add
-skipin describe block of the Pester *.test.ps1 file to skip.
.\GuiMyPS
| .gitignore
| CODE_OF_CONDUCT.md
| contributor.guide.md
| git.cheatsheet.md.ps1
| GitHub_Action_Docs.md
| LICENSE
| project.json
| ps.readinglist.md
| README.md
| wpf.guide.md
|
+---.github
| \---workflows
| tests.yml
|
+---archive
+---dist
| \---GuiMyPS
| about_GuiMyPS.help.txt
| GuiMyPS.psd1
| GuiMyPS.psm1
|
+---src
| +---private
| +---public
| | Add-ClickToEveryButton.ps1
| | Add-ClickToEveryMenuItem.ps1
| | Add-EventsToEveryCheckBox.ps1
| | Build-HandlerCode.ps1
| | Find-EveryControl.ps1
| | Find-RootElement.ps1
| | Format-XML.ps1
| | Get-ControlContent.ps1
| | Get-FormVariable.ps1
| | Get-ObjectPropertyDetail.ps1
| | New-XamlWindow.ps1
| |
| \---resources
| about_GuiMyPS.help.txt
|
\---tests
Module.Tests.ps1
OutputFiles.Tests.ps1
ScriptAnalyzer.Tests.ps1
Test-Usage-01.ps1
Test-WpfSqlQueryClassExample.ps1
TestDatabase1.mdf
TestDatabase1.parameters.psd1
TestDatabase1_log.ldfAll files and folders in the src folder, will be published Module.
All other folder and files in the .\GuiMyPS folder will resides in the GitHub GuiMyPS Repository except those excluded by inclusion in the .\GuiMyPS\.gitignore file.
The project.json file contains all the important details about your module, is used during the module build process, and helps to generate the GuiMyPS.psd1 manifest.
- .gitignore -- List of file, folder, and wildcard specifications to ignore when publishing to GitHub repository
- CODE_OF_CONDUCT.md -- Standard GitHub code of conduct and standards
- GitHub_Action_Docs.md -- How to add GitHub Action WorkFlows to automate CI/CD (Continuous Integration/Continuous Deployment)
- LICENSE -- MIT License notice and copyright
- project.json -- ModuleTools project configuration file used to build the
GuiMyPSmodule - README.md -- Documentation (this) file for the
GuiMyPSmodule - .vscode\settings.json -- VS Code settings used during
GuiMyPSmodule development - *.guide.md -- various guides such as contributor, wpf
.\GuiMyPS\archive is not used in this project. Its a temporary place / BitBucket to hold code snippets and files during development and is not part of the build.
Generated module is stored in dist\GuiMyPS folder, you can easily import it or publish it to PowerShell Gallery or repository.
- All functions in the
publicfolder are exported during the module build. - All functions in the
privatefolder are accessible internally within the module but are not exposed outside the module. - All files and folder contained in the
resourcesfolder will be published to thedist\GuiMyPSfolder.
If you want to run any pester tests, keep them in tests folder and named *.test.ps1.
Run Invoke-MTTest to execute the tests.
- .\src\public\New-XamlWindow.tests.ps1 -- Full set of usage example Tests. Good Resource for usage examples
- .\tests\Module.Tests.ps1 -- General Module Control to verify the module imports correctly
- .\tests\OutputFiles.Tests.ps1 -- Module and Manifest testing to verify output files are readable
- .\tests\ScriptAnalyzer.Tests.ps1 -- Code Quality Checks to verify PowerShell syntax and best practices
- .\tests\TestDatabase1.parameters.psd1 -- PowerShell Data File of configuration settings used in Test-WpfSqlQueryClassExample.ps1
- .\tests\TestDatabase1.mdf -- Sample SQL Express Database File with samples data used in Test-WpfSqlQueryClassExample.ps1
- .\tests\TestDatabase1_log.ldf -- Created when using TestDatabase1.mdf
We encourage you to participate in our Discussions section! Whether you have questions, ideas, or just want to chat with other users, Discussions is the place to be. Your feedback and contributions are valuable to us!
This project is licensed under the MIT License - see the LICENSE file for details.
- Manjunath Beli for the ModuleTools module used in the build process.
- Brooks Vaughn for maintaining the GuiMyPS module.
For support, inquiries, or feedback, contact Brooks Vaughn at BrooksV through one of the following methods:
- GitHub Issues: Open an issue
- GitHub Discussions: Start a discussion