简单的答案是从第一个参数中删除数组选项,并分配位置参数,然后像这样使用ValueFromRemain ...
简单验证了一下PowerShell对C#编译的PowerShellModule中的变量是否同一引用。 代码如下: namespacePowershellModule{[Cmdlet(VerbsDiagnostic.Test,"SampleCmdlet")][OutputType(typeof(FavoriteStuff))]publicclassTestSampleCmdletCommand:PSCmdlet{[Parameter(Mandatory=true,Position=0,ValueFromPipelineByPropertyName=true)]...
简单的答案是从第一个参数中删除数组选项,并分配位置参数,然后像这样使用ValueFromRemain ...
ParameterName : InputObject ParameterType : System.ServiceProcess.ServiceController[] ValueFromPipeline : True ValueFromPipelineByPropertyName : False ParameterName : Name ParameterType : System.String[] ValueFromPipeline : True ValueFromPipelineByPropertyName : True 總結...
ValueFromPipelineByPropertyName 参数指示参数接受管道对象的属性的输入。 对象属性必须与参数具有相同的名称或别名。例如,如果函数具有 ComputerName 参数,并且管道对象具有 ComputerName 属性,则会将 ComputerName 属性的值分配给函数的 ComputerName 参数。以下示例声明一个 ComputerName 参数,该参数是必需的...
按属性名称接受管道输入与此相似,不同之处在于使用ValueFromPipelineByPropertyName参数属性来指定它,并且这可以为任意数量的参数指定,而无需考虑数据类型。 关键是,管道传入的命令输出必须有一个属性名称,该属性名称需要与函数的参数名称或参数别名相匹配。
[Parameter(Mandatory=true,ValueFromPipelineByPropertyName=true,ParameterSetName=ParameterSetLiteralFileRaw)] [FileinfoToString] [Alias("PSPath","LP")] publicstring[]LiteralPath { get=>Path; set { Path=value; _isLiteralPath=true; } }
[Parameter(ValueFromPipeline = $true)]Here's our revised function with the added ValueFromPipeline parameter.function Get-DirectoryFileSize { param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [string] $Directory ) if (Test-Path -Path $Directory) { Get-ChildItem -Path $...
Function Do-Something { [CmdletBinding()] param( [Parameter(Mandatory=$True, ValueFromPipeline=$True)] [string[]]$computername ) BEGIN {} PROCESS {} END {} } 有几个有关这些 cmdlet 的混乱方面。 例如,在该形状中,已定义的输入的参数调用的计算机名。 这可以接受输入的管道。 这意味着您可以在两...
代码的问题在于读取begin块中的ParameterSetName属性。当命令接受管道输入时,输入对象可能会影响选定的...