powershell - Rum Get-MrPiplelineInput 但得到 5 个相同的结果
问题描述
我跑Get-MrPipelineInput -name get-help
但得到:
ParameterName ParameterType ValueFromPipeline ValueFromPipelineByPropertyName
------------- ------------- ----------------- -------------------------------
Name System.String False True
Name System.String False True
Name System.String False True
Name System.String False True
Name System.String False True
Name System.String False True
获得 4 个额外的 Name 相同结果。
我使用 Get-MrPipelienInput 有什么问题吗?
解决方案
我不认为你在这里做错了什么。我认为问题实际上出在代码中。Get-Help
可能不同于大多数/所有其他 PS Cmdlet/Function 的结构,因此不符合 Mike Robbins(此工具的作者)所期望的结构。
在闲逛了几分钟后,我可以看到这里发生了什么。
Get-Help
有 6 个参数集。在每一个中,唯一允许来自管道的值的参数是Name
. 可以对Mike 的 Miscellaneous PowerShell Tools Code进行简单的改进,使其成为更好的工具。
function Get-MrPipelineInput {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]$Name,
[System.Management.Automation.WhereOperatorSelectionMode]$Option = 'Default',
[ValidateRange(1, 2147483647)]
[int]$Records = 2147483647
)
$FunctionOutput = [System.Collections.ArrayList]::new()
(Get-Command -Name $Name).ParameterSets.ForEach{
$ParameterSet = $PSItem
$PSItem.Parameters.Where( {
$_.ValueFromPipeline -or $_.ValueFromPipelineByPropertyName
}, $Option, $Records).ForEach( {
$null = $FunctionOutput.Add(
[pscustomobject]@{
ParameterSetName = $ParameterSet.Name
ParameterName = $_.Name
ParameterType = $_.ParameterType
ValueFromPipeline = $_.ValueFromPipeline
ValueFromPipelineByPropertyName = $_.ValueFromPipelineByPropertyName
})
})
}
$FunctionOutput
}
运行它会产生一个更容易理解的输出:
PS > (Get-MrPipelineInput -Name Get-Help | ft)
ParameterSetName ParameterName ParameterType ValueFromPipeline ValueFromPipelineByPropertyName
---------------- ------------- ------------- ----------------- -------------------------------
AllUsersView Name System.String False True
DetailedView Name System.String False True
Examples Name System.String False True
Parameters Name System.String False True
Online Name System.String False True
ShowWindow Name System.String False True
我希望这可以帮到你!
推荐阅读
- python - 非关键字变量名的python“TypeError:不支持的操作数类型-:'builtin_function_or_method'和'int'”中的错误?
- r - R markdown HTML文件中自定义和反应图形的编号标题
- javascript - 省略或跳过图表js中x轴区域的间隔
- hadoop - Impala 和 mem_limit
- android - Android MotionLayout 在 RecyclerView 滚动时崩溃
- python - 属性错误:“_tkinter.tkapp”对象没有属性“根”
- scala - 如何在 IntelliJ IDEA 中添加新的 SBT shell 选项卡?
- android - 使用 AAR 进行虚幻 Android 开发
- python - 递归中的python列表是否不会更改为其先前的值?
- java - 对于 400 Bad Request 没有得到正确的错误信息