如何为 powershell 函数的描述属性添加值?

2024-03-12

我想填充我在 $PROFILE 中创建的 Powershell 函数的 Description 属性。我想向“描述”属性添加一个值,例如“在个人配置文件中创建”。这可能吗?

目前,如果我检查我的功能描述,我发现没有填充任何内容,例如:

    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

填充该值将使我能够搜索并快速查看我的函数是在哪里创建的,或者它们做什么,等等。

谢谢。

+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~ +~+~+~+~+~+~+~+~+~+~+~+~+~+~+~

Note:

我不想通过 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 检索它们,为什么会有这样的类型?”

谢谢。


您应该使用基于注释的帮助而不是使用功能。基于注释的帮助将允许您使用 PowerShell 的内置帮助系统。编写起来并不难,您甚至不需要使用所有部分。

这里是TechNet 上的 about_Comment_Based_Help http://technet.microsoft.com/en-us/library/dd819489.aspx,举一些例子:

基于注释的帮助的语法如下:

# .< 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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何为 powershell 函数的描述属性添加值? 的相关文章

随机推荐

  • React 中的 getElementById

    目前出现此错误 Uncaught TypeError Cannot read property value of null 我在下面的渲染函数中调用它
  • 触发单击 SVG 图像

    我正在尝试使用 SVG 图像 看看是否可以为我的网站创建地图 我从第三方网站获取了该图像 现在我只是尝试实现它 这是我所拥有的一个小提琴 https jsfiddle net hL1weg3o 1 https jsfiddle net hL
  • 使用 ctypes 从 Python 调用 fortran 函数

    我希望使用 ctypes 来调用一些旧的 Fortran 库 这些库是我老板几年前编写的 我按照中给出的例子进行操作上一个问题 https stackoverflow com questions 5811949 call functions
  • 如何在Python中实现自己的自定义字典类

    我正在学习 python 课程 并且正在尝试创建我自己的版本defaultdict from collections模块 这是我尝试过的 class Mydict dict def missing self key self key ret
  • 如何使 @Controller 映射路径可配置?

    我正在构建一个内部库 它应该自动向 Spring MVC 应用程序添加一些控制器 这些控制器都是 RestController一些带有注释的处理程序方法 RequestMapping 由于它是一个库 我希望用户能够指定库应公开所有这些控制器
  • 在 ngOnInit Angular 之前处理异步 Promise

    我有一个返回表数据的请求 需要像等待数据加载的承诺一样处理该请求 为了将数据加载到表中 我必须使用异步 等待 但这会弄乱所有其他函数 方法 如何在 ngOnInit 上不使用 async wait 的情况下将数据存储在 currentLis
  • 直接调用LayoutInflater和不调用LayoutInflater有什么区别?

    我浏览了一些教程 在 Android Doc 中 它说在实例化 LayoutInflater 时不要直接访问它 谷歌文档中的示例 LayoutInflater inflater LayoutInflater context getSyste
  • 我们可以在没有 hibernate.cfg.xml 的情况下配置 Hibernate

    下面是hibernate cfg xml
  • 找不到路径为 Platform SDK 的平台:platforms;android-31

    我正打算将支持 SDK 更新到最新版本的 Android 即 SDK 31 S 但 Gradle 同步存在一些问题 错误 Failed to notify build listener Could not resolve all depen
  • 从命令行登录 Firebase 工具

    我正在使用 Codeship 部署 firebase 应用程序 为此 我首先需要使用firebase login命令 问题是 我需要在浏览器中登录 然后返回命令行并执行部署 是否有一种自动方式向 Firebase 提供凭据 Cheers f
  • cursor.toArray() 返回一个承诺而不是数组

    目前使用node 4 3 2和mongo 2 6 我正在尝试获取整个集合 集合中当前有三个文档 当我使用这段代码时 我遇到了一个问题 function checkUpdateTime last updated var collection
  • 如何转换上传的视频并从此文件获取屏幕截图?

    我正在构建一个CMS 我希望用户能够上传视频 但我不熟悉视频上传和转换 有没有例子或者有人编写了这样的解决方案 我听说过 ffmpeg 但我不知道如何将它与 asp net 集成 作为简单的解决方案 我可以让我的客户上传 flv 文件 但我
  • 如何向 graphql 中的输入参数添加默认值

    我有这种输入类型 我想向其中一个字段添加默认值 我想将 0 添加到 ExampleInput 内的值字段 type ExampleType value Int another String type Mutation example inp
  • 在dispatch_async中正确引用self

    如何在快速关闭中正确引用 self dispatch async dispatch get main queue self popViewControllerAnimated true 我收到错误 Cannot convert the ex
  • django-admin 中的模型描述

    django admin中是否可以在某个模型的列表显示页面上放置模型描述或描述 我说的是当你点击 django admin 主页上的模型名称链接并进入该模型的列表显示页面时 表格顶部将写有说明 就像是 该模型用于记录将通过我们的抓取获取的所
  • SVG 容器在 Safari 桌面中呈现错误的大小(在 Chrome/iOS 中正常)

    我以为 Safari 已经解决了这个问题 但它似乎仍然是一个问题 除非我做了一些明显错误的事情 我在对象标签内放置了一个 SVG 它被包裹在一个灵活的包含 DIV 中 例如设置为宽度 50 在调整大小时 容器高度在 Firefox Chro
  • JPMS支持模块版本吗?

    我以为JPMS不支持模块版本 然而 当我这样做时java list modules我有以下输出 java activation 9 java base 9 java compiler 9 java corba 9 java datatran
  • 使用 jenkins 执行 wsl.exe 返回 exit -1073740791

    我在一台具有 WSL 适用于 Linux 的 Windows 子系统 的 Windows 10 计算机上设置了 jenkins 例如 当我从终端运行简单命令 C Windows System32 wsl exe help 时 它工作正常 使
  • 删除 Shapely 多边形外部的 numpy 网格点

    我有一个 10 x 10 网格 我想删除形状多边形之外的点 import numpy as np from shapely geometry import Polygon Point from descartes import Polygo
  • 如何为 powershell 函数的描述属性添加值?

    我想填充我在 PROFILE 中创建的 Powershell 函数的 Description 属性 我想向 描述 属性添加一个值 例如 在个人配置文件中创建 这可能吗 目前 如果我检查我的功能描述 我发现没有填充任何内容 例如 Get Co