我想填充在$ PROFILE中创建的Powershell函数的Description属性。我想向Description属性添加一个值,例如“在个人PROFILE中创建”。这可能吗?
当前,如果我检查我的功能说明,我发现没有人填写,例如:
Get-Command -Type Function -Name get-* | Select-Object -Property Name, Description -First 10
Name Description
---- -----------
Get-AlertLog
Get-AllColors
Get-AppBackgroundTask
Get-AppvVirtualProcess
Get-AppxLastError
Get-AppxLog
Get-AssignedAccess
Get-AutologgerConfig
Get-BCClientConfiguration
Get-BCContentServerConfiguration
填充值将使我能够搜索并快速查看函数的创建位置或作用等。
谢谢。
+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜 +〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜
注意:
我不想通过Get-Help检索信息,而是填充一些Type的属性:System.Management.Automation.FunctionInfo:
Get-Command -Type Function -Name Get-AllColors | Get-Member
TypeName: System.Management.Automation.FunctionInfo
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ResolveParameter Method System.Management.Automation.ParameterMetadata ResolveParameter(string name)
ToString Method string ToString()
CmdletBinding Property bool CmdletBinding {get;}
CommandType Property System.Management.Automation.CommandTypes CommandType {get;}
DefaultParameterSet Property string DefaultParameterSet {get;}
Definition Property string Definition {get;}
Description Property string Description {get;set;}
HelpFile Property string HelpFile {get;}
Module Property psmoduleinfo Module {get;}
ModuleName Property string ModuleName {get;}
Name Property string Name {get;}
Noun Property string Noun {get;}
Options Property System.Management.Automation.ScopedItemOptions Options {get;set;}
OutputType Property System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.PS...
Parameters Property System.Collections.Generic.Dictionary[string,System.Management.Automation.Paramet...
ParameterSets Property System.Collections.ObjectModel.ReadOnlyCollection[System.Management.Automation.Co...
RemotingCapability Property System.Management.Automation.RemotingCapability RemotingCapability {get;}
ScriptBlock Property scriptblock ScriptBlock {get;}
Source Property string Source {get;}
Verb Property string Verb {get;}
Version Property version Version {get;}
Visibility Property System.Management.Automation.SessionStateEntryVisibility Visibility {get;set;}
HelpUri ScriptProperty System.Object HelpUri {get=$oldProgressPreference = $ProgressPreference...
另一种询问方式是“如果没有方法用值填充属性并通过Select-Object -Property检索它们,为什么会有这样的Type?”
谢谢。
最佳答案
您应该使用基于注释的帮助,而不是使用功能。基于注释的帮助将允许您使用PowerShell的内置帮助系统。编写起来并不难,甚至不需要使用所有部分。
这是TechNet on about_Comment_Based_Help,并带有一些示例:
The syntax for comment-based Help is as follows:
# .< help keyword> # <help content>
-or -
<# .< help keyword> < help content> #>
您必须确保正确拼写了类别,否则功能上的全部帮助将不会显示,并且您不会收到错误消息。一个简单的示例,只包含一个提要和说明:
.SYNOPSIS A brief description of the function or script. This keyword can be used only once in each topic. .DESCRIPTION A detailed description of the function or script. This keyword can be used only once in each topic.
阅读链接文章,了解所有关键字及其说明。通过运行
get-help about_comment_based_help
可以找到类似的信息
关于powershell - 如何为Powershell函数的description属性添加值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3304423/