-
Notifications
You must be signed in to change notification settings - Fork 163
Powershell Dynamic Parameters and How to Add Them to the Get‐Help Syntax
PowerShell has a feature called dynamic parameters that allows you to add parameters to a cmdlet based on the value of another parameter. This is useful when you have a parameter that can take multiple values and you want to add additional parameters based on the value of the first parameter.
Dynamic parameters also allow you to make a parameter conditionally mandatory based on different criteria.
They are very powerful but have a downside: since they are runtime-defined, they are not displayed in the Get-Help output. This can be a problem if you want to provide help to users of your cmdlet and inform them of all of the available parameters that your cmdlet supports, including the dynamic ones.
Usually, PowerShell developers use comment-based help inside of the cmdlet's function to provide help content to the user, however that approach doesn't allow us to control all aspects of the help content, such as the syntax. If you want to add the dynamic parameters to the Get-Help output's syntax, you will need to switch to XML-based help.
PlatyPS is a module that allows you to generate XML-based help for your cmdlets. It can be used to add dynamic parameters to the Get-Help output's syntax. You will be editing a Markdown file which is convenient and the module will automatically generate the XML help file for you.
New-MarkdownHelp -Command 'YourCmdletName' -OutputFolder ".\docs"
After you've created a markdown file based on your current cmdlet's parameters and details, you can start adding the dynamic parameters to it and modify the syntax, because dynamic parameters are not automatically added to it. Once you are done, you can run the following command to generate the XML help file.
New-ExternalHelp -Path "Path-To-Markdown-File.md" -OutputPath "Path-To-XML-File.xml" -Force
After creating your XML-based help file, you will then have to reference it in your cmdlet's function like this
.EXTERNALHELP .\Help\Cmdlet-Name.xml
The path doesn't accept variables but it can be either relative or full path to the XML help file. Once you reference that, you can either remove all of the comment-based help from the function or keep them, the XML-based help takes precedence over the comment-based help when both types of help content are present.
- PlatyPS on GitHub
- PlatyPS on PowerShell Gallery
- PlatyPS cmdlet guides on Microsoft Learn
- How to add syntax to a cmdlet help topic
- Writing Help for PowerShell Cmdlets
- Create AppControl Policy
- Create Supplemental Policy
- System Information
- Configure Policy Rule Options
- Simulation
- Allow New Apps
- Build New Certificate
- Create Policy From Event Logs
- Create Policy From MDE Advanced Hunting
- Create Deny Policy
- Merge App Control Policies
- Deploy App Control Policy
- Get Code Integrity Hashes
- Get Secure Policy Settings
- Update
- Sidebar
- Introduction
- App Control for Lightly Managed Devices
- App Control for Fully managed device - Variant 1
- App Control for Fully managed device - Variant 2
- App Control for Fully managed device - Variant 3
- App Control for Fully managed device - Variant 4
- App Control Notes
- How to Create and Deploy a Signed App Control Policy
- Fast and Automatic Microsoft Recommended Driver Block Rules updates
- App Control policy for BYOVD Kernel mode only protection
- EKUs in App Control for Business Policies
- App Control Rule Levels Comparison and Guide
- Script Enforcement and PowerShell Constrained Language Mode in App Control Policies
- How to Use Microsoft Defender for Endpoint Advanced Hunting With App Control
- App Control Frequently Asked Questions (FAQs)
- Create Bootable USB flash drive with no 3rd party tools
- Event Viewer
- Group Policy
- How to compact your OS and free up extra space
- Hyper V
- Overrides for Microsoft Security Baseline
- Git GitHub Desktop and Mandatory ASLR
- Signed and Verified commits with GitHub desktop
- About TLS, DNS, Encryption and OPSEC concepts
- Things to do when clean installing Windows
- Comparison of security benchmarks
- BitLocker, TPM and Pluton | What Are They and How Do They Work
- How to Detect Changes in User and Local Machine Certificate Stores in Real Time Using PowerShell
- Cloning Personal and Enterprise Repositories Using GitHub Desktop
- Only a Small Portion of The Windows OS Security Apparatus
- Rethinking Trust: Advanced Security Measures for High‐Stakes Systems
- Clean Source principle, Azure and Privileged Access Workstations
- How to Securely Connect to Azure VMs and Use RDP
- Basic PowerShell tricks and notes
- Basic PowerShell tricks and notes Part 2
- Basic PowerShell tricks and notes Part 3
- Basic PowerShell tricks and notes Part 4
- Basic PowerShell tricks and notes Part 5
- How To Access All Stream Outputs From Thread Jobs In PowerShell In Real Time
- PowerShell Best Practices To Follow When Coding
- How To Asynchronously Access All Stream Outputs From Background Jobs In PowerShell
- Powershell Dynamic Parameters and How to Add Them to the Get‐Help Syntax
- RunSpaces In PowerShell
- How To Use Reflection And Prevent Using Internal & Private C# Methods in PowerShell