- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add help in the PowerShell function?
When we write a program, people from a non-programming background often expect to get much possible help related to the program. When we write the function and we declare the parameters, people who are unaware of what kind of input the parameter need, generally search for the help first using the Get-Help command and then they find only the parameters but not the description of it. For example,
function TestFunct{ param( #16 Digit Application ID [parameter(Mandatory=$true)] [String]$AppID, #Date in the Unix Format - 2020-10-31T17:12:10+0530 [String]$Date ) }
In the above example, there are two parameters specified and when the user gets help with the function, it doesn’t specify the comments where the parameter description is given. For example,
PS C:\> help TestFunct -Parameter * -AppID <string> Required? true Position? 0 Accept pipeline input? false Parameter set name (All) Aliases None Dynamic? false -Date <string> Required? false Position? 1 Accept pipeline input? false Parameter set name (All) Aliases None Dynamic? false
To add the description from the comment, we need to add the comment-based help and need to use SYNOPSIS from the comment-based help.
Example
function TestFunct{ <# .SYNOPSIS This is test function for parameter based help #> param( #16 Digit Application ID [parameter(Mandatory=$true)] [String]$AppID, #Date in the Unix Format - 2020-10-31T17:12:10+0530 [String]$Date ) }
Now when we check the parameter, we get the comment based description.
PS C:\> help TestFunct -Parameter * -AppID <String> 16 Digit Application ID Required? true Position? 1 Default value Accept pipeline input? false Accept wildcard characters? false -Date <String> Date in the Unix Format - 2020-10-31T17:12:10+0530 Required? false Position? 2 Default value Accept pipeline input? false Accept wildcard characters? false
- Related Articles
- How to use PowerShell Help commands?
- How to write comment based Help in PowerShell?
- How to add/remove values in the array in PowerShell?
- How to pass the parameters in the PowerShell function?
- How to add multiple values in the Hashtable using PowerShell?
- How to use the ValidateRange attribute in PowerShell function?
- How to use the ValidateSet Attribute in PowerShell function?
- How to use the ValidateScript attribute in PowerShell function?
- How to use the ValidateCount attribute in PowerShell Function?
- How to use function Alias in PowerShell?
- How to add a new element in the XML using PowerShell?
- How to add/merge two hash tables in PowerShell?
- How to add and remove values to the Hash Table in PowerShell?
- How to add the entry in the windows host file using PowerShell?
- How to add the tag of Azure VM using PowerShell?
