2016-10-11 92 views
1

我想填充我在$ PROFILE中創建的Powershell函數的Description屬性。我想爲Description屬性添加一個值,例如「Created in personal PROFILE」。這可能嗎?如何將值添加到PowerShell功能的描述屬性?

目前,如果我檢查我的職務,我覺得沒有被填充的說明,例如:

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 

有填充,讓我來搜索和快速查看值,其中創建我的功能,或者是什麼他們這樣做等。

謝謝。

+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+ +〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜+〜

注:

我不想檢索通過獲取幫助的信息,而是填充某些類型的屬性: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檢索它們?「

謝謝。

回答

3

您應該使用基於評論的幫助,而不是使用功能。基於評論的幫助將允許您使用PowerShell的幫助系統中的內部版本。這不難寫,你甚至不需要使用所有的部分。

這裏是TechNet on about_Comment_Based_Help,有一些例子:

發表評論基於幫助的語法如下:

# .< help keyword> 
# <help content> 

- 或 -

<# 
    .< help keyword> 
    < help content> 
#> 

你必須確保類別拼寫正確,否則整個hel對你的功能p不會出現,你不會得到一個錯誤信息。只是有一個大綱和說明一個簡單的例子:

.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

1

找到可以使用Comment-Based Help的描述(和許多其他信息)添加到您的功能:

SYNTAX FOR COMMENT-BASED HELP 
    The syntax for comment-based help is as follows: 

     # .< help keyword> 
     # <help content> 

    -or - 

     <# 
      .< help keyword> 
      < help content> 
     #> 

例子:

function Add-Extension 
{ 
     param ([string]$Name,[string]$Extension = "txt") 
     $name = $name + "." + $extension 
     $name 

    <# 
    .SYNOPSIS 
    Adds a file name extension to a supplied name. 

    .DESCRIPTION 
    Adds a file name extension to a supplied name. 
    Takes any strings for the file name or extension. 
    } 
+0

Brian/@Matt - – catiarx