gpt4 book ai didi

powershell - 当命令行开关接受管道输入时,ByPropertyName 和 ByValue 之间有什么区别?

转载 作者:行者123 更新时间:2023-12-04 17:09:56 29 4
gpt4 key购买 nike

一些 PowerShell commandlet 接受管道输入 ByProperyName,一些接受 ByValue,另一些接受两者兼而有之。这是什么意思?它如何影响我们的 PowerShell 脚本?

最佳答案

ValueFromPipeline parameter attribute将参数值映射到从管道传入的任何对象类型。如果您使用 ValueFromPipelineByPropertyName parameter attribute ,然后将使用管道到命令+参数的对象中的特定属性。

ValueFromPipeline 示例

Get-Process | Stop-Process; # Stop-Process expects to receive a Process object

<#
-InputObject <Process[]>
Stops the processes represented by the specified process objects. Enter a variable that contains the objects, or
type a command or expression that gets the objects.

Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
#>

ValueFromPipelineByPropertyName 示例
# Get-Process looks for a ComputerName property on the incoming objects
[PSCustomObject]@{
ComputerName = 'localhost';
} | Get-Process;

<#
-ComputerName <String[]>
Gets the processes running on the specified computers. The default is the local computer.

Type the NetBIOS name, an IP address, or a fully qualified domain name of one or more computers. To specify the
local computer, type the computer name, a dot (.), or "localhost".

This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Get-Process
even if your computer is not configured to run remote commands.

Required? false
Position? named
Default value Local computer
Accept pipeline input? True (ByPropertyName)
Accept wildcard characters? false
#>

关于powershell - 当命令行开关接受管道输入时,ByPropertyName 和 ByValue 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21117947/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com