├── .github └── ISSUE_TEMPLATE │ ├── bug-report.yml │ ├── config.yml │ ├── feature-request.yml │ └── other-request.yml ├── ChangeLog.md ├── License.txt ├── PSFunctionInfo.psd1 ├── PSFunctionInfo.psm1 ├── README.md ├── docs ├── Edit-PSFunctionInfo.md ├── Get-PSFunctionInfo.md ├── Get-PSFunctionInfoDefaults.md ├── Get-PSFunctionInfoTag.md ├── New-PSFunctionInfo.md ├── Remove-PSFunctionInfo.md ├── Set-PSFunctionInfo.md ├── Set-PSFunctionInfoDefaults.md ├── Update-PSFunctionInfoDefaults.md └── about_PSFunctionInfo.md ├── en-us ├── PSFunctionInfo-help.xml └── about_PSFunctionInfo.help.txt ├── formats └── psfunctioninfo.format.ps1xml ├── functions ├── Edit-PSFunctionInfo.ps1 ├── Get-PSFunctionInfo.ps1 ├── Get-PSFunctionInfoDefaults.ps1 ├── Get-PSFunctionInfoTag.ps1 ├── New-PSFunctionInfo.ps1 ├── Remove-PSFunctionInfo.ps1 ├── Set-PSFunctionInfo.ps1 ├── Set-PSFunctionInfoDefaults.ps1 ├── Update-PSFunctionInfoDefaults.ps1 ├── private.ps1 └── public.ps1 ├── images ├── get-psfunctioninfo-1.png ├── get-psfunctioninfo-2.png ├── get-psfunctioninfo-3.png ├── get-psfunctioninfo-file.png ├── ise-function-picker.png ├── ise-psfunction-menu.png ├── ise-psfunctioninfo.png ├── psfunctioninfo-icon.png └── psfunctioninfo-vscode.png └── types └── psfunctioninfo.types.ps1xml /.github/ISSUE_TEMPLATE/bug-report.yml: -------------------------------------------------------------------------------- 1 | name: 🪲 Bug Report 2 | description: Report a bug or problem. 3 | title: "[Bug]: " 4 | labels: ["bug","triage"] 5 | assignees: 6 | - jdhitsolutions 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: "## Thank you for bringing this to our attention." 11 | - type: textarea 12 | id: description 13 | attributes: 14 | label: Describe the problem 15 | description: Please describe the bug or problem including the exact syntax you are using and any error or warning messages. 16 | validations: 17 | required: true 18 | - type: textarea 19 | id: expected-behavior 20 | attributes: 21 | label: Expectation 22 | description: What did you expect to happen? 23 | - type: textarea 24 | id: additional-info 25 | attributes: 26 | label: Additional Information 27 | description: Do you have any additional information or context that you think will be helpful in resolving this issue? 28 | - type: dropdown 29 | id: psversion 30 | attributes: 31 | label: PowerShell version 32 | description: What version of PowerShell are you running? 33 | options: 34 | - '4.0' 35 | - '5.1' 36 | - 6.x 37 | - '7.0' 38 | - '7.1' 39 | - '7.2' 40 | - Other 41 | validations: 42 | required: true 43 | - type: dropdown 44 | id: platform 45 | attributes: 46 | label: Platform 47 | description: What operating system are you running? 48 | options: 49 | - Windows 10 Home 50 | - Windows 11 Home 51 | - Windows 10 Pro or Enterprise 52 | - Windows 11 Pro or Enterprise 53 | - MacOS 54 | - Linux 55 | - Other 56 | - type: checkboxes 57 | id: checks 58 | attributes: 59 | label: Additional Checks 60 | description: Have you verified the following? 61 | options: 62 | - label: You are using the latest version of this module. 63 | required: true 64 | - label: You have read this repository's README file. 65 | - label: You have read full help and examples for the command you are having problems with. 66 | - label: You are running PowerShell in an elevated session. 67 | - label: You are running in a traditional PowerShell console or Windows Terminal 68 | 69 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: README 4 | url: https://github.com/jdhitsolutions/PSFunctionInfo/blob/main/README.md 5 | about: Open this module's README.md file. 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.yml: -------------------------------------------------------------------------------- 1 | name: 💡Feature Request 2 | description: Request a new feature or enhancement 3 | title: "[Request]: " 4 | labels: ["enhancement","triage"] 5 | assignees: 6 | - jdhitsolutions 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: "## Thank you for bringing this to our attention." 11 | - type: textarea 12 | id: description 13 | attributes: 14 | label: Describe the request 15 | description: Please describe your feature request or enhancement in detail. What deficiency does it address in the module? What use cases support your request? 16 | validations: 17 | required: true 18 | - type: dropdown 19 | id: psversion 20 | attributes: 21 | label: PowerShell version 22 | description: What version of PowerShell are you running? 23 | options: 24 | - '4.0' 25 | - '5.1' 26 | - 6.x 27 | - '7.0' 28 | - '7.1' 29 | - '7.2' 30 | - Other 31 | validations: 32 | required: false 33 | - type: dropdown 34 | id: platform 35 | attributes: 36 | label: Platform 37 | description: What operating system are you running? 38 | options: 39 | - Windows 10 Home 40 | - Windows 11 Home 41 | - Windows 10 Pro or Enterprise 42 | - Windows 11 Pro or Enterprise 43 | - MacOS 44 | - Linux 45 | - Other 46 | 47 | 48 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/other-request.yml: -------------------------------------------------------------------------------- 1 | name: 🤔Other Request or Question 2 | description: Open a request for all other issues 3 | title: "[Question]: " 4 | labels: ["question","triage"] 5 | assignees: 6 | - jdhitsolutions 7 | body: 8 | - type: textarea 9 | id: description 10 | attributes: 11 | label: Describe the question or issue 12 | description: What is on your mind? 13 | validations: 14 | required: true 15 | - type: dropdown 16 | id: psversion 17 | attributes: 18 | label: PowerShell version 19 | description: What version of PowerShell are you running? 20 | options: 21 | - '4.0' 22 | - '5.1' 23 | - 6.x 24 | - '7.0' 25 | - '7.1' 26 | - '7.2' 27 | - Other 28 | validations: 29 | required: false 30 | - type: dropdown 31 | id: platform 32 | attributes: 33 | label: Platform 34 | description: What operating system are you running? 35 | options: 36 | - Windows 10 Home 37 | - Windows 11 Home 38 | - Windows 10 Pro or Enterprise 39 | - Windows 11 Pro or Enterprise 40 | - MacOS 41 | - Linux 42 | - Other 43 | 44 | 45 | -------------------------------------------------------------------------------- /ChangeLog.md: -------------------------------------------------------------------------------- 1 | # ChangeLog for PSFunctionInfo 2 | 3 | ## [Unreleased] 4 | 5 | ## [1.5.0] - 2025-03-19 6 | 7 | ### Added 8 | 9 | - Added a default formatted list view for `Get-PSFunctionInfo` output. 10 | - Added a script property type extension for `PSFunctionInfo` objects to show `Age`. 11 | 12 | ### Changed 13 | 14 | - Replaced bitly online help links 15 | - Refined filtering regex for PSFunctionInfo objects to exclude functions that end in a colon. These are typically PSDrive shortcuts. __This is a potential breaking change.__ 16 | - Converted changelog to new format. 17 | - Updated help documentation. 18 | 19 | ## [1.4.0] - 2024-01-22 20 | 21 | ### Changed 22 | 23 | - Code cleanup 24 | - Modified `Get-PSFunctionInfo` to sort functions by name. 25 | - Help updates 26 | - Updated `README` 27 | 28 | ### Added 29 | 30 | - Added a warning to `Set-PSFunctionInfoDefaults` if the command is run without specifying any parameters. 31 | 32 | ## [1.3.0] - 2022-07-22 33 | 34 | ### Changed 35 | 36 | - Updated missing online help links. 37 | - Help documentation updates. 38 | - Updated `README.md`. 39 | 40 | ## [1.2.0] - 2022-07-22 41 | 42 | ### Added 43 | 44 | - Added custom error messages to `ValidateScript()` parameter attributes. 45 | - Added a `NoSource` parameter to `New-PSFunctionInfo` to not include the source path. 46 | - Added `Set-PSFunctionInfo` and its alias `spfi`. 47 | - Added `Remove-PSFunctionInfo` and its alias `rpfi`. 48 | 49 | ### Changed 50 | 51 | - Help updates. 52 | - Updated `README.md`. 53 | 54 | ## [1.1.0] - 2022-03-15 55 | 56 | ### Added 57 | 58 | - Added online help links. 59 | 60 | ### Updated 61 | 62 | - Updated `README.md`. 63 | 64 | ### Fixed 65 | 66 | - Fixed DefaultDisplayPropertySet in types.ps1xml file. 67 | 68 | ## [1.0.0] - 2020-10-02 69 | 70 | First official release to the PowerShell Gallery. 71 | 72 | ### Added 73 | 74 | - Added a property set called `TagInfo`. 75 | - Added command `Edit-PSFunctionInfo` with an alias of `efpi`. ([Issue #7](https://github.com/jdhitsolutions/PSFunctionInfo/issues/7)) 76 | - Added better error handling to `Get-PSFunctionInfo` where function can't be found. 77 | 78 | ### Changed 79 | 80 | - Restructured module layout. 81 | - Help updates. 82 | - Updated `README.md`. 83 | 84 | ## [0.6.0] - 2021-04-27 85 | 86 | Preview release 87 | 88 | ### Added 89 | 90 | - Added a `-Backup` parameter to `New-PSFunctionInfo`. ([Issue #1](https://github.com/jdhitsolutions/PSFunctionInfo/issues/1)) 91 | - Created private function `backup_file`. 92 | 93 | ### Changed 94 | 95 | - Help updates 96 | - Updated `README.md`. 97 | 98 | ### Fixed 99 | 100 | - Fixed the `-Name` parameter argument completer in `Get-PSFunctionInfo`. The function parameter changed from `Name` to `FunctionName` which is why it broke. ([Issue #6](https://github.com/jdhitsolutions/PSFunctionInfo/issues/6)) 101 | 102 | ## [0.5.0] - 2021-04-26 103 | 104 | Preview release 105 | 106 | ### Added 107 | 108 | - Added an auto completer for the `-Tag` parameter in `Get-PSFunctionInfo`. ([Issue #4](https://github.com/jdhitsolutions/PSFunctionInfo/issues/4)) 109 | - Added missing online help links. 110 | - Added a table view called `tags` to `psfunctioninfo.format.ps1xml`. 111 | - Added integration into the PowerShell ISE. 112 | - Added a private function, `new_psfunctioninfo`, to create a new PSFunctionInfo object from the metadata block. 113 | - Added integration into VS Code. ([Issue #2](https://github.com/jdhitsolutions/PSFunctionInfo/issues/2)) 114 | 115 | ### Changed 116 | 117 | - Changed `Name` parameter in `Get-PSFunctionInfo` to `FunctionName`. The parameter is positional, so it shouldn't make much difference. **This is a breaking change.** 118 | - Modified `Get-PSFunctionInfo` to get metadata from files. ([Issue #3](https://github.com/jdhitsolutions/PSFunctionInfo/issues/3)) 119 | - Modified `PSFunctionInfo` class to not require Tags in the constructor. 120 | - Modified `psfunctioninfo.format.ps1xml` to reduce the `Alias` column to 15. 121 | - Updated help documentation. 122 | - Updated `README.md`. 123 | 124 | ## [0.4.0] - 2021-04-22 125 | 126 | Preview release 127 | 128 | ### Added 129 | 130 | - Added `Set-PSFunctionInfoDefaults` and `Get-PSFunctionInfoDefaults` to store default values. The defaults are stored in a JSON file at `$home\psfunctioninfo-defaults.json`. If the file is found when the module is imported, it will be used to set $PSDefaultParameterValues for this module. 131 | - Added `Update-PSFunctionInfoDefaults` which can be used to update defaults if they are changed after the module has been loaded. 132 | - Added `about_PSFunctionInfo` help. 133 | 134 | ### Changed 135 | 136 | - Minor help updates. 137 | - Updated `README.md`. 138 | 139 | ## 0.3.0 - 2021-04-21 140 | 141 | Preview release published to the PowerShell Gallery. 142 | 143 | ### Added 144 | 145 | - Added online help links. 146 | 147 | ### Changed 148 | 149 | - Updated `README.md`. 150 | 151 | ## 0.2.0 - 2021-04-21 152 | 153 | ### Added 154 | 155 | - Added Verbose output to `Get-PSFunctionInfoTag`. 156 | - Added an argument completer for the `Name` parameter of `Get-PSFunctionInfo`. 157 | - Added alias `gpfi` for `Get-PSFunctionInfo`. 158 | - Added alias `npfi` for `New-PSFunctionInfo`. 159 | 160 | ## Changed 161 | 162 | - Modified `Source` view in `psfunctioninfo.format.ps1xml` to not limit the Description width. 163 | - Updated `New-PSFunctionInfo` to better handle different function layouts. 164 | - Help updates. 165 | - Updated module manifest. 166 | - Updated `README.md`. 167 | 168 | ## 0.1.0 - 2021-03-10 169 | 170 | - initial module files 171 | 172 | [Unreleased]: https://github.com/jdhitsolutions/PSFunctionInfo/compare/v1.5.0..HEAD 173 | [1.5.0]: https://github.com/jdhitsolutions/PSFunctionInfo/compare/v1.4.0..v1.5.0 174 | [1.4.0]: https://github.com/jdhitsolutions/PSFunctionInfo/compare/v1.3.0..v1.4.0 175 | [1.3.0]: https://github.com/jdhitsolutions/PSFunctionInfo/compare/v1.2.0..v1.3.0 176 | [1.2.0]: https://github.com/jdhitsolutions/PSFunctionInfo/compare/v1.1.0..v1.2.0 177 | [1.1.0]: https://github.com/jdhitsolutions/PSFunctionInfo/compare/v1.0.0..v1.1.0 178 | [1.0.0]: https://github.com/jdhitsolutions/PSFunctionInfo/compare/v0.6.0..v1.0.0 179 | [0.6.0]: https://github.com/jdhitsolutions/PSFunctionInfo/compare/v0.5.0..v0.6.0 180 | [0.5.0]: https://github.com/jdhitsolutions/PSFunctionInfo/compare/v0.4.0..v0.5.0 181 | [0.4.0]: https://github.com/jdhitsolutions/PSFunctionInfo/compare/v0.3.0..v0.4.0 -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/PSFunctionInfo/db3b6d47945420a88004a489aaa53cb8bf956e8d/License.txt -------------------------------------------------------------------------------- /PSFunctionInfo.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/PSFunctionInfo/db3b6d47945420a88004a489aaa53cb8bf956e8d/PSFunctionInfo.psd1 -------------------------------------------------------------------------------- /PSFunctionInfo.psm1: -------------------------------------------------------------------------------- 1 | Get-ChildItem $PSScriptRoot\functions\*.ps1 | ForEach-Object { 2 | . $_.FullName 3 | } 4 | 5 | #load defaults if found 6 | $defaults = Join-Path $home -ChildPath psfunctioninfo-defaults.json 7 | if (Test-Path -path $defaults) { 8 | $d = Get-Content -Path $defaults | ConvertFrom-JSON 9 | $d.PSObject.properties | Foreach-Object { 10 | $global:PSDefaultParameterValues["New-PSFunctionInfo:$($_.name)"] = $_.value 11 | } 12 | } 13 | 14 | #region Add VSCode Shortcuts 15 | if ($host.name -eq 'Visual Studio Code Host') { 16 | $global:PSDefaultParameterValues["New-PSFunctionInfo:Path"] = {$PSEditor.GetEditorContext().CurrentFile.Path} 17 | 18 | #create an argument completer for the Name parameter 19 | Register-ArgumentCompleter -CommandName New-PSFunctionInfo -ParameterName Name -ScriptBlock { 20 | param($commandName, $parameterName, $WordToComplete, $commandAst, $fakeBoundParameter) 21 | 22 | #PowerShell code to populate $WordToComplete 23 | $ASTTokens = $PSEditor.GetEditorContext().CurrentFile.tokens 24 | $NameList = @() 25 | for ($i=0;$i -lt $ASTTokens.count;$i++) { 26 | if ($ASTTokens[$i].text -eq 'function') { 27 | $NameList+= $ASTTokens[$i+1].text 28 | } 29 | } 30 | $NameList | Where-Object {$_ -like "$WordToComplete*"} | 31 | ForEach-Object { 32 | # completion text,listItem text,result type,Tooltip 33 | [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) 34 | } 35 | } 36 | } 37 | elseif ($host.name -eq 'Windows PowerShell ISE Host') { 38 | #create shortcut for the ISE 39 | $global:PSDefaultParameterValues["New-PSFunctionInfo:Path"] = {$PSIse.CurrentFile.FullPath} 40 | 41 | #add a menu item 42 | $sb = { 43 | Function PickList { 44 | # A WPF function picker for the PowerShell ISE 45 | Param([string[]]$Name) 46 | 47 | $title = "New-PSFunctionInfo" 48 | 49 | $form = New-Object System.Windows.Window 50 | #define what it looks like 51 | $form.Title = $Title 52 | $form.Height = 200 53 | $form.Width = 300 54 | $form.WindowStartupLocation = [System.Windows.WindowStartupLocation]::CenterScreen 55 | 56 | $grid = New-Object System.Windows.Controls.Grid 57 | 58 | $label = New-Object System.Windows.Controls.Label 59 | $label.Content = "Select a function from the list and click OK." 60 | $label.HorizontalAlignment = "left" 61 | $label.VerticalAlignment = "top" 62 | $grid.AddChild($label) 63 | 64 | $combo = New-Object System.Windows.Controls.ListBox 65 | $combo.AllowDrop = $true 66 | 67 | $combo.Width = 160 68 | $combo.Height = 75 69 | $combo.HorizontalAlignment = "left" 70 | $combo.VerticalAlignment = "top" 71 | $combo.Margin = "15,25,0,0" 72 | 73 | foreach ($item in $Name) { 74 | [void]$combo.items.Add($item) 75 | } 76 | $combo.SelectedIndex = 0 77 | 78 | $grid.AddChild($combo) 79 | #initialize an array to hold all processed objects 80 | 81 | $ok = New-Object System.windows.controls.button 82 | $ok.Content = "_OK" 83 | $ok.IsDefault = $True 84 | $ok.Width = 75 85 | $ok.Height = 25 86 | $ok.HorizontalAlignment = "left" 87 | $ok.Margin = "25,100,0,0" 88 | $OK.Add_Click( { 89 | $global:SelectedPickItem = $combo.SelectedItem 90 | #$combo.SelectedItem | Out-Default 91 | $form.Close() 92 | }) 93 | $grid.AddChild($ok) 94 | 95 | $cancel = New-Object System.Windows.Controls.Button 96 | $cancel.Content = "_Cancel" 97 | $cancel.Width = 75 98 | $cancel.Height = 25 99 | #$cancel.HorizontalAlignment = "right" 100 | $cancel.Margin = "150,100,0,0" 101 | $cancel.Add_Click( { 102 | $form.Close() 103 | }) 104 | 105 | $grid.AddChild($cancel) 106 | 107 | $form.AddChild($grid) 108 | [void]($form.ShowDialog()) 109 | } 110 | 111 | if ($PSIse.CurrentFile.IsSaved) { 112 | $Path = $PSIse.CurrentFile.FullPath 113 | 114 | New-Variable ASTTokens -Force 115 | New-Variable astErr -Force 116 | $AST = [System.Management.Automation.Language.Parser]::ParseFile($Path, [ref]$ASTTokens, [ref]$astErr) 117 | 118 | $file = [System.Collections.Generic.list[string[]]]::new() 119 | Get-Content $path | ForEach-Object { $file.Add($_) } 120 | 121 | $name = @() 122 | for ($i = 0; $i -lt $ASTTokens.count; $i++) { 123 | if ($ASTTokens[$i].text -eq 'function') { 124 | $name += $ASTTokens[$i + 1].text 125 | } 126 | } #for 127 | if ($name) { 128 | Remove-Variable -Name SelectedPickItem -ErrorAction SilentlyContinue 129 | PickList -name $name 130 | #| Out-GridView -Title "Select a function" -OutputMode Single 131 | 132 | if ($SelectedPickItem) { 133 | New-PSFunctionInfo -Name $SelectedPickItem -path $path 134 | 135 | $idx = $file.findIndex( { $args[0] -match "[Ff]unction(\s+)$SelectedPickItem" }) 136 | $idx++ 137 | #save and re-open the file 138 | [void]$PSIse.CurrentPowerShellTab.files.Remove($PSIse.CurrentFile) 139 | [void]$PSIse.CurrentPowerShellTab.Files.Add($path) 140 | $r = $PSIse.CurrentPowerShellTab.Files.where( { $_.FullPath -eq $path }) 141 | $r.Editor.Focus() 142 | 143 | if ($idx -ge 0) { 144 | $r.Editor.SetCaretPosition($idx, 1) 145 | $r.Editor.SelectCaretLine() 146 | $r.Editor.EnsureVisible($idx) 147 | } 148 | } 149 | } #if names found 150 | else { 151 | [System.Windows.MessageBox]::Show("No matching functions found in $Path", "New-PSFunctionInfo", "OK", "Information") 152 | } 153 | } #if saved 154 | else { 155 | [System.Windows.MessageBox]::Show("Please save your file first:$Path and then try again.", "New-PSFunctionInfo", "OK", "Warning") 156 | } 157 | } 158 | 159 | $PSIse.CurrentPowerShellTab.AddOnsMenu.Submenus.add("New-PSFunctionInfo", $sb, $Null) 160 | } 161 | #endregion 162 | 163 | #region create argument completers 164 | Register-ArgumentCompleter -CommandName Get-PSFunctionInfo -ParameterName FunctionName -ScriptBlock { 165 | param($commandName, $parameterName, $WordToComplete, $commandAst, $fakeBoundParameter) 166 | 167 | Get-ChildItem -path "Function:\$WordToComplete*" | 168 | ForEach-Object { 169 | # completion text,listItem text,result type,Tooltip 170 | [System.Management.Automation.CompletionResult]::new($_.name, $_.name, 'ParameterValue', $_.name) 171 | } 172 | } 173 | 174 | Register-ArgumentCompleter -CommandName Get-PSFunctionInfo -ParameterName Tag -ScriptBlock { 175 | param($commandName, $parameterName, $WordToComplete, $commandAst, $fakeBoundParameter) 176 | 177 | (Get-PSFunctionInfoTag).where({$_ -like "$WordToComplete*"}) | 178 | ForEach-Object { 179 | # completion text,listItem text,result type,Tooltip 180 | [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) 181 | } 182 | } 183 | #endregion 184 | 185 | #region type extensions 186 | 187 | Update-TypeData -TypeName PSFunctionInfo -MemberType ScriptProperty -MemberName Age -Value { 188 | New-TimeSpan -Start $this.LastUpdate -end (Get-Date) 189 | } -Force 190 | 191 | #endregion -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PSFunctionInfo 2 | 3 | [![PSGallery Version](https://img.shields.io/powershellgallery/v/PSFunctionInfo.png?style=plastic&logo=powershell&label=PowerShell%20Gallery)](https://www.powershellgallery.com/packages/PSFunctionInfo/) ![PSGallery Downloads](https://img.shields.io/powershellgallery/dt/PSFunctionInfo.png?style=plastic&&logo=powershell&label=Downloads) 4 | 5 | ## Synopsis 6 | 7 | ![documents](images/psfunctioninfo-icon.png) 8 | 9 | This module contains a set of PowerShell commands to add and manage metadata in stand-alone PowerShell functions. 10 | 11 | ## Installation 12 | 13 | You can install this module from the PowerShell Gallery. 14 | 15 | ```powershell 16 | Install-Module PSFunctionInfo -Force [-scope CurrentUser] 17 | ``` 18 | 19 | Or using `PSResourceGet`: 20 | 21 | ```powershell 22 | Install-PSResource PSFunctionInfo [-scope CurrentUser] 23 | ``` 24 | 25 | The module should work on both Windows PowerShell and PowerShell 7, even cross-platform, except for a few PowerShell ISE related commands. 26 | 27 | ## Description 28 | 29 | The purpose of this code is to provide a way to get versioning and other metadata information for functions that do not belong to a module. This is information you want to get after the function has been loaded into your PowerShell session. I have numerous stand-alone functions. These functions don't belong to a module, so there is no version or source information. However, I'd like to have that type of information for non-module functions. 30 | 31 | The code in this module isn't concerned with loading, running, or finding functions. By default, [Get-PSFunctionInfo](docs/Get-PSFunctionInfo.md) queries whatever is in the `Function:` PSDrive. If the PowerShell function belongs to a module, then you'll get the module version and source. Otherwise, the command will use the function metadata. 32 | 33 | ![Get a single function](images/get-psfunctioninfo-1.png) 34 | 35 | The default behavior is to show all functions that __don't__ belong to a module and excluding a few common functions that PowerShell defines. 36 | 37 | ![Get stand-alone functions](images/get-psfunctioninfo-2.png) 38 | 39 | You can also get currently loaded functions by tag. Use `Get-PSFunctionInfoTag` to get a list of tags currently in use. 40 | 41 | ![Get functions by tag](images/get-psfunctioninfo-3.png) 42 | 43 | The PSFunctionInfo object includes a PropertySet called `AuthorInfo`. 44 | 45 | ```dos 46 | PS C:\> Get-PSFunctionInfo -Tag modules | Select-Object -property AuthorInfo 47 | 48 | Name : Test-HelpLink 49 | Version : 0.9.0 50 | Source : C:\scripts\update-helplinks.ps1 51 | CompanyName : JDH IT Solutions, Inc. 52 | Copyright : (c) JDH IT Solutions, Inc. 53 | Description : Test if help file is missing the online link 54 | LastUpdate : 4/23/2024 9:21:00 AM 55 | ``` 56 | 57 | Or you can use the `TagInfo` property set. This gives you the same result as using the `tag` named view with `Format-Table`., 58 | 59 | ```powershell 60 | Get-PSFunctionInfo | Select-Object taginfo 61 | ``` 62 | 63 | Finally, you can also search .ps1 files for PSFunctionInfo metadata. 64 | 65 | ![Get function info from file](images/get-psfunctioninfo-file.png) 66 | 67 | ## Creating PSFunctionInfo 68 | 69 | Use the [New-PSFunctionInfo](docs/New-PSFunctionInfo.md) command to insert the metadata tag into your script file. 70 | 71 | ```powershell 72 | New-PSFunctionInfo -Path c:\scripts\Test-ConsoleColors.ps1 -Description "show console color combinations" -Name Test-ConsoleColor -Author "Jeff Hicks" -CompanyName "JDH IT Solutions" -Copyright "2024 JDH IT Solutions, Inc." -Tags "scripting","console" 73 | ``` 74 | 75 | The default behavior is to insert the metadata tag immediately after the opening brace (`{`) into the file. __This command will update the file__. Or you can use the `ToClipBoard` parameter which will copy the metadata to the clipboard. You can then manually insert it into your script file that defines the function. You should avoid changing the formatting of the comment block. 76 | 77 | You should get something like this: 78 | 79 | ```text 80 | 81 | <# PSFunctionInfo 82 | 83 | Version 1.0.0 84 | Author Jeff Hicks 85 | CompanyName JDH IT Solutions 86 | Copyright 2024 JDH IT Solutions, Inc. 87 | Description show console color combinations 88 | Guid 8e43a9d9-1df6-48c7-8595-7363087aba43 89 | Tags scripting,console 90 | LastUpdate 2/22/2024 10:43 AM 91 | Source C:\scripts\Test-ConsoleColors.ps1 92 | 93 | #> 94 | ``` 95 | 96 | This command will __not work__ with functions defined in a single line like: 97 | 98 | ```powershell 99 | Function Get-Foo { Get-Date } 100 | ``` 101 | 102 | However, you could run `New-PSFunctionInfo` with the `ToClipboard` parameter and manually edit your function to insert the metadata. 103 | 104 | ```powershell 105 | Function Get-Foo { 106 | 107 | <# PSFunctionInfo 108 | 109 | Version 1.0.0 110 | Author Jeff Hicks 111 | CompanyName JDH IT Solutions 112 | Copyright 2024 JDH IT Solutions, Inc. 113 | Description Get Foo Stuff 114 | Guid 490595c6-6a0c-4572-baf4-f808c010de70 115 | Tags scripting,console 116 | LastUpdate 2/21/2024 10:41 AM 117 | Source C:\scripts\FooStuff.ps1 118 | 119 | #> 120 | Get-Date 121 | } 122 | ``` 123 | 124 | ### Backup 125 | 126 | Because creating a PSFunctionInfo metadata comment block modifies the file, you might feel safer with a file backup. `New-PSFunctionInfo` has a `-BackupParameter` which will create a backup copy of the source file before inserting the metadata comment block. The file will be created in the same directory, appending an extension of .bak1. If there are previous backups, the number will increment, i.e. .bak2. You have to manually delete the backup files. 127 | 128 | The `-Backup` parameter has no effect if you use `-Clipboard`. 129 | 130 | ## PSFunctionInfo Defaults 131 | 132 | Because you might define function metadata often and want to maintain consistency, you can define a set of default values for `New-PSFunctionInfo`. Use the command, [Set-PSFunctionInfoDefaults](docs/Set-PSFunctionInfoDefaults): 133 | 134 | ```powershell 135 | Set-PSFunctionInfoDefaults -Tags "stand-alone" -Copyright "(c) JDH IT Solutions, Inc." -author "Jeff Hicks" -company "JDH IT Solutions, Inc." 136 | ``` 137 | 138 | The defaults will be stored in a JSON file (`$HOME\psfunctioninfo-defaults.json`). When you import this module, the values from this file will be used to define entries in `$PSDefaultParameterValues`. Or, run [Update-PSFunctionInfoDefaults](docs/Update-PSFunctionInfoDefaults) to update parameter defaults. 139 | 140 | You can use [Get-PSFunctionInfoDefaults](docs/Get-PSFunctionInfoDefaults.md) to see the current values. 141 | 142 | ```powershell 143 | PS C:\> Get-PSFunctionInfoDefaults 144 | 145 | Version : 0.9.0 146 | CompanyName : JDH IT Solutions, Inc. 147 | Author : Jeffery Hicks 148 | Tags : {stand-alone} 149 | Copyright : (c) JDH IT Solutions, Inc. 150 | ``` 151 | 152 | ## Editor Integration 153 | 154 | When you import the module into an editor, you will get additional features to make it easier to insert PSFunctionInfo metadata into your file. It is recommended that you explicitly import the module into the editor's integrated console session. You could add an `Import-Module PSFunctionInfo` command into the editor's PowerShell profile script. 155 | 156 | ### Visual Studio Code 157 | 158 | If you have an open file, in the integrated PowerShell console, you can run `New-PSFunctionInfo` and press TAB to tab-complete the detected functions in the current file. The file path will automatically be detected. You can enter other values such as version, or simply press ENTER to insert the metadata, which you can then edit. 159 | 160 | ![VSCode integration](images/psfunctioninfo-vscode.png) 161 | 162 | This example is taking advantage of saved defaults. See [`Set-PSFunctionInfoDefaults`](docs/Set-PSFunctionInfoDefaults.md) 163 | 164 | ### PowerShell ISE 165 | 166 | When you import the module in the PowerShell ISE, it will add a menu shortcut. 167 | 168 | ![ISE Menu](images/ise-psfunction-menu.png) 169 | 170 | With a loaded file, you could run `New-PSFunctionInfo` in the console specifying the function name. The Path will be auto-detected. Or use the menu shortcut which will give you a graphical "function picker" 171 | 172 | ![function picker](images/ise-function-picker.png) 173 | 174 | Select a function and click OK. The metadata block will be inserted into the file. This will not work with a file that has unsaved changes. When you insert new function metadata, the file in the ISE will be closed, re-opened and focus should jump to the function. 175 | 176 | ![ISE metadata](images/ise-psfunctioninfo.png) 177 | 178 | ### Editing Source Files 179 | 180 | The module has a command called [Edit-PSFunctionInfo](docs/Edit-PSFunctionInfo.md) which will open a source file in your preferred editor. The command has an alias of `epfi`. The default editor selection is VS Code, but you can specify the PowerShell ISE or Notepad. 181 | 182 | You can either specify a loaded function by name: 183 | 184 | ```powershell 185 | Edit-PSFunctionInfo Get-QOTD 186 | ``` 187 | 188 | Or pipe to it. 189 | 190 | ```powershell 191 | Get-PSFunctionInfo Get-QOTD | Edit-PSFunctionInfo -editor ise 192 | ``` 193 | 194 | Once opened, you will need to navigate to the appropriate function and metadata section. 195 | 196 | It is assumed you will normally edit function metadata when editing the script file. But you can use [`Set-PSFunctionInfo](docs/Set-PSFunctionInfo.md) to make changes from the console. 197 | 198 | ```powershell 199 | PS C:\> Set-PSFunctionInfo -Name Get-EventlogInfo -Path c:\work\LogTools.ps1 -Tags "profile,eventlog" -Version "1.2.1" 200 | ``` 201 | 202 | If you want to clear an existing value, set the parameter value to `$null`. 203 | 204 | ```powershell 205 | PS C:\> Set-PSFunctionInfo -Name Get-EventlogInfo -Path c:\work\LogTools.ps1 -Source $null 206 | ``` 207 | 208 | ## Background 209 | 210 | This code is a prototype for a [suggestion](https://github.com/PowerShell/PowerShell/issues/11667) I made for PowerShell 7. Early versions of this code were published as [https://gist.github.com/jdhitsolutions/65070cd51b5cfb572bc6375f67bcbc3d](https://gist.github.com/jdhitsolutions/65070cd51b5cfb572bc6375f67bcbc3d "view the Github gist") 211 | 212 | This module was first described at . 213 | 214 | ## Related Modules 215 | 216 | :bulb: You might also be interested in the [PSFunctionTools](https://github.com/jdhitsolutions/PSFunctionTools) module which contains a set of PowerShell 7 tools for automating and accelerating script and module development. 217 | 218 | ## Roadmap 219 | 220 | - Add function metadata by file, auto-detecting the function name. 221 | - Consider a bulk removal command to clean PSFunctionInfo metadata from files. 222 | -------------------------------------------------------------------------------- /docs/Edit-PSFunctionInfo.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSFunctionInfo-help.xml 3 | Module Name: PSFunctionInfo 4 | online version: https://jdhitsolutions.com/yourls/06a244 5 | schema: 2.0.0 6 | --- 7 | 8 | # Edit-PSFunctionInfo 9 | 10 | ## SYNOPSIS 11 | 12 | Open a source file in your preferred editor. 13 | 14 | ## SYNTAX 15 | 16 | ### name (Default) 17 | 18 | ```yaml 19 | Edit-PSFunctionInfo [-Name] [-Editor ] [] 20 | ``` 21 | 22 | ### source 23 | 24 | ```yaml 25 | Edit-PSFunctionInfo [-Source ] [[-Name] ] [-Editor ] [] 26 | ``` 27 | 28 | ## DESCRIPTION 29 | 30 | You can use Edit-PSFunctionInfo to open the source file for a given function with PSFunctionInfo metadata. You can either specify a loaded function by name, or pipe a Get-PSFunctionInfo expression to Edit-PSFunctionInfo. Once the function is opened in the editor, you will need to navigate to the function itself. 31 | 32 | The editor choices are VS Code, PowerShell ISE, or Notepad. Of course they are also dependent on your operating system and if you have installed it. 33 | 34 | ## EXAMPLES 35 | 36 | ### Example 1 37 | 38 | ```powershell 39 | PS C:\> Edit-PSFunctionInfo -name Set-Title -editor ise 40 | ``` 41 | 42 | Open the source file for the Set-Title function and open in the PowerShell ISE. This assumes the Set-Title function is currently loaded into your PowerShell session. 43 | 44 | ### Example 2 45 | 46 | ```powershell 47 | PS C:\> Get-PSFunctionInfo *git* | Edit-PSFunctionInfo 48 | ``` 49 | 50 | Get all functions with git in the name and edit them with the default editor. 51 | 52 | ## PARAMETERS 53 | 54 | ### -Editor 55 | 56 | Specify the editor you want to use. 57 | On non-Windows systems enter the value in lower case. 58 | 59 | ```yaml 60 | Type: String 61 | Parameter Sets: (All) 62 | Aliases: 63 | Accepted values: code, ise, notepad 64 | 65 | Required: False 66 | Position: Named 67 | Default value: code 68 | Accept pipeline input: False 69 | Accept wildcard characters: False 70 | ``` 71 | 72 | ### -Name 73 | 74 | The name of a loaded function, presumably with PSFunctionInfo metadata. 75 | 76 | ```yaml 77 | Type: String 78 | Parameter Sets: name 79 | Aliases: 80 | 81 | Required: True 82 | Position: 0 83 | Default value: None 84 | Accept pipeline input: False 85 | Accept wildcard characters: False 86 | ``` 87 | 88 | ```yaml 89 | Type: String 90 | Parameter Sets: source 91 | Aliases: 92 | 93 | Required: False 94 | Position: 0 95 | Default value: None 96 | Accept pipeline input: False 97 | Accept wildcard characters: False 98 | ``` 99 | 100 | ### -Source 101 | 102 | Specify the path to the source file. 103 | 104 | ```yaml 105 | Type: String 106 | Parameter Sets: source 107 | Aliases: 108 | 109 | Required: False 110 | Position: Named 111 | Default value: None 112 | Accept pipeline input: True (ByPropertyName, ByValue) 113 | Accept wildcard characters: False 114 | ``` 115 | 116 | ### CommonParameters 117 | 118 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 119 | 120 | ## INPUTS 121 | 122 | ### System.String 123 | 124 | ## OUTPUTS 125 | 126 | ### None 127 | 128 | ## NOTES 129 | 130 | This command has an alias of epfi. 131 | 132 | Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter 133 | 134 | ## RELATED LINKS 135 | 136 | [Get-PSFunctionInfo](Get-PSFunctionInfo.md) 137 | 138 | [New-PSFunctionInfo](New-PSFunctionInfo.md) 139 | -------------------------------------------------------------------------------- /docs/Get-PSFunctionInfo.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSFunctionInfo-help.xml 3 | Module Name: PSFunctionInfo 4 | online version: https://jdhitsolutions.com/yourls/1f9f84 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-PSFunctionInfo 9 | 10 | ## SYNOPSIS 11 | 12 | Get metadata for stand-alone functions. 13 | 14 | ## SYNTAX 15 | 16 | ### name (Default) 17 | 18 | ```yaml 19 | Get-PSFunctionInfo [-FunctionName ] [-Tag ] [] 20 | ``` 21 | 22 | ### file 23 | 24 | ```yaml 25 | Get-PSFunctionInfo [-Path ] [-Tag ] [] 26 | ``` 27 | 28 | ## DESCRIPTION 29 | 30 | Get-PSFunctionIfo will display function metadata that was created using New-PSFunctionInfo. The default behavior is to search loaded functions that don't belong to a module and display the custom function metadata. 31 | 32 | As an alternative to searching items in the Function: PSDrive, you can also search .ps1 files. If you specify the path to a script file, you will get function metadata for every defined function in the file. 33 | 34 | ## EXAMPLES 35 | 36 | ### Example 1 37 | 38 | ```powershell 39 | PS C:\> Get-PSFunctionInfo 40 | 41 | Name Version Alias Source 42 | ---- ------- ----- ------ 43 | prompt 44 | Get-QOTD 2.0.0 qotd C:\scripts\Get-QOTD.ps1 45 | Get-Status 2.1.0 gst C:\scripts\getstat.ps1 46 | Get-StatusString 1.1.0 gss C:\scripts\getstat.ps1 47 | Convert-Expression 1.0.0 spoof C:\scripts\Convert-Expression... 48 | Add-BackupEntry 1.3.0 abe C:\scripts\PSBackup\Add-Backu... 49 | Get-MyBackupFile 1.0.0 gbf C:\scripts\PSBackup\Get-MyBac... 50 | ConvertTo-ASCIIArt cart 51 | Test-IsAdministrator 1.0.0 C:\Scripts\JDH-Functions.ps1 52 | Open-VSCode 2.0.0 code C:\Scripts\JDH-Functions.ps1 53 | ... 54 | ``` 55 | 56 | ### Example 2 57 | 58 | ```powershell 59 | PS C:\> Get-PSFunctionInfo -name get* | Select Name,Source 60 | 61 | Name Source 62 | ---- ------ 63 | Get-QOTD C:\scripts\Get-QOTD.ps1 64 | Get-Status C:\scripts\getstat.ps1 65 | Get-UTCString C:\Scripts\JDH-Functions.ps1 66 | Get-DiskFree C:\Scripts\JDH-Functions.ps1 67 | Get-LastBoot C:\Scripts\JDH-Functions.ps1 68 | Get-ModifiedFile C:\Scripts\JDH-Functions.ps1 69 | Get-MyFunctions C:\Scripts\JDH-Functions.ps1 70 | ``` 71 | 72 | Get function information by the function name. 73 | 74 | ### Example 3 75 | 76 | ```powershell 77 | PS C:\> Get-PSFunctionInfo | Sort Source | Format-Table -View Source 78 | 79 | 80 | Source: 81 | 82 | Name Version Description 83 | ---- ------- ----------- 84 | tm profile-defined 85 | Hide-Git profile-defined 86 | Get-LogStamp profile-defined 87 | dt profile-defined 88 | ConvertTo-ASCIIArt profile-defined 89 | prompt 90 | 91 | 92 | Source: C:\scripts\Convert-Expression.ps1 93 | 94 | Name Version Description 95 | ---- ------- ----------- 96 | Convert-Expression 1.0.0 Spoof command output 97 | 98 | 99 | Source: C:\Scripts\JDH-Functions.ps1 100 | 101 | Name Version Description 102 | ---- ------- ----------- 103 | Get-DiskFree 1.0.0 My version of the df command 104 | Get-ModifiedFile 1.1.0 find all files of modified within a given.. 105 | Get-LastFile 2.1.0 Get files sorted by last modified date 106 | Get-LastBoot 1.0.0 Get the last boot up time 107 | ... 108 | ``` 109 | 110 | Use the custom table view called Source. 111 | 112 | ### Example 4 113 | 114 | ```powershell 115 | PS C:\> Get-PSFunctionInfo -Tag cim 116 | 117 | Name Version Alias Source 118 | ---- ------- ----- ------ 119 | Get-Status 2.1.0 gst C:\scripts\getstat.ps1 120 | Get-StatusString 1.1.0 gss C:\scripts\getstat.ps1 121 | ``` 122 | 123 | Get functions by tag. 124 | 125 | ### Example 5 126 | 127 | ```powershell 128 | PS C:\> Get-PSFunctionInfo Get-qotd | Select-Object * 129 | 130 | Name : Get-QOTD 131 | Version : 2.0.0 132 | Source : C:\scripts\Get-QOTD.ps1 133 | CompanyName : JDH IT Solutions 134 | Copyright : 2020 135 | Description : Get a quote of the day 136 | LastUpdate : 5/21/2020 5:56:01 PM 137 | Module : 138 | Path : C:\scripts\Get-QOTD.ps1 139 | Alias : qotd 140 | Author : Jeff 141 | Guid : 16b5d672-4778-46d9-bbe5-08e7860e4e8a 142 | Tags : {Web,profile} 143 | Commandtype : Function 144 | ``` 145 | 146 | Get all properties for a single function. 147 | 148 | ### Example 6 149 | 150 | ```powershell 151 | PS C:\> dir C:\scripts\*.ps1 | Get-PSFunctionInfo 152 | 153 | Name Version Alias Source 154 | ---- ------- ----- ------ 155 | Add-BackupEntry 1.0.0 abe C:\scripts\Add-BackupEntry.ps1 156 | Get-MyFunctions 1.0.0 C:\Scripts\archived-Functions... 157 | Convert-Expression 1.0.0 spoof C:\scripts\Convert-Expression... 158 | Get-LastPassItem 1.0.0 glp C:\Scripts\Get-LastPassItem.ps1 159 | Get-QOTD 2.0.0 qotd C:\scripts\Get-QOTD.ps1 160 | ... 161 | ``` 162 | 163 | Search script files for function metadata. 164 | 165 | ### Example 7 166 | 167 | ```powershell 168 | PS C:\> Get-PSFunctionInfo -Tag modules | Select-Object -property AuthorInfo 169 | 170 | 171 | Name : Test-HelpLink 172 | Version : 0.9.0 173 | Source : C:\scripts\update-helplinks.ps1 174 | CompanyName : JDH IT Solutions, Inc. 175 | Copyright : (c) JDH IT Solutions, Inc. 176 | Description : Test if help file is missing the online link 177 | LastUpdate : 4/23/2023 9:21:00 AM 178 | ``` 179 | 180 | The PSFunctionInfo object includes a PropertySet called AuthorInfo. 181 | 182 | ### Example 8 183 | 184 | ```powershell 185 | 186 | PS C:\> Get-PSFunctionInfo -Path C:\work\sample.ps1 187 | 188 | Name Version Alias Source 189 | ---- ------- ----- ------ 190 | Get-EventlogInfo 1.0.0 191 | Test-EventLog 1.0.0 C:\work\sample.ps1 192 | ``` 193 | 194 | Get function metadata for every function in the specified file. 195 | 196 | ## PARAMETERS 197 | 198 | ### -Tag 199 | 200 | Specify a tag 201 | 202 | ```yaml 203 | Type: String 204 | Parameter Sets: (All) 205 | Aliases: 206 | 207 | Required: False 208 | Position: Named 209 | Default value: None 210 | Accept pipeline input: False 211 | Accept wildcard characters: False 212 | ``` 213 | 214 | ### -FunctionName 215 | 216 | Specify the name of a function that doesn't belong to a module. 217 | 218 | ```yaml 219 | Type: String 220 | Parameter Sets: name 221 | Aliases: 222 | 223 | Required: False 224 | Position: Named 225 | Default value: None 226 | Accept pipeline input: True (ByPropertyName, ByValue) 227 | Accept wildcard characters: False 228 | ``` 229 | 230 | ### -Path 231 | 232 | Specify a .ps1 file to search. The command will not be able to determine if the function definition in the file has been commented out. 233 | 234 | ```yaml 235 | Type: String 236 | Parameter Sets: file 237 | Aliases: FullName 238 | 239 | Required: False 240 | Position: Named 241 | Default value: None 242 | Accept pipeline input: True (ByPropertyName) 243 | Accept wildcard characters: False 244 | ``` 245 | 246 | ### CommonParameters 247 | 248 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 249 | 250 | ## INPUTS 251 | 252 | ### System.String 253 | 254 | ## OUTPUTS 255 | 256 | ### PSFunctionInfo 257 | 258 | ## NOTES 259 | 260 | This function has an alias of gpfi. The PSFunctionInfo object has additional named table views of source and tags. 261 | 262 | Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter 263 | 264 | ## RELATED LINKS 265 | 266 | [New-PSFunctionInfo](New-PSFunctionInfo.md) 267 | 268 | [Get-PSFunctionInfoTag](Get-PSFunctionInfoTag.md) 269 | 270 | [Edit-PSFunctionInfo](Edit-PSFunctionInfo.md) 271 | 272 | [Set-PSFunctionInfo](Set-PSFunctionInfo.md) 273 | -------------------------------------------------------------------------------- /docs/Get-PSFunctionInfoDefaults.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSFunctionInfo-help.xml 3 | Module Name: PSFunctionInfo 4 | online version: https://jdhitsolutions.com/yourls/a2852b 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-PSFunctionInfoDefaults 9 | 10 | ## SYNOPSIS 11 | 12 | Get defined PSFunctionInfo defaults. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Get-PSFunctionInfoDefaults [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | You can store default values for PSFunctionInfo commands using Set-PSFunctionInfoDefaults. The data is stored in a JSON file at $home\psfunctioninfo-defaults.json. Use Get-PSFunctionInfoDefaults to view. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Get-PSFunctionInfoDefaults 30 | 31 | 32 | Version : 0.9.0 33 | CompanyName : JDH IT Solutions, Inc. 34 | Author : Jeffery Hicks 35 | Tags : {stand-alone} 36 | Copyright : (c) JDH IT Solutions, Inc. 37 | ``` 38 | 39 | ## PARAMETERS 40 | 41 | ### CommonParameters 42 | 43 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 44 | 45 | ## INPUTS 46 | 47 | ### None 48 | 49 | ## OUTPUTS 50 | 51 | ### PSFunctionInfoDefault 52 | 53 | ## NOTES 54 | 55 | Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter 56 | 57 | ## RELATED LINKS 58 | 59 | [Set-PSFunctionInfoDefaults](Set-PSFunctionInfoDefaults.md) 60 | 61 | [Update-PSFunctionInfoDefaults](Update-PSFunctionInfoDefaults.md) 62 | -------------------------------------------------------------------------------- /docs/Get-PSFunctionInfoTag.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSFunctionInfo-help.xml 3 | Module Name: PSFunctionInfo 4 | online version: https://jdhitsolutions.com/yourls/241397 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-PSFunctionInfoTag 9 | 10 | ## SYNOPSIS 11 | 12 | Get a list of function tags. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Get-PSFunctionInfoTag [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | PSFunctionInfo metadata can contain tags. Get-PSFunctionInfoTag will create a list of all tags currently in use. The tag list is built from the functions currently loaded into your PowerShell session. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Get-PSFunctionInfoTag 30 | backup 31 | cim 32 | console 33 | directory 34 | git 35 | powershellget 36 | profile 37 | secrets 38 | Web 39 | ``` 40 | 41 | Get a list of current tags. 42 | 43 | ## PARAMETERS 44 | 45 | ### CommonParameters 46 | 47 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 48 | 49 | ## INPUTS 50 | 51 | ### None 52 | 53 | ## OUTPUTS 54 | 55 | ### System.String 56 | 57 | ## NOTES 58 | 59 | Learn more about PowerShell: 60 | https://jdhitsolutions.com/yourls/newsletter 61 | 62 | ## RELATED LINKS 63 | 64 | [Get-PSFunctionInfo](Get-PSFunctionInfo.md) 65 | -------------------------------------------------------------------------------- /docs/New-PSFunctionInfo.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSFunctionInfo-help.xml 3 | Module Name: PSFunctionInfo 4 | online version: https://jdhitsolutions.com/yourls/acc59c 5 | schema: 2.0.0 6 | --- 7 | 8 | # New-PSFunctionInfo 9 | 10 | ## SYNOPSIS 11 | 12 | Create PowerShell function metadata. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | New-PSFunctionInfo [-Name] -Path [-Author ] [-CompanyName ] [-Copyright ] [-Description ] [-Version ] [-Tags ] [-ToClipboard] [-Backup] [-NoSource] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | This command will create a function metadata comment block and insert it into the source script file. Or you can copy it to the clipboard and insert it yourself. There are no commands to modify or remove the function metadata once it has been inserted into the file. It is assumed that if you update the function, you can manually update (or remove) the metadata at the same time. 23 | 24 | NOTE: This command will not work properly with one-line function declarations like Function Get-This { Get-Date }. It is also expected that you don't have multiple versions of the function in the same file. DO NOT modify spacing or formatting of the function metadata. 25 | 26 | ## EXAMPLES 27 | 28 | ### Example 1 29 | 30 | ```powershell 31 | PS C:\> New-PSFunctionInfo -Path c:\scripts\Test-ConsoleColors.ps1 -Description "show console color combinations" -Name Test-ConsoleColor -Author "Jeff Hicks" -CompanyName "JDH IT Solutions" -Copyright "2025 JDH IT Solutions, Inc." -Tags "scripting","console" -backup 32 | ``` 33 | 34 | Insert function metadata into the script file before the [cmdletbinding()] tag. This example will produce this comment block: 35 | 36 | PSFunctionInfo 37 | 38 | Version 1.0.0 39 | 40 | Author Jeff Hicks 41 | 42 | CompanyName JDH IT Solutions 43 | 44 | Copyright 2025 JDH IT Solutions, Inc. 45 | 46 | Description show console color combinations 47 | 48 | Guid e07e256e-a2d6-4acc-a1cf-5d8d1be7db27 49 | 50 | Tags scripting,console 51 | 52 | LastUpdate 03/02/2025 10:34:18 53 | 54 | Source C:\Scripts\Test-ConsoleColors.ps1 55 | 56 | This example will also create a backup copy of the source file at c:\scripts\Test-ConsoleColors.ps1.bak1. 57 | 58 | ### Example 2 59 | 60 | ```powershell 61 | PS C:\> New-PSFunctionInfo -Path c:\scripts\Test-ConsoleColors.ps1 -Description "show console color combinations" -Name Test-ConsoleColor -Author "Jeff Hicks" -CompanyName "JDH IT Solutions" -Copyright "2025 JDH IT Solutions, Inc." -Tags "scripting","console" -ToClipboard 62 | ``` 63 | 64 | This will create the same metadata as the first example. Except it will be copied to the clipboard and not to the file. 65 | 66 | ## PARAMETERS 67 | 68 | ### -Author 69 | 70 | Specify the function author. 71 | 72 | ```yaml 73 | Type: String 74 | Parameter Sets: (All) 75 | Aliases: 76 | 77 | Required: False 78 | Position: Named 79 | Default value: Current user name 80 | Accept pipeline input: False 81 | Accept wildcard characters: False 82 | ``` 83 | 84 | ### -CompanyName 85 | 86 | Specify a company or organization. 87 | 88 | ```yaml 89 | Type: String 90 | Parameter Sets: (All) 91 | Aliases: 92 | 93 | Required: False 94 | Position: Named 95 | Default value: None 96 | Accept pipeline input: False 97 | Accept wildcard characters: False 98 | ``` 99 | 100 | ### -Confirm 101 | 102 | Prompts you for confirmation before running the cmdlet. 103 | 104 | ```yaml 105 | Type: SwitchParameter 106 | Parameter Sets: (All) 107 | Aliases: cf 108 | 109 | Required: False 110 | Position: Named 111 | Default value: False 112 | Accept pipeline input: False 113 | Accept wildcard characters: False 114 | ``` 115 | 116 | ### -Copyright 117 | 118 | Specify a copyright for the function. 119 | 120 | ```yaml 121 | Type: String 122 | Parameter Sets: (All) 123 | Aliases: 124 | 125 | Required: False 126 | Position: Named 127 | Default value: The current year 128 | Accept pipeline input: False 129 | Accept wildcard characters: False 130 | ``` 131 | 132 | ### -Description 133 | 134 | Specify a brief function description. 135 | 136 | ```yaml 137 | Type: String 138 | Parameter Sets: (All) 139 | Aliases: 140 | 141 | Required: False 142 | Position: Named 143 | Default value: None 144 | Accept pipeline input: False 145 | Accept wildcard characters: False 146 | ``` 147 | 148 | ### -Name 149 | 150 | Specify the name of the function. 151 | 152 | ```yaml 153 | Type: String 154 | Parameter Sets: (All) 155 | Aliases: 156 | 157 | Required: True 158 | Position: 0 159 | Default value: None 160 | Accept pipeline input: False 161 | Accept wildcard characters: False 162 | ``` 163 | 164 | ### -Path 165 | 166 | Specify the path to the .ps1 file that contains the function. The path must end in .ps1. 167 | 168 | ```yaml 169 | Type: String 170 | Parameter Sets: (All) 171 | Aliases: 172 | 173 | Required: True 174 | Position: Named 175 | Default value: None 176 | Accept pipeline input: False 177 | Accept wildcard characters: False 178 | ``` 179 | 180 | ### -Tags 181 | 182 | Specify an array of optional tags. 183 | 184 | ```yaml 185 | Type: String[] 186 | Parameter Sets: (All) 187 | Aliases: 188 | 189 | Required: False 190 | Position: Named 191 | Default value: None 192 | Accept pipeline input: False 193 | Accept wildcard characters: False 194 | ``` 195 | 196 | ### -ToClipboard 197 | 198 | Copy the metadata to the clipboard. The file is left untouched. 199 | 200 | ```yaml 201 | Type: SwitchParameter 202 | Parameter Sets: (All) 203 | Aliases: clip 204 | 205 | Required: False 206 | Position: Named 207 | Default value: False 208 | Accept pipeline input: False 209 | Accept wildcard characters: False 210 | ``` 211 | 212 | ### -Version 213 | 214 | Specify a version number. It is recommended to use a semantic version numbering. 215 | 216 | ```yaml 217 | Type: String 218 | Parameter Sets: (All) 219 | Aliases: 220 | 221 | Required: False 222 | Position: Named 223 | Default value: 1.0.0 224 | Accept pipeline input: False 225 | Accept wildcard characters: False 226 | ``` 227 | 228 | ### -WhatIf 229 | 230 | Shows what would happen if the cmdlet runs. The cmdlet is not run. 231 | 232 | ```yaml 233 | Type: SwitchParameter 234 | Parameter Sets: (All) 235 | Aliases: wi 236 | 237 | Required: False 238 | Position: Named 239 | Default value: False 240 | Accept pipeline input: False 241 | Accept wildcard characters: False 242 | ``` 243 | 244 | ### -Backup 245 | 246 | Create a backup copy of the source file before inserting the metadata comment block. The file will be created in the same directory, appending an extension of .bak1. If there are previous backups, the number will increment, i.e. .bak2. You can manually delete the backup files. 247 | 248 | This parameter has no effect if you use -Clipboard. 249 | 250 | ```yaml 251 | Type: SwitchParameter 252 | Parameter Sets: (All) 253 | Aliases: 254 | 255 | Required: False 256 | Position: Named 257 | Default value: False 258 | Accept pipeline input: False 259 | Accept wildcard characters: False 260 | ``` 261 | 262 | ### -NoSource 263 | 264 | Do not insert the source file path into the metadata comment block. 265 | 266 | ```yaml 267 | Type: SwitchParameter 268 | Parameter Sets: (All) 269 | Aliases: 270 | 271 | Required: False 272 | Position: Named 273 | Default value: None 274 | Accept pipeline input: False 275 | Accept wildcard characters: False 276 | ``` 277 | 278 | ### CommonParameters 279 | 280 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 281 | 282 | ## INPUTS 283 | 284 | ### None 285 | 286 | ## OUTPUTS 287 | 288 | ### None 289 | 290 | ## NOTES 291 | 292 | This function has an alias of npfi. 293 | 294 | Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter 295 | 296 | ## RELATED LINKS 297 | 298 | [Get-PSFunctionInfo](Get-PSFunctionInfo.md) 299 | 300 | [Edit-PSFunctionInfo](Edit-PSFunctionInfo.md) 301 | 302 | [Remove-PSFunctionInfo](Remove-PSFunctionInfo.md) 303 | 304 | [Set-PSFunctionInfo](Set-PSFunctionInfo.md) 305 | -------------------------------------------------------------------------------- /docs/Remove-PSFunctionInfo.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSFunctionInfo-help.xml 3 | Module Name: PSFunctionInfo 4 | online version: https://jdhitsolutions.com/yourls/b91632 5 | schema: 2.0.0 6 | --- 7 | 8 | # Remove-PSFunctionInfo 9 | 10 | ## SYNOPSIS 11 | 12 | Remove PSFunctionInfo metadata. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Remove-PSFunctionInfo [-FunctionName] -Path [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Use this function to remove the PSFunctionInfo metadata for a given function. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Remove-PSFunctionInfo Test-Eventlog -path c:\work\eventlogtools.ps1 30 | ``` 31 | 32 | Remove the entry for the given function. 33 | 34 | ### Example 2 35 | 36 | ```powershell 37 | PS C:\> Get-PSFunctioninfo -Path c:\work\tools.ps1 | Remove-PSFunctionInfo 38 | ``` 39 | 40 | Get PSFUnctionInfo for all functions from the specified file and remove them. This assumes that every function has a source value that reflects c:\work\tools.ps1. Otherwise, you could specify the Path parameter with Remove-PSFunctionInfo. 41 | 42 | ## PARAMETERS 43 | 44 | ### -Confirm 45 | 46 | Prompts you for confirmation before running the cmdlet. 47 | 48 | ```yaml 49 | Type: SwitchParameter 50 | Parameter Sets: (All) 51 | Aliases: cf 52 | 53 | Required: False 54 | Position: Named 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -FunctionName 61 | 62 | Specify the name of a function that doesn't belong to a module. 63 | 64 | ```yaml 65 | Type: String 66 | Parameter Sets: (All) 67 | Aliases: Name 68 | 69 | Required: True 70 | Position: 0 71 | Default value: None 72 | Accept pipeline input: True (ByPropertyName) 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### -Path 77 | 78 | Specify the source .ps1 file for the function. 79 | 80 | ```yaml 81 | Type: String 82 | Parameter Sets: (All) 83 | Aliases: FullName, Source 84 | 85 | Required: True 86 | Position: Named 87 | Default value: None 88 | Accept pipeline input: True (ByPropertyName) 89 | Accept wildcard characters: False 90 | ``` 91 | 92 | ### -WhatIf 93 | 94 | Shows what would happen if the cmdlet runs. 95 | The cmdlet is not run. 96 | 97 | ```yaml 98 | Type: SwitchParameter 99 | Parameter Sets: (All) 100 | Aliases: wi 101 | 102 | Required: False 103 | Position: Named 104 | Default value: None 105 | Accept pipeline input: False 106 | Accept wildcard characters: False 107 | ``` 108 | 109 | ### CommonParameters 110 | 111 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 112 | 113 | ## INPUTS 114 | 115 | ### System.String 116 | 117 | ## OUTPUTS 118 | 119 | ### None 120 | 121 | ## NOTES 122 | 123 | Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter 124 | 125 | ## RELATED LINKS 126 | 127 | [Set-PSFunctionInfo](Set-PSFunctionInfo.md) 128 | 129 | [Get-PSFunctionInfo](Get-PSFunctionInfo.md) 130 | -------------------------------------------------------------------------------- /docs/Set-PSFunctionInfo.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSFunctionInfo-help.xml 3 | Module Name: PSFunctionInfo 4 | online version: https://jdhitsolutions.com/yourls/30835d 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-PSFunctionInfo 9 | 10 | ## SYNOPSIS 11 | 12 | Set PSFunctionInfo values. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Set-PSFunctionInfo [-FunctionName] -Path [-Version ] [-Author ] [-CompanyName ] [-Copyright ] [-Description ] [-Tags ] [-Source ] [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | Normally, if you want to update an existing PSFunctionInfo metadata entry, you would do this while editing the file. However, you could use this command to make changes from the command prompt. If you want to remove a setting, use $Null as the parameter value. The LastUpdate value will be automatically updated to reflect the current date and time. 23 | 24 | If you update the metadata, you won't see any changes until you manually reload the function into your PowerShell session. 25 | 26 | . (Get-PSFunctionInfo Get-EventlogInfo).Source 27 | 28 | ## EXAMPLES 29 | 30 | ### Example 1 31 | 32 | ```powershell 33 | PS C:\> Set-PSFunctionInfo -Name Get-EventlogInfo -Path c:\work\LogTools.ps1 -Tags "profile,eventlog" -Version "1.2.1" 34 | ``` 35 | 36 | Update PSFunctionInfo for the Get-EventlogInfo function in the specified file. 37 | 38 | ### Example 2 39 | 40 | ```powershell 41 | PS C:\> Set-PSFunctionInfo -Name Test-Eventlog -Path c:\work\LogTools.ps1 -Source $null 42 | ``` 43 | 44 | Clear the PSFunctionInfo Source value for the Test-Eventlog function. 45 | 46 | ## PARAMETERS 47 | 48 | ### -Author 49 | 50 | Specify the new author. 51 | 52 | ```yaml 53 | Type: String 54 | Parameter Sets: (All) 55 | Aliases: 56 | 57 | Required: False 58 | Position: Named 59 | Default value: None 60 | Accept pipeline input: False 61 | Accept wildcard characters: False 62 | ``` 63 | 64 | ### -CompanyName 65 | 66 | Specify the new company information. 67 | 68 | ```yaml 69 | Type: String 70 | Parameter Sets: (All) 71 | Aliases: 72 | 73 | Required: False 74 | Position: Named 75 | Default value: None 76 | Accept pipeline input: False 77 | Accept wildcard characters: False 78 | ``` 79 | 80 | ### -Confirm 81 | 82 | Prompts you for confirmation before running the cmdlet. 83 | 84 | ```yaml 85 | Type: SwitchParameter 86 | Parameter Sets: (All) 87 | Aliases: cf 88 | 89 | Required: False 90 | Position: Named 91 | Default value: None 92 | Accept pipeline input: False 93 | Accept wildcard characters: False 94 | ``` 95 | 96 | ### -Copyright 97 | 98 | Specify the new copyright information. 99 | 100 | ```yaml 101 | Type: String 102 | Parameter Sets: (All) 103 | Aliases: 104 | 105 | Required: False 106 | Position: Named 107 | Default value: None 108 | Accept pipeline input: False 109 | Accept wildcard characters: False 110 | ``` 111 | 112 | ### -Description 113 | 114 | Specify the new description. This should be a single line of text. 115 | 116 | ```yaml 117 | Type: String 118 | Parameter Sets: (All) 119 | Aliases: 120 | 121 | Required: False 122 | Position: Named 123 | Default value: None 124 | Accept pipeline input: False 125 | Accept wildcard characters: False 126 | ``` 127 | 128 | ### -FunctionName 129 | 130 | Specify the name of a function that doesn't belong to a module. 131 | 132 | ```yaml 133 | Type: String 134 | Parameter Sets: (All) 135 | Aliases: Name 136 | 137 | Required: True 138 | Position: 0 139 | Default value: None 140 | Accept pipeline input: True (ByPropertyName, ByValue) 141 | Accept wildcard characters: False 142 | ``` 143 | 144 | ### -Path 145 | 146 | Specify the .ps1 file that contains the function. 147 | 148 | ```yaml 149 | Type: String 150 | Parameter Sets: (All) 151 | Aliases: fullname 152 | 153 | Required: True 154 | Position: Named 155 | Default value: None 156 | Accept pipeline input: True (ByPropertyName) 157 | Accept wildcard characters: False 158 | ``` 159 | 160 | ### -Source 161 | 162 | Specify the new Source. 163 | 164 | ```yaml 165 | Type: String 166 | Parameter Sets: (All) 167 | Aliases: 168 | 169 | Required: False 170 | Position: Named 171 | Default value: None 172 | Accept pipeline input: False 173 | Accept wildcard characters: False 174 | ``` 175 | 176 | ### -Tags 177 | 178 | Specify the new tags as a comma-separated string. 179 | This will replace existing tags. 180 | 181 | ```yaml 182 | Type: String 183 | Parameter Sets: (All) 184 | Aliases: 185 | 186 | Required: False 187 | Position: Named 188 | Default value: None 189 | Accept pipeline input: False 190 | Accept wildcard characters: False 191 | ``` 192 | 193 | ### -Version 194 | 195 | Specify the new version number. 196 | 197 | ```yaml 198 | Type: String 199 | Parameter Sets: (All) 200 | Aliases: 201 | 202 | Required: False 203 | Position: Named 204 | Default value: None 205 | Accept pipeline input: False 206 | Accept wildcard characters: False 207 | ``` 208 | 209 | ### -WhatIf 210 | 211 | Shows what would happen if the cmdlet runs. 212 | The cmdlet is not run. 213 | 214 | ```yaml 215 | Type: SwitchParameter 216 | Parameter Sets: (All) 217 | Aliases: wi 218 | 219 | Required: False 220 | Position: Named 221 | Default value: None 222 | Accept pipeline input: False 223 | Accept wildcard characters: False 224 | ``` 225 | 226 | ### CommonParameters 227 | 228 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 229 | 230 | ## INPUTS 231 | 232 | ### System.String 233 | 234 | ## OUTPUTS 235 | 236 | ### None 237 | 238 | ## NOTES 239 | 240 | Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter 241 | 242 | ## RELATED LINKS 243 | 244 | [Get-PSFunctionInfo](Get-PSFunctionInfo.md) 245 | 246 | [Edit-PSFunctionInfo](Edit-PSFunctionInfo.md) 247 | 248 | [Remove-PSFunctionInfo](Remove-PSFunctionInfo.md) 249 | -------------------------------------------------------------------------------- /docs/Set-PSFunctionInfoDefaults.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSFunctionInfo-help.xml 3 | Module Name: PSFunctionInfo 4 | online version: https://jdhitsolutions.com/yourls/82077e 5 | schema: 2.0.0 6 | --- 7 | 8 | # Set-PSFunctionInfoDefaults 9 | 10 | ## SYNOPSIS 11 | 12 | Store default values for PSFunctionInfo commands. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Set-PSFunctionInfoDefaults [[-Author] ] [[-CompanyName] ] 18 | [[-Copyright] ] [[-Version] ] [[-Tags] ] [-WhatIf] [-Confirm] [] 19 | ``` 20 | 21 | ## DESCRIPTION 22 | 23 | Because you might define function metadata often, and want to maintain consistency, you can define a set of default values for New-PSFunctionInfo. Set-PSFunctionInfoDefaults will create a JSON file at $home\psfunctioninfo-defaults.json. When you import this module, these values will be used to define entries in $PSDefaultParameterValues. Or, run Update-PSFunctionInfoDefaults to update parameter defaults. 24 | 25 | If you run the command without specifying any parameters, you will get a warning and no file will be created. 26 | 27 | ## EXAMPLES 28 | 29 | ### Example 1 30 | 31 | ```powershell 32 | PS C:\> Set-PSFunctionInfoDefaults -Copyright "(c) JDH IT Solutions, Inc." -author "Jeff Hicks" -company "JDH IT Solutions, Inc." 33 | ``` 34 | 35 | ## PARAMETERS 36 | 37 | ### -Author 38 | 39 | Enter the default author name. 40 | 41 | ```yaml 42 | Type: String 43 | Parameter Sets: (All) 44 | Aliases: 45 | 46 | Required: False 47 | Position: 0 48 | Default value: None 49 | Accept pipeline input: True (ByPropertyName) 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -CompanyName 54 | 55 | Enter the default company name. 56 | 57 | ```yaml 58 | Type: String 59 | Parameter Sets: (All) 60 | Aliases: 61 | 62 | Required: False 63 | Position: 1 64 | Default value: None 65 | Accept pipeline input: True (ByPropertyName) 66 | Accept wildcard characters: False 67 | ``` 68 | 69 | ### -Confirm 70 | 71 | Prompts you for confirmation before running the cmdlet. 72 | 73 | ```yaml 74 | Type: SwitchParameter 75 | Parameter Sets: (All) 76 | Aliases: cf 77 | 78 | Required: False 79 | Position: Named 80 | Default value: None 81 | Accept pipeline input: False 82 | Accept wildcard characters: False 83 | ``` 84 | 85 | ### -Copyright 86 | 87 | Enter the default copyright string. 88 | 89 | ```yaml 90 | Type: String 91 | Parameter Sets: (All) 92 | Aliases: 93 | 94 | Required: False 95 | Position: 2 96 | Default value: None 97 | Accept pipeline input: True (ByPropertyName) 98 | Accept wildcard characters: False 99 | ``` 100 | 101 | ### -Tags 102 | 103 | Enter the default tag(s). 104 | 105 | ```yaml 106 | Type: String[] 107 | Parameter Sets: (All) 108 | Aliases: 109 | 110 | Required: False 111 | Position: 4 112 | Default value: None 113 | Accept pipeline input: True (ByPropertyName) 114 | Accept wildcard characters: False 115 | ``` 116 | 117 | ### -Version 118 | 119 | Enter the default version. 120 | 121 | ```yaml 122 | Type: String 123 | Parameter Sets: (All) 124 | Aliases: 125 | 126 | Required: False 127 | Position: 3 128 | Default value: None 129 | Accept pipeline input: True (ByPropertyName) 130 | Accept wildcard characters: False 131 | ``` 132 | 133 | ### -WhatIf 134 | 135 | Shows what would happen if the cmdlet runs. 136 | The cmdlet is not run. 137 | 138 | ```yaml 139 | Type: SwitchParameter 140 | Parameter Sets: (All) 141 | Aliases: wi 142 | 143 | Required: False 144 | Position: Named 145 | Default value: None 146 | Accept pipeline input: False 147 | Accept wildcard characters: False 148 | ``` 149 | 150 | ### CommonParameters 151 | 152 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 153 | 154 | ## INPUTS 155 | 156 | ### System.String 157 | 158 | ### System.String[] 159 | 160 | ## OUTPUTS 161 | 162 | ### None 163 | 164 | ## NOTES 165 | 166 | Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter 167 | 168 | ## RELATED LINKS 169 | 170 | [Get-PSFunctionInfoDefaults](Get-PSFunctionInfoDefaults.md) 171 | 172 | [Update-PSFunctionInfoDefaults](Update-PSFunctionInfoDefaults.md) 173 | -------------------------------------------------------------------------------- /docs/Update-PSFunctionInfoDefaults.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PSFunctionInfo-help.xml 3 | Module Name: PSFunctionInfo 4 | online version: https://jdhitsolutions.com/yourls/065d5b 5 | schema: 2.0.0 6 | --- 7 | 8 | # Update-PSFunctionInfoDefaults 9 | 10 | ## SYNOPSIS 11 | 12 | Refresh $PSDefaultParameterValues with PSFunctionInfo defaults. 13 | 14 | ## SYNTAX 15 | 16 | ```yaml 17 | Update-PSFunctionInfoDefaults [-WhatIf] [-Confirm] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | 22 | You can store default values for PSFunctionInfo commands using Set-PSFunctionInfoDefaults. The data is stored in a JSON file at $home\psfunctioninfo-defaults.json. When you import the PSFunctionInfo module, this file will be imported and used to set entries in $PSDefaultParameterValues. If you modify the defaults, you can refresh your $PSDefaultParameterValues by running Update-PSFunctionInfoDefaults. 23 | 24 | ## EXAMPLES 25 | 26 | ### Example 1 27 | 28 | ```powershell 29 | PS C:\> Set-PSFunctionInfoDefaults -author "Gladys Kravitz" 30 | PS C:\> Update-PSFunctionInfoDefaults 31 | ``` 32 | 33 | This example updates the default Author parameter value. The second command refreshes $PSDefaultParameterValues. 34 | 35 | ## PARAMETERS 36 | 37 | ### -Confirm 38 | 39 | Prompts you for confirmation before running the cmdlet. 40 | 41 | ```yaml 42 | Type: SwitchParameter 43 | Parameter Sets: (All) 44 | Aliases: cf 45 | 46 | Required: False 47 | Position: Named 48 | Default value: None 49 | Accept pipeline input: False 50 | Accept wildcard characters: False 51 | ``` 52 | 53 | ### -WhatIf 54 | 55 | Shows what would happen if the cmdlet runs. 56 | The cmdlet is not run. 57 | 58 | ```yaml 59 | Type: SwitchParameter 60 | Parameter Sets: (All) 61 | Aliases: wi 62 | 63 | Required: False 64 | Position: Named 65 | Default value: None 66 | Accept pipeline input: False 67 | Accept wildcard characters: False 68 | ``` 69 | 70 | ### CommonParameters 71 | 72 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). 73 | 74 | ## INPUTS 75 | 76 | ### None 77 | 78 | ## OUTPUTS 79 | 80 | ### None 81 | 82 | ## NOTES 83 | 84 | Learn more about PowerShell: https://jdhitsolutions.com/yourls/newsletter 85 | 86 | ## RELATED LINKS 87 | 88 | [Set-PSFunctionInfoDefaults](Set-PSFunctionInfoDefaults.md) 89 | 90 | [Get-PSFunctionInfoDefaults](Get-PSFunctionInfoDefaults.md) 91 | -------------------------------------------------------------------------------- /docs/about_PSFunctionInfo.md: -------------------------------------------------------------------------------- 1 | # PSFunctionInfo 2 | 3 | ## about_PSFunctionInfo 4 | 5 | # SHORT DESCRIPTION 6 | 7 | This module contains a set of PowerShell commands to add and manage metadata in stand-alone PowerShell functions. 8 | 9 | # LONG DESCRIPTION 10 | 11 | The purpose of this code is to provide a way to get versioning and other metadata information for functions that may not belong to a module. This is information you want to get after the function has been loaded into your PowerShell session. I have numerous stand-alone functions. These functions don't belong to a module, so there is no version or source information. However, I'd like to use that type of information for non-module files. 12 | 13 | The code in this module isn't concerned with loading, running, or finding functions. It queries whatever is in the `Function:` PSDrive. If the PowerShell function belongs to a module, then you'll get the module version and source. Otherwise, you can use the function metadata. 14 | 15 | The default behavior is to show all functions that __don't__ belong to a module. You can also get functions by tag. Use `Get-PSFunctionInfoTag` to get a list of tags currently in use. 16 | 17 | ## Creating PSFunctionInfo 18 | 19 | Use the `New-PSFunctionInfo` command to insert the metadata tag into your script file. 20 | 21 | ```powershell 22 | $params = @{ 23 | Name = 'Test-ConsoleColor' 24 | Path = 'c:\scripts\Test-ConsoleColors.ps1' 25 | Description = 'show console color combinations' 26 | Author = 'Jeff Hicks' 27 | CompanyName = 'JDH IT Solutions' 28 | Copyright = '2024 JDH IT Solutions, Inc.' 29 | Tags = @('scripting', 'console') 30 | } 31 | New-PSFunctionInfo @params 32 | ``` 33 | 34 | The default behavior is to insert the metadata tag immediately after the opening brace ({) into the file. **This command will update the file**. Or you can use the `ToClipBoard` parameter which will copy the metadata to the clipboard and you can manually insert it into your script file that defines the function. 35 | 36 | You should get something like this: 37 | 38 | ```text 39 | 40 | <# PSFunctionInfo 41 | 42 | Version 1.0.0 43 | Author Jeff Hicks 44 | CompanyName JDH IT Solutions 45 | Copyright 2024 JDH IT Solutions, Inc. 46 | Description show console color combinations 47 | Guid 8e43a9d9-1df6-48c7-8595-7363087aba43 48 | Tags scripting,console 49 | LastUpdate 4/21/2024 10:43 AM 50 | Source C:\scripts\Test-ConsoleColors.ps1 51 | 52 | #> 53 | ``` 54 | 55 | This command will not work with functions defined in a single line like this: 56 | 57 | ```powershell 58 | Function Get-Foo { Get-Date } 59 | ``` 60 | 61 | You can still run `New-PSFunctionInfo` with the `ToClipboard` parameter and manually edit your function to insert the metadata. 62 | 63 | ```powershell 64 | Function Get-Foo { 65 | 66 | <# PSFunctionInfo 67 | 68 | Version 1.0.0 69 | Author Jeff Hicks 70 | CompanyName JDH IT Solutions 71 | Copyright 2024 JDH IT Solutions, Inc. 72 | Description Get Foo Stuff 73 | Guid 490595c6-6a0c-4572-baf4-f808c010de70 74 | Tags scripting,console 75 | LastUpdate 4/21/2024 10:4f AM 76 | Source C:\scripts\FooStuff.ps1 77 | 78 | #> 79 | Get-Date 80 | } 81 | ``` 82 | 83 | There are no commands to modify or remove function metadata. It is assumed that when you update the function, you can update or remove the metadata. 84 | 85 | ## PSFunctionInfo Defaults 86 | 87 | Because you might define function metadata often and want to maintain consistency, you can define a set of default values for `New-PSFunctionInfo`. Use the command, `Set-PSFunctionInfoDefaults`: 88 | 89 | ```powershell 90 | $params = @{ 91 | Tags = @('stand-alone') 92 | Author = 'Jeff Hicks' 93 | CompanyName = 'JDH IT Solutions, Inc.' 94 | Copyright = '(c) JDH IT Solutions, Inc.' 95 | } 96 | Set-PSFunctionInfoDefaults @params 97 | ``` 98 | 99 | The defaults will be stored in a JSON file at `$home\psfunctioninfo-defaults.json`. When you import this module, these values will be used to define entries in `$PSDefaultParameterValues`. Or, run `Update-PSFunctionInfoDefaults` to update parameter defaults. 100 | 101 | You can use `Get-PSFunctionInfoDefaults` to see the current values. 102 | 103 | ## Editor Integration 104 | 105 | When you import the module into an editor, you will get additional features to make it easier to insert PSFunctionInfo metadata into your file. It is recommended that you explicitly import the module into the editor's integrated console session. You could add an `Import-Module PSFunctionInfo` command into the editor's PowerShell profile script. 106 | 107 | ### Visual Studio Code 108 | 109 | If you have an open file, in the integrated PowerShell console, you can run `New-PSFunctionInfo` and press TAB to tab-complete the detected functions in the current file. The file path will automatically be detected. You can enter other values such as version, or simply press ENTER to insert the metadata, which you can then edit. 110 | 111 | ### PowerShell ISE 112 | 113 | When you import the module in the PowerShell ISE, it will add a menu shortcut. 114 | 115 | With a loaded file, you could run `New-PSFunctionInfo` in the console specifying the function name. The Path will be auto-detected. Or use the menu shortcut which will give you a graphical "function picker" 116 | 117 | Select a function and click OK. The metadata block will be inserted into the file. This will not work with a file that has unsaved changes. When you insert new function metadata, the file in the ISE will be closed, re-opened and focus should jump to the function. 118 | 119 | # TROUBLESHOOTING NOTE 120 | 121 | Please report any bugs or feature requests at https://github.com/jdhitsolutions/PSFunctionInfo/issues. 122 | 123 | # KEYWORDS 124 | 125 | - functions 126 | - metadata 127 | -------------------------------------------------------------------------------- /en-us/about_PSFunctionInfo.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_psfunctioninfo 3 | 4 | SHORT DESCRIPTION 5 | This module contains a set of PowerShell commands to add and manage metadata 6 | in stand-alone PowerShell functions. 7 | 8 | LONG DESCRIPTION 9 | The purpose of this code is to provide a way to get versioning and other 10 | metadata information for functions that may not belong to a module. This is 11 | information you want to get after the function has been loaded into your 12 | PowerShell session. I have numerous stand-alone functions. These functions 13 | don't belong to a module, so there is no version or source information. 14 | 15 | However, I'd like to use that type of information for non-module files. 16 | The code in this module isn't concerned with loading, running, or finding 17 | functions. It queries whatever is in the Function: PSDrive. If the PowerShell 18 | function belongs to a module, then you'll get the module version and source. 19 | 20 | Otherwise, you can use the function metadata. The default behavior is to show 21 | all functions that don't belong to a module. You can also get functions by tag. 22 | 23 | Use Get-PSFunctionInfoTag to get a list of tags currently in use. 24 | 25 | Creating PSFunctionInfo 26 | Use the New-PSFunctionInfo command to insert the metadata tag into your script 27 | file. 28 | 29 | $params = @{ 30 | Name = 'Test-ConsoleColor' 31 | Path = 'c:\scripts\Test-ConsoleColors.ps1' 32 | Description = 'show console color combinations' 33 | Author = 'Jeff Hicks' 34 | CompanyName = 'JDH IT Solutions' 35 | Copyright = '2025 JDH IT Solutions, Inc.' 36 | Tags = @('scripting', 'console') 37 | } 38 | New-PSFunctionInfo @params 39 | 40 | The default behavior is to insert the metadata tag immediately after the 41 | opening brace ({) into the file. 42 | 43 | This command will update the file. Or you can use the ToClipBoard parameter 44 | which will copy the metadata to the clipboard and you can manually insert 45 | it into your script file that defines the function. 46 | 47 | You should get something like this: 48 | 49 | <# PSFunctionInfo 50 | 51 | Version 1.0.0 52 | Author Jeff Hicks 53 | CompanyName JDH IT Solutions 54 | Copyright 2024 JDH IT Solutions, Inc. 55 | Description show console color combinations 56 | Guid 8e43a9d9-1df6-48c7-8595-7363087aba43 57 | Tags scripting,console 58 | LastUpdate 4/21/2024 10:43 AM 59 | Source C:\scripts\Test-ConsoleColors.ps1 60 | 61 | #> 62 | 63 | This command will not work with functions defined in a single line like 64 | this: 65 | 66 | Function Get-Foo { Get-Date } 67 | 68 | You can still run New-PSFunctionInfo with the ToClipboard parameter and 69 | manually edit your function to insert the metadata. 70 | 71 | Function Get-Foo { 72 | 73 | <# PSFunctionInfo 74 | 75 | Version 1.0.0 76 | Author Jeff Hicks 77 | CompanyName JDH IT Solutions 78 | Copyright 2024 JDH IT Solutions, Inc. 79 | Description Get Foo Stuff 80 | Guid 490595c6-6a0c-4572-baf4-f808c010de70 81 | Tags scripting,console 82 | LastUpdate 4/21/2024 10:4f AM 83 | Source C:\scripts\FooStuff.ps1 84 | 85 | #> 86 | Get-Date 87 | } 88 | 89 | There are no commands to modify or remove function metadata. It is assumed 90 | that when you update the function, you can update or remove the metadata. 91 | 92 | PSFunctionInfo Defaults 93 | Because you might define function metadata often and want to maintain 94 | consistency, you can define a set of default values for New-PSFunctionInfo. 95 | 96 | Use the command, Set-PSFunctionInfoDefaults: 97 | 98 | $params = @{ 99 | Tags = @('stand-alone') 100 | Author = 'Jeff Hicks' 101 | CompanyName = 'JDH IT Solutions, Inc.' 102 | Copyright = '(c) JDH IT Solutions, Inc.' 103 | } 104 | Set-PSFunctionInfoDefaults @params 105 | 106 | The defaults will be stored in a JSON file saved to: 107 | 108 | $home\psfunctioninfo-defaults.json. 109 | 110 | When you import this module, these values will be used to define entries in 111 | $PSDefaultParameterValues. Or, run Update-PSFunctionInfoDefaults to update 112 | parameter defaults. You can use Get-PSFunctionInfoDefaults to see the 113 | current values. 114 | 115 | Editor Integration 116 | When you import the module into an editor, you will get additional features 117 | to make it easier to insert PSFunctionInfo metadata into your file. It is 118 | recommended that you explicitly import the module into the editor's 119 | integrated console session. You could add an Import-Module PSFunctionInfo 120 | command into the editor's PowerShell profile script. 121 | 122 | VISUAL STUDIO CODE 123 | If you have an open file, in the integrated PowerShell console, you can run 124 | New-PSFunctionInfo and press TAB to tab-complete the detected functions in 125 | the current file. The file path will automatically be detected. You can 126 | enter other values such as version, or simply press ENTER to insert the 127 | metadata, which you can then edit. 128 | 129 | POWERSHELL ISE 130 | When you import the module in the PowerShell ISE, it will add a menu 131 | shortcut. With a loaded file, you could run New-PSFunctionInfo in the 132 | console specifying the function name. The Path will be auto-detected. 133 | 134 | Or use the menu shortcut which will give you a graphical "function picker" 135 | 136 | Select a function and click OK. The metadata block will be inserted into 137 | the file. This will not work with a file that has unsaved changes. 138 | 139 | When you insert new function metadata, the file in the ISE will be closed, 140 | re-opened and the focus should jump to the function. 141 | 142 | TROUBLESHOOTING NOTE 143 | Please report any bugs or feature requests at 144 | https://github.com/jdhitsolutions/PSFunctionInfo/issues. 145 | 146 | KEYWORDS 147 | - functions 148 | - metadata 149 | 150 | -------------------------------------------------------------------------------- /formats/psfunctioninfo.format.ps1xml: -------------------------------------------------------------------------------- 1 |  2 | 9 | 10 | 11 | 12 | 13 | default 14 | 15 | PSFunctionInfo 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 24 | left 25 | 26 | 27 | 28 | 10 29 | left 30 | 31 | 32 | 33 | 15 34 | left 35 | 36 | 37 | 38 | 40 39 | left 40 | 41 | 42 | 43 | 44 | 45 | 46 | Name 47 | 48 | 49 | Version 50 | 51 | 52 | Alias 53 | 54 | 55 | Source 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | source 65 | 66 | PSFunctionInfo 67 | 68 | 69 | Source 70 | 71 | 72 | 73 | 75 | 76 | 77 | 78 | 25 79 | left 80 | 81 | 82 | 83 | 10 84 | left 85 | 86 | 87 | 88 | left 89 | 90 | 91 | 92 | 93 | 94 | 95 | Name 96 | 97 | 98 | Version 99 | 100 | 101 | Description 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | tags 111 | 112 | PSFunctionInfo 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 16 121 | left 122 | 123 | 124 | 125 | 10 126 | left 127 | 128 | 129 | 130 | 18 131 | left 132 | 133 | 134 | 135 | 34 136 | left 137 | 138 | 139 | 140 | 141 | 142 | 143 | Name 144 | 145 | 146 | Version 147 | 148 | 149 | Tags 150 | 151 | 152 | Source 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | default 162 | 163 | PSFunctionInfo 164 | 165 | 166 | 167 | 168 | 169 | 173 | 174 | 175 | Name 176 | 177 | 178 | 179 | Alias 180 | 181 | 182 | 183 | Version 184 | 185 | 186 | 187 | Source 188 | 189 | 190 | 191 | Description 192 | 193 | 194 | 195 | Path 196 | 197 | 198 | 199 | Tags 200 | 201 | 202 | 203 | LastUpdate 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | -------------------------------------------------------------------------------- /functions/Edit-PSFunctionInfo.ps1: -------------------------------------------------------------------------------- 1 | Function Edit-PSFunctionInfo { 2 | [CmdletBinding(DefaultParameterSetName="name")] 3 | [OutputType("None")] 4 | [Alias("epfi")] 5 | Param( 6 | [Parameter( 7 | ValueFromPipeline, 8 | ValueFromPipelineByPropertyName, 9 | HelpMessage = "Specify the path to the source file.", 10 | ParameterSetName="source" 11 | )] 12 | [ValidateNotNullOrEmpty()] 13 | [String]$Source, 14 | [parameter(HelpMessage = "Specify the name of a loaded function.")] 15 | [Parameter( 16 | Mandatory, 17 | Position=0, 18 | ParameterSetName="name" 19 | )] 20 | [String]$Name, 21 | [Parameter(HelpMessage = "Specify the editor you want to use. On non-Windows systems enter the value in lower case.")] 22 | [ValidateSet("code","ise","notepad")] 23 | [String]$Editor = "code" 24 | ) 25 | Begin { 26 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" 27 | 28 | Switch ($Editor) { 29 | "code" { 30 | $EditorName = "VSCode" 31 | Try { 32 | #need to allow for VSCode cross-platform 33 | if ($IsCoreCLR -AND (-Not $IsWindows)) { 34 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Testing for VS Code on non-Windows platforms" 35 | $cmd = (Get-Command -Name code -ErrorAction stop).name 36 | } 37 | else { 38 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Testing for VS Code on Windows platforms" 39 | $cmd =(Get-Command -Name code.cmd -ErrorAction stop).name 40 | } 41 | $editorOK = $True 42 | if ($host.name -eq "Visual Studio Code Host") { 43 | #use the internal psedit command 44 | $sb = [scriptblock]::Create('Param($path) psedit $path') 45 | } 46 | else { 47 | $sb = [scriptblock]::Create("Param(`$path) $cmd `$path") 48 | } 49 | } 50 | Catch { 51 | $editorOK = $False 52 | } 53 | } 54 | "ise" { 55 | $EditorName = "PowerShell ISE" 56 | Try { 57 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Testing for the PowerShell ISE" 58 | [void](Get-Command -Name PowerShell_ise.exe -ErrorAction stop) 59 | $editorOK = $True 60 | if ($host.name -eq "Windows PowerShell ISE Host") { 61 | #use the internal psedit command 62 | $sb = [scriptblock]::Create('Param($path) psedit $path') 63 | } 64 | else { 65 | $sb = [scriptblock]::Create('Param($path) PowerShell_ise.exe $path') 66 | } 67 | } 68 | Catch { 69 | $editorOK = $False 70 | } 71 | } 72 | "notepad" { 73 | $EditorName = "Notepad" 74 | Try { 75 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Testing for Notepad." 76 | [void](Get-Command -Name "notepad.exe" -ErrorAction stop) 77 | $editorOK = $True 78 | $sb = [scriptblock]::Create('Param($path) notepad.exe $path') 79 | } 80 | Catch { 81 | $editorOK = $False 82 | } 83 | } 84 | } #switch 85 | If (-Not $editorOK) { 86 | Write-Warning "Failed to find $EditorName." 87 | } 88 | } #begin 89 | 90 | Process { 91 | if ($Name) { 92 | Try { 93 | $f = Get-PSFunctionInfo -FunctionName $Name -ErrorAction Stop 94 | $source = $f.source 95 | } 96 | Catch { 97 | Write-Warning "Can't find a function called $Name." 98 | } 99 | } 100 | 101 | If ((Test-Path -path $source) -AND $editorOK) { 102 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Opening $Source in $EditorName" 103 | Invoke-Command -ScriptBlock $sb -ArgumentList $source 104 | } 105 | else { 106 | Write-Warning "Failed to load function source." 107 | } 108 | } #process 109 | 110 | End { 111 | Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" 112 | } #end 113 | 114 | } #close Edit-PSFunctionInfo 115 | -------------------------------------------------------------------------------- /functions/Get-PSFunctionInfo.ps1: -------------------------------------------------------------------------------- 1 | #get function info from non-module functions 2 | Function Get-PSFunctionInfo { 3 | [CmdletBinding(DefaultParameterSetName = "name")] 4 | [OutputType("PSFunctionInfo")] 5 | [alias("gpfi")] 6 | 7 | Param( 8 | [Parameter( 9 | Position = 0, 10 | HelpMessage = "Specify the name of a function that doesn't belong to a module.", 11 | ValueFromPipeline, 12 | ValueFromPipelineByPropertyName, 13 | ParameterSetName = "name" 14 | )] 15 | [alias("Name")] 16 | [String]$FunctionName = "*", 17 | 18 | [Parameter( 19 | HelpMessage = "Specify a .ps1 file to search.", 20 | ValueFromPipelineByPropertyName, 21 | ParameterSetName = "file" 22 | )] 23 | [ValidatePattern('\.ps1$')] 24 | [ValidateScript( { 25 | if (Test-Path $_) { 26 | return $True 27 | } 28 | else { 29 | Throw "Cannot find the specified file $_." 30 | return $False 31 | } 32 | })] 33 | [alias("FullName")] 34 | [String]$Path, 35 | [Parameter(HelpMessage = "Specify a tag")] 36 | [String]$Tag 37 | ) 38 | Begin { 39 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" 40 | 41 | #a regex pattern that will be used to parse the metadata from the function definition 42 | [regex]$rx = "(?\w+)\s+(?.*)" 43 | } #begin 44 | 45 | Process { 46 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Using parameter set $($PSCmdlet.ParameterSetName)" 47 | 48 | if ($PSCmdlet.ParameterSetName -eq 'file') { 49 | 50 | $file = [System.Collections.Generic.list[String]]::New() 51 | Get-Content -Path $path | ForEach-Object { 52 | $file.add($_) 53 | } 54 | 55 | #get location of PSFunctionInfo 56 | $start = 0 57 | 58 | #need to ignore case 59 | $rxName = [System.Text.RegularExpressions.Regex]::new("(\s+)?Function\s+\S+", "IgnoreCase") 60 | do { 61 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Searching $path at $start" 62 | $i = $j = $file.FindIndex( $start, { $args[0] -match "#(\s+)?PSFunctionInfo" }) 63 | 64 | if ($i -gt 0) { 65 | 66 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Metadata found at index $i" 67 | do { 68 | $funName = $rxName.Match($file[$i]).value.trim() 69 | $i-- 70 | } until ($i -lt 0 -OR $funName) 71 | 72 | $name = $funName.split()[1] 73 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Found function $Name" 74 | $h = @{Name = $name } 75 | 76 | do { 77 | $j++ 78 | #trim off spaces in case the comment block is indented 79 | $line = $file[$j].trim() 80 | if ($line -match "\w+\s+\w+") { 81 | $meta = $line.split(" ", 2) 82 | $h.add($meta[0], $meta[1]) 83 | } 84 | } Until ($j -gt $file.count -OR $line -match "#>") 85 | 86 | #$h | Out-String | Write-Verbose 87 | Try { 88 | #calling an internal function 89 | $out = new_psfunctioninfo @h -ErrorAction Stop 90 | $out.CommandType = "function" 91 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Filtering for tag $tag" 92 | if ($PSBoundParameters.ContainsKey("Tag") -AND ($out.Tags -match $Tag)) { 93 | $out 94 | } 95 | elseif (-Not $PSBoundParameters.ContainsKey("Tag")) { 96 | $out 97 | } 98 | } 99 | Catch { 100 | Write-Warning "Failed to process $Path. $($_.Exception.message)." 101 | } 102 | $start = $j 103 | } 104 | } Until ($i -lt 0) 105 | 106 | } 107 | else { 108 | if (Test-Path Function:\$FunctionName) { 109 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Getting function $FunctionName" 110 | # filter out functions with a module source and that pass the private filtering test 111 | # 19 March 2025 - filter out functions with : in the name 112 | $functions = (Get-ChildItem -Path Function:\$FunctionName).where( { -Not $_.source -And (test_functionName $_.name) }) | Sort-Object -property Name 113 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Found $($functions.count) functions" 114 | Foreach ($fun in $functions) { 115 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] $($fun.name)" 116 | $definition = $fun.definition -split "`n" 117 | $m = $definition | Select-String -Pattern "#(\s+)?PSFunctionInfo" 118 | if ($m.count -gt 1) { 119 | Write-Warning "Multiple matches found for PSFunctionInfo in $($fun.name). Will only process the first one." 120 | } 121 | if ($m) { 122 | #get the starting line number 123 | $i = $m[0].LineNumber 124 | 125 | $meta = While ($definition[$i] -notmatch "#\>") { 126 | $raw = $definition[$i] 127 | if ($raw -match "\w+") { 128 | $raw 129 | } 130 | $i++ 131 | } 132 | 133 | #Define a hashtable that will eventually become a custom object 134 | $h = @{ 135 | Name = $fun.name 136 | CommandType = $fun.CommandType 137 | Module = $fun.Module 138 | } 139 | #parse the metadata using regular expressions 140 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Parsing metadata" 141 | for ($i = 0; $i -lt $meta.count; $i++) { 142 | $groups = $rx.Match($meta[$i]).groups 143 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] $($groups[1].value) = $($groups[2].value)" 144 | $h.add($groups[1].value, $groups[2].value.trim()) 145 | } 146 | #check for required properties 147 | if (-Not ($h.ContainsKey("Source")) ) { 148 | $h.add("Source", "") 149 | } 150 | if (-Not ($h.ContainsKey("version"))) { 151 | $h.add("Version", "") 152 | } 153 | #$h | Out-String | Write-Verbose 154 | #write the custom object to the pipeline 155 | $fi = New-Object -TypeName PSFunctionInfo -ArgumentList $h.name, $h.version 156 | 157 | #update the object with hash table properties 158 | foreach ($key in $h.keys) { 159 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Updating $key [$($h.$key)]" 160 | $fi.$key = $h.$key 161 | } 162 | if ($tag) { 163 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Filtering for tag $tag" 164 | # Write-Verbose "$($fi.name) tag: $($fi.tags)" 165 | if ($fi.tags -match $tag) { 166 | $fi 167 | } 168 | } 169 | else { 170 | $fi 171 | } 172 | #clear the variable so it doesn't get reused 173 | Remove-Variable m, h 174 | 175 | } #if metadata found 176 | else { 177 | #insert the custom type name and write the object to the pipeline 178 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Creating a new and temporary PSFunctionInfo object." 179 | $fi = New-Object PSFunctionInfo -ArgumentList $fun.name, $fun.source 180 | $fi.version = $fun.version 181 | $fi.module = $fun.Module 182 | $fi.CommandType = $fun.CommandType 183 | $fi.Description = $fun.Description 184 | 185 | #Write the object depending on the parameter set and if it belongs to a module AND has a source 186 | if (-Not $tag) { 187 | $fi 188 | } 189 | } 190 | } 191 | } #if Test-Path 192 | Else { 193 | Write-Warning "Can't find $FunctionName as a loaded function." 194 | } 195 | } #foreach 196 | 197 | } #process 198 | 199 | End { 200 | Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" 201 | } #end 202 | 203 | } #close Get-PSFunctionInfo 204 | -------------------------------------------------------------------------------- /functions/Get-PSFunctionInfoDefaults.ps1: -------------------------------------------------------------------------------- 1 | Function Get-PSFunctionInfoDefaults { 2 | [CmdletBinding()] 3 | [OutputType("PSFunctionInfoDefault")] 4 | 5 | Param() 6 | Begin { 7 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" 8 | $OutFile = Join-Path $home -ChildPath psfunctioninfo-defaults.json 9 | } #begin 10 | 11 | Process { 12 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Testing $OutFile" 13 | If (Test-Path -Path $OutFile) { 14 | Get-Content -Path $OutFile | ConvertFrom-Json | 15 | ForEach-Object { 16 | $_.PSObject.TypeNames.insert(0, 'PSFunctionInfoDefault') 17 | $_ 18 | } 19 | } 20 | else { 21 | Write-Warning "No default file found at $OutFile. Use Set-PSFunctionInfoDefaults to create it." 22 | } 23 | 24 | } #process 25 | 26 | End { 27 | Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" 28 | } #end 29 | 30 | } #close Get-PSFunctionInfoDefaults 31 | -------------------------------------------------------------------------------- /functions/Get-PSFunctionInfoTag.ps1: -------------------------------------------------------------------------------- 1 | Function Get-PSFunctionInfoTag { 2 | [CmdletBinding()] 3 | [OutputType("String")] 4 | Param() 5 | 6 | Write-Verbose "[$((Get-Date).TimeOfDay)] Starting $($MyInvocation.MyCommand)" 7 | $TagList = [System.Collections.Generic.list[String]]::new() 8 | 9 | Write-Verbose "[$((Get-Date).TimeOfDay)] Getting unique tags from Get-PSFunctionInfo" 10 | $items = (Get-PSFunctionInfo -ErrorAction stop).tags | Select-Object -Unique 11 | if ($items.count -eq 0) { 12 | Write-Warning "Failed to find any matching functions with tags" 13 | } 14 | else { 15 | Write-Verbose "[$((Get-Date).TimeOfDay)] Found at least $($items.count) tags" 16 | foreach ($item in $items) { 17 | if ($item -match ",") { 18 | #split strings into an array 19 | $item.split(",") | ForEach-Object { 20 | if (-Not $TagList.contains($_)) { 21 | $TagList.add($_.trim()) 22 | } 23 | } 24 | } #if an array of tags 25 | else { 26 | if (-Not $TagList.contains($item)) { 27 | $TagList.add($item.trim()) 28 | } 29 | } 30 | } #foreach item 31 | } #else 32 | 33 | #write the list to the pipeline 34 | $TagList | Sort-Object 35 | 36 | Write-Verbose "[$((Get-Date).TimeOfDay)] Ending $($MyInvocation.MyCommand)" 37 | 38 | } 39 | -------------------------------------------------------------------------------- /functions/New-PSFunctionInfo.ps1: -------------------------------------------------------------------------------- 1 | Function New-PSFunctionInfo { 2 | [CmdletBinding(SupportsShouldProcess)] 3 | [alias('npfi')] 4 | Param( 5 | [Parameter( 6 | Position = 0, 7 | Mandatory, 8 | HelpMessage = "Specify the name of the function" 9 | )] 10 | [ValidateNotNullOrEmpty()] 11 | [String]$Name, 12 | [Parameter(Mandatory, HelpMessage = "Specify the path that contains the function")] 13 | [ValidateNotNullOrEmpty()] 14 | [ValidateScript( { 15 | if (Test-Path $_) { 16 | return $True 17 | } 18 | else { 19 | Throw "Cannot find the specified file $_." 20 | return $False 21 | } 22 | })] 23 | [ValidatePattern("\.ps1$")] 24 | [String]$Path, 25 | [String]$Author = [System.Environment]::UserName, 26 | [String]$CompanyName, 27 | [String]$Copyright = (Get-Date).Year, 28 | [String]$Description, 29 | [ValidateNotNullOrEmpty()] 30 | [String]$Version = "1.0.0", 31 | [string[]]$Tags, 32 | [Parameter(HelpMessage = "Copy the metadata to the clipboard. The file is left untouched.")] 33 | [alias("clip")] 34 | [Switch]$ToClipboard, 35 | [Parameter(HelpMessage = "Create a backup copy of the source file before inserting the metadata comment block.")] 36 | [Switch]$Backup, 37 | [Parameter(HelpMessage = "Do not insert the source file path into the metadata comment block.")] 38 | [Switch]$NoSource 39 | ) 40 | Begin { 41 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" 42 | [guid]$Guid = $(([guid]::NewGuid()).guid) 43 | [String]$updated = Get-Date -Format g 44 | } #begin 45 | 46 | Process { 47 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Creating this metadata" 48 | 49 | if ($NoSource) { 50 | $src = $null 51 | } 52 | else { 53 | $src = $(Convert-Path $Path) 54 | } 55 | $info = @" 56 | 57 | <# PSFunctionInfo 58 | 59 | Version $Version 60 | Author $Author 61 | CompanyName $CompanyName 62 | Copyright $Copyright 63 | Description $Description 64 | Guid $Guid 65 | Tags $($Tags -join ",") 66 | LastUpdate $Updated 67 | Source $src 68 | 69 | #> 70 | "@ 71 | 72 | Write-Verbose $info 73 | if ($ToClipboard) { 74 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Copying the metadata to clipboard" 75 | if ($PSCmdlet.ShouldProcess("function metadata", "Copy to clipboard")) { 76 | Set-Clipboard -Value $info 77 | } 78 | } 79 | else { 80 | #backup file if requested 81 | if ($Backup) { 82 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Backing up the source file $Path." 83 | Try { 84 | backup_file -path $path 85 | } 86 | Catch { 87 | Throw $_ 88 | } 89 | } 90 | #get the contents of the script file 91 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Getting the file contents from $Path" 92 | 93 | $file = [System.Collections.Generic.list[String]]::New() 94 | Get-Content -Path $path | ForEach-Object { 95 | $file.add($_) 96 | } 97 | 98 | #find the function line 99 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Searching for Function $Name" 100 | $find = $file | Select-String -Pattern "^(\s+)?(F|f)unction $name(\s+|\{)?" 101 | if ($find.count -gt 1) { 102 | Write-Warning "Detected multiple matches for Function $name in $Path. Unable to insert metadata." 103 | #bail out 104 | return 105 | } 106 | elseif ($find.count -eq 1) { 107 | #$index = $file.findIndex( { $args[0] -match "^(\s+)?Function $name(\s+|\{)" }) 108 | #the index for the file list will be 1 less than the pattern match 109 | $index = $find.LineNumber - 1 110 | } 111 | else { 112 | Write-Warning "Failed to find a function called $Name in $path." 113 | return 114 | } 115 | 116 | #find the opening { for the function 117 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Getting the position of the opening {" 118 | $i = $index 119 | do { 120 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Testing index $i" 121 | if ($file[$i] -match "\{") { 122 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Found opening { at $i" 123 | $found = $True 124 | } 125 | else { 126 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] incrementing index" 127 | $i++ 128 | } 129 | } until ($found -OR $i -gt $file.count) 130 | 131 | if ($i -gt $file.count) { 132 | Write-Warning "Failed to find the opening { for Function $Name." 133 | return 134 | } 135 | 136 | #test for an existing PSFunctionInfo entry in the next 5 lines 137 | if ($file[$i..($i + 5)] | Select-String -Pattern "PSFunctionInfo" -Quiet) { 138 | Write-Warning "An existing PSFunctionInfo entry has been detected." 139 | } 140 | else { 141 | # insert after the opening { 142 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Inserting metadata at position $($i+1)" 143 | $file.Insert(($i + 1), $info) 144 | 145 | #write the new data to the file 146 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Updating $path" 147 | $file | Set-Content -Path $Path 148 | } 149 | 150 | } #else process the file 151 | } #process 152 | 153 | End { 154 | Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" 155 | } #end 156 | 157 | } #close New-PSFunctionInfo 158 | -------------------------------------------------------------------------------- /functions/Remove-PSFunctionInfo.ps1: -------------------------------------------------------------------------------- 1 | 2 | 3 | Function Remove-PSFunctionInfo { 4 | [CmdletBinding(SupportsShouldProcess)] 5 | [OutputType("None")] 6 | [alias("rpfi")] 7 | Param( 8 | [Parameter( 9 | Mandatory, 10 | Position = 0, 11 | HelpMessage = "Specify the name of a function that doesn't belong to a module.", 12 | ValueFromPipelineByPropertyName 13 | )] 14 | [alias("Name")] 15 | [String]$FunctionName, 16 | [Parameter( 17 | Mandatory, 18 | HelpMessage = "Specify the source .ps1 file for the function.", 19 | ValueFromPipelineByPropertyName 20 | )] 21 | [ValidatePattern('\.ps1$')] 22 | [ValidateScript( { 23 | if (Test-Path $_) { 24 | return $True 25 | } 26 | else { 27 | Throw "Cannot find the specified file $_." 28 | return $False 29 | } 30 | })] 31 | [alias("FullName","source")] 32 | [String]$Path 33 | ) 34 | Begin { 35 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" 36 | } #begin 37 | 38 | Process { 39 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Loading file $path" 40 | $file = [System.Collections.Generic.list[String]]::New() 41 | Get-Content -Path $path | ForEach-Object { 42 | $file.add($_) 43 | } 44 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Getting PSFunctionInfo indices for $FunctionName" 45 | 46 | Try { 47 | $index = _getInfoIndex -File $file -Name $FunctionName -ErrorAction Stop 48 | <# 49 | Name Value 50 | ---- ----- 51 | Name get-eventloginfo 52 | Version 11 53 | Author 12 54 | Company 13 55 | Copyright 14 56 | Description 100 57 | Tags 102 58 | Source 104 59 | LastUpdate 18 60 | OpenIndex 9 61 | CloseIndex 21 62 | #> 63 | } 64 | Catch { 65 | Throw $_ 66 | } 67 | 68 | if ($index) { 69 | $index | Out-String | Write-Verbose 70 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Removing lines $($index.OpenIndex) to $($index.CloseIndex)" 71 | $file.RemoveRange($index.OpenIndex,($index.CloseIndex-$index.OpenIndex+1)) 72 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Updating $path" 73 | $file | Set-Content -Path $Path 74 | } 75 | } #process 76 | 77 | End { 78 | Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" 79 | 80 | } #end 81 | 82 | } #close Remove-PSFunctionInfo 83 | -------------------------------------------------------------------------------- /functions/Set-PSFunctionInfo.ps1: -------------------------------------------------------------------------------- 1 | Function Set-PSFunctionInfo { 2 | [CmdletBinding(SupportsShouldProcess)] 3 | [alias("spfi")] 4 | 5 | Param( 6 | [Parameter( 7 | Mandatory, 8 | Position = 0, 9 | HelpMessage = "Specify the name of a function that doesn't belong to a module.", 10 | ValueFromPipeline, 11 | ValueFromPipelineByPropertyName 12 | )] 13 | [Alias("Name")] 14 | [ValidateNotNullOrEmpty()] 15 | [String]$FunctionName, 16 | 17 | [Parameter( 18 | Mandatory, 19 | HelpMessage = "Specify the .ps1 file that contains the function.", 20 | ValueFromPipelineByPropertyName 21 | )] 22 | [ValidatePattern('\.ps1$')] 23 | [ValidateScript( { 24 | if (Test-Path $_) { 25 | return $True 26 | } 27 | else { 28 | Throw "Cannot find the specified file $_." 29 | return $False 30 | } 31 | })] 32 | [alias("FullName")] 33 | [String]$Path, 34 | 35 | [Parameter(HelpMessage = "Specify the new version.")] 36 | [String]$Version, 37 | [Parameter(HelpMessage = "Specify the new author.")] 38 | [String]$Author, 39 | [Parameter(HelpMessage = "Specify the new company information.")] 40 | [String]$CompanyName, 41 | [Parameter(HelpMessage = "Specify the new copyright information.")] 42 | [String]$Copyright, 43 | [Parameter(HelpMessage = "Specify the new description.")] 44 | [String]$Description, 45 | [Parameter(HelpMessage = "Specify the new tags as a comma-separated string. This will replace existing tags.")] 46 | [String]$Tags, 47 | [Parameter(HelpMessage = "Specify the new Source.")] 48 | [String]$Source 49 | ) 50 | Begin { 51 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" 52 | $Changes = "Version", "Author", "CompanyName", "Copyright", "Description", "Tags", "Source" 53 | } #begin 54 | 55 | Process { 56 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Loading function $FunctionName from $Path " 57 | 58 | $file = [System.Collections.Generic.list[String]]::New() 59 | Get-Content -Path $Path | ForEach-Object { 60 | $file.add($_) 61 | } 62 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Getting PSFunctionInfo indices" 63 | 64 | Try { 65 | $index = _getInfoIndex -File $file -Name $FunctionName -ErrorAction Stop 66 | <# 67 | Name Value 68 | ---- ----- 69 | Name get-eventloginfo 70 | Version 11 71 | Author 12 72 | Company 13 73 | Copyright 14 74 | Description 100 75 | Tags 102 76 | Source 104 77 | LastUpdate 18 78 | OpenIndex 9 79 | CloseIndex 21 80 | #> 81 | } 82 | Catch { 83 | Throw $_ 84 | } 85 | 86 | if ($index) { 87 | $index | Out-String | Write-Verbose 88 | #process changes 89 | foreach ($item in $changes) { 90 | if ($PSBoundParameters.ContainsKey($item)) { 91 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Setting $item to $($PSBoundParameters[$item])" 92 | $file[$index.$item] = "$item $($PSBoundParameters[$item])" 93 | } 94 | } #write the new data to the file 95 | 96 | #update LastUpdate 97 | $file[$index.LastUpdate] = "LastUpdate $(Get-Date -Format g)" 98 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Updating $Path" 99 | $file | Set-Content -Path $Path 100 | } 101 | 102 | } #process 103 | 104 | End { 105 | Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" 106 | } #end 107 | 108 | } #close Set-PSFunctionInfo 109 | -------------------------------------------------------------------------------- /functions/Set-PSFunctionInfoDefaults.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Version $Version 3 | Author $Author 4 | CompanyName $CompanyName 5 | Copyright $Copyright 6 | Description $Description 7 | Guid $Guid 8 | Tags $($Tags -join ",") 9 | LastUpdate $Updated 10 | Source $(Convert-Path $Path) 11 | #> 12 | 13 | Function Set-PSFunctionInfoDefaults { 14 | [CmdletBinding(SupportsShouldProcess)] 15 | Param( 16 | [Parameter( 17 | ValueFromPipelineByPropertyName, 18 | HelpMessage = "Enter the default author name." 19 | )] 20 | [String]$Author, 21 | [Parameter( 22 | ValueFromPipelineByPropertyName, 23 | HelpMessage = "Enter the default company name." 24 | )] 25 | [String]$CompanyName, 26 | [Parameter( 27 | ValueFromPipelineByPropertyName, 28 | HelpMessage = "Enter the default copyright string" 29 | )] 30 | [String]$Copyright, 31 | [Parameter( 32 | ValueFromPipelineByPropertyName, 33 | HelpMessage = "Enter the default version" 34 | )] 35 | [String]$Version, 36 | [Parameter( 37 | ValueFromPipelineByPropertyName, 38 | HelpMessage = "Enter the default tag(s)." 39 | )] 40 | [string[]]$Tags 41 | ) 42 | Begin { 43 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" 44 | $OutFile = Join-Path $home -ChildPath psfunctioninfo-defaults.json 45 | 46 | #remove common and optional parameters if bound 47 | $common = [System.Management.Automation.Cmdlet]::CommonParameters 48 | $option = [System.Management.Automation.Cmdlet]::OptionalCommonParameters 49 | 50 | $option | ForEach-Object { 51 | #Write-Verbose "Testing for $_" 52 | if ($PSBoundParameters.ContainsKey($_)) { 53 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Removing $_" 54 | [void]$PSBoundParameters.remove($_) 55 | } 56 | } 57 | $common | ForEach-Object { 58 | #Write-Verbose "Testing for $_" 59 | if ($PSBoundParameters.ContainsKey($_)) { 60 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ]Removing $_" 61 | [void]$PSBoundParameters.remove($_) 62 | } 63 | } 64 | 65 | #get existing defaults 66 | if (Test-Path -Path $OutFile) { 67 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Getting current defaults" 68 | $current = Get-PSFunctionInfoDefaults 69 | } 70 | } #begin 71 | 72 | Process { 73 | if ($PSBoundParameters.Keys.Count -eq 0) { 74 | Write-Warning "No parameters were specified. Exiting." 75 | return 76 | } 77 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Using these new defaults" 78 | $PSBoundParameters | Out-String | Write-Verbose 79 | 80 | if ($current) { 81 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Updating current defaults" 82 | $PSBoundParameters.GetEnumerator() | ForEach-Object { 83 | if ($current.$($_.key)) { 84 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] ...$($_.key)" 85 | $current.$($_.key) = $_.value 86 | } 87 | else { 88 | #add new values 89 | Add-Member -InputObject $current -MemberType NoteProperty -Name $_.key -Value $_.value -Force 90 | } 91 | } 92 | 93 | $defaults = $current 94 | } 95 | else { 96 | $defaults = $PSBoundParameters 97 | } 98 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Saving results to $OutFile" 99 | $defaults | Out-String | Write-Verbose 100 | $defaults | ConvertTo-Json | Out-File -FilePath $OutFile -Force 101 | } #process 102 | 103 | End { 104 | If (-Not $WhatIfPreference) { 105 | Write-Verbose "[$((Get-Date).TimeOfDay) END ] Re-import the module or run Update-PSFunctionInfoDefaults to load the new values." 106 | } 107 | Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" 108 | } #end 109 | 110 | } #close Set-PSFunctionInfoDefaults 111 | -------------------------------------------------------------------------------- /functions/Update-PSFunctionInfoDefaults.ps1: -------------------------------------------------------------------------------- 1 | Function Update-PSFunctionInfoDefaults { 2 | [CmdletBinding(SupportsShouldProcess)] 3 | Param() 4 | 5 | Begin { 6 | Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" 7 | $defaults = Join-Path $home -ChildPath psfunctioninfo-defaults.json 8 | } #begin 9 | 10 | Process { 11 | Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Updating PSDefaultParameterValues " 12 | if (Test-Path -Path $defaults) { 13 | $d = Get-Content -Path $defaults | ConvertFrom-Json 14 | $d.PSObject.properties | ForEach-Object { 15 | if ($PSCmdlet.ShouldProcess($_.name)) { 16 | $global:PSDefaultParameterValues["New-PSFunctionInfo:$($_.name)"] = $_.value 17 | } 18 | } 19 | } 20 | } #process 21 | 22 | End { 23 | Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" 24 | } #end 25 | 26 | } #close Update-PSFunctionInfoDefaults 27 | -------------------------------------------------------------------------------- /functions/private.ps1: -------------------------------------------------------------------------------- 1 | Function test_functionName { 2 | [CmdletBinding()] 3 | param( 4 | [Parameter(Position = 0, Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] 5 | [String]$Name, 6 | [Switch]$Quiet 7 | ) 8 | begin { 9 | #exclude built-in Microsoft functions 10 | $exclude = "more", "cd..", "cd\", "cd~","ImportSystemModules", "Pause", "help", "TabExpansion2", "mkdir", "Get-Verb", "oss", "Clear-Host" 11 | } 12 | Process { 13 | #"^[A-Za-z]:" 14 | #19 March 2025 filter out any functions that end in a colon 15 | if ($exclude -NotContains $name -AND ($name -notmatch "^.*:$")) { 16 | if ($Quiet) { 17 | $true 18 | } 19 | else { 20 | $name 21 | } 22 | } #if the name passes the filter 23 | elseif ($Quiet) { 24 | $False 25 | } 26 | } #process 27 | End { 28 | #not used 29 | } 30 | } 31 | 32 | Function new_PSFunctionInfo { 33 | [CmdletBinding()] 34 | Param ( 35 | [String]$Name, 36 | [String]$Version, 37 | [String]$Description, 38 | [String]$Author, 39 | [String]$Source, 40 | [String]$Module, 41 | [String]$CompanyName, 42 | [String]$Copyright, 43 | [guid]$Guid, 44 | [string[]]$Tags, 45 | [DateTime]$LastUpdate, 46 | [String]$CommandType 47 | ) 48 | 49 | # Write-Verbose "creating new object Using these parameters" 50 | # $PSBoundParameters | Out-String | Write-Verbose 51 | $obj = [PSFunctionInfo]::new([String]$Name, [String]$Author, [String]$Version, [String]$Source, [String]$Description, [String]$Module, [String]$CompanyName, [String]$Copyright, [guid]$Guid, [DateTime]$LastUpdate, [String]$Commandtype) 52 | if ($tags) { 53 | $obj.Tags = $Tags 54 | } 55 | $obj 56 | } 57 | 58 | function backup_file { 59 | [CmdletBinding(SupportsShouldProcess)] 60 | Param( 61 | [Parameter(Mandatory)] 62 | [alias("FullName")] 63 | [String]$Path 64 | ) 65 | 66 | #The path is the full file system name to the ps1 file. 67 | 68 | $folder = Split-Path -Path $path 69 | $filename = Split-Path -Path $path -Leaf 70 | $i = 0 71 | 72 | do { 73 | $i++ 74 | $new = Join-Path -Path $Folder -child "$filename.bak$i" 75 | } Until (-Not (Test-Path -Path $New)) 76 | 77 | Write-Verbose "[$((Get-Date).TimeOfDay) PRIVATE] Backing up $path to $new" 78 | Try { 79 | Copy-Item -Path $path -Destination $new -ErrorAction stop 80 | } 81 | Catch { 82 | #this shouldn't happen. 83 | Throw "Failed to create backup copy $new. $($_.exception.message)" 84 | } 85 | } 86 | 87 | function _getInfoIndex { 88 | [CmdletBinding()] 89 | Param([System.Collections.Generic.list[String]]$File, [String]$Name) 90 | 91 | #find index of function name 92 | $idx = $file.FindIndex({ $args[0] -match "function $Name" }) 93 | if ($Idx -eq -1) { 94 | Throw "Could not find function $name" 95 | } 96 | #find index of PSFunction Info 97 | $openIdx = $file.FindIndex($idx, { $args[0] -match "PSFunctionInfo" }) 98 | if ($openIdx -eq -1) { 99 | Throw "Could not find PSFunctionInfo for $name" 100 | } 101 | $CloseIdx = $file.FindIndex($openIdx, { $args[0] -eq "#>" }) 102 | 103 | #Find index of Version|Description|LastUpdate starting from the function index 104 | $versionIdx = $file.FindIndex($openIdx, { $args[0] -match '^Version\s.*$' }) 105 | $descriptionIdx = $file.FindIndex($openIdx, { $args[0] -match '^Description(\s.*)?$' }) 106 | $lastUpdateIdx = $file.FindIndex($openIdx, { $args[0] -match '^LastUpdate\s.*$' }) 107 | $authorIdx = $file.FindIndex($openIdx, { $args[0] -match '^Author(\s.*)?$' }) 108 | $tagsIdx = $file.FindIndex($openIdx, { $args[0] -match '^Tags(\s.*)?$' }) 109 | $companyIdx = $file.FindIndex($openIdx, { $args[0] -match '^CompanyName(\s.*)?$' }) 110 | $copyIdx = $file.FindIndex($openIdx, { $args[0] -match '^Copyright(\s.*)?$' }) 111 | $sourceIdx = $file.FindIndex($openIdx, { $args[0] -match '^Source(\s.*)?$' }) 112 | 113 | [ordered]@{ 114 | Name = $Name 115 | Version = $versionIdx 116 | Author = $authorIdx 117 | CompanyName = $companyIdx 118 | Copyright = $copyIdx 119 | Description = $descriptionIdx 120 | Tags = $tagsIdx 121 | LastUpdate = $lastUpdateIdx 122 | Source = $sourceIdx 123 | OpenIndex = $openIdx 124 | CloseIndex = $CloseIdx 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /functions/public.ps1: -------------------------------------------------------------------------------- 1 | # define an object class for the Get-PSFunctionInfo command 2 | 3 | class PSFunctionInfo { 4 | [String]$Name 5 | [version]$Version 6 | [String]$Description 7 | [String]$Author 8 | [String]$Source 9 | [String]$Module 10 | [String]$CompanyName 11 | [String]$Copyright 12 | [guid]$Guid 13 | [string[]]$Tags 14 | [DateTime]$LastUpdate 15 | [String]$CommandType 16 | 17 | #this class has no methods 18 | 19 | #constructors 20 | PSFunctionInfo([String]$Name, [String]$Source) { 21 | $this.Name = $Name 22 | $this.Source = $Source 23 | } 24 | PSFunctionInfo([String]$Name, [String]$Author, [String]$Version, [String]$Source, [String]$Description, [String]$Module, [String]$CompanyName, [String]$Copyright, [guid]$Guid, [DateTime]$LastUpdate, [String]$Commandtype) { 25 | $this.Name = $Name 26 | $this.Author = $Author 27 | $this.Version = $Version 28 | $this.Source = $Source 29 | $this.Description = $Description 30 | $this.Module = $Module 31 | $this.CompanyName = $CompanyName 32 | $this.Copyright = $Copyright 33 | #$this.Tags = $Tags 34 | $this.guid = $Guid 35 | $this.LastUpdate = $LastUpdate 36 | $this.CommandType = $CommandType 37 | } 38 | } 39 | #endregion 40 | -------------------------------------------------------------------------------- /images/get-psfunctioninfo-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/PSFunctionInfo/db3b6d47945420a88004a489aaa53cb8bf956e8d/images/get-psfunctioninfo-1.png -------------------------------------------------------------------------------- /images/get-psfunctioninfo-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/PSFunctionInfo/db3b6d47945420a88004a489aaa53cb8bf956e8d/images/get-psfunctioninfo-2.png -------------------------------------------------------------------------------- /images/get-psfunctioninfo-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/PSFunctionInfo/db3b6d47945420a88004a489aaa53cb8bf956e8d/images/get-psfunctioninfo-3.png -------------------------------------------------------------------------------- /images/get-psfunctioninfo-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/PSFunctionInfo/db3b6d47945420a88004a489aaa53cb8bf956e8d/images/get-psfunctioninfo-file.png -------------------------------------------------------------------------------- /images/ise-function-picker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/PSFunctionInfo/db3b6d47945420a88004a489aaa53cb8bf956e8d/images/ise-function-picker.png -------------------------------------------------------------------------------- /images/ise-psfunction-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/PSFunctionInfo/db3b6d47945420a88004a489aaa53cb8bf956e8d/images/ise-psfunction-menu.png -------------------------------------------------------------------------------- /images/ise-psfunctioninfo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/PSFunctionInfo/db3b6d47945420a88004a489aaa53cb8bf956e8d/images/ise-psfunctioninfo.png -------------------------------------------------------------------------------- /images/psfunctioninfo-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/PSFunctionInfo/db3b6d47945420a88004a489aaa53cb8bf956e8d/images/psfunctioninfo-icon.png -------------------------------------------------------------------------------- /images/psfunctioninfo-vscode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdhitsolutions/PSFunctionInfo/db3b6d47945420a88004a489aaa53cb8bf956e8d/images/psfunctioninfo-vscode.png -------------------------------------------------------------------------------- /types/psfunctioninfo.types.ps1xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | PSFunctionInfo 5 | 6 | 7 | AuthorInfo 8 | 9 | Name 10 | Version 11 | Source 12 | CompanyName 13 | Copyright 14 | Description 15 | LastUpdate 16 | 17 | 18 | 19 | TagInfo 20 | 21 | Name 22 | Version 23 | Tags 24 | Source 25 | 26 | 27 | 28 | PSStandardMembers 29 | 30 | 31 | 32 | DefaultDisplayPropertySet 33 | 34 | Name 35 | Version 36 | Source 37 | Module 38 | 39 | 40 | 41 | 42 | 43 | Path 44 | Source 45 | 46 | 47 | Alias 48 | (Get-Alias -Definition $this.Name -ErrorAction SilentlyContinue).name 49 | 50 | 51 | 52 | --------------------------------------------------------------------------------