You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否通过ByPropertyName管道绑定New-Item的-Value参数?

关于New-Item的-Value参数管道ByPropertyName绑定的问题解答

通过Help New-item -parameter "Value"可以确认,-Value <System.Object>参数同时支持ByPropertyName和ByValue两种管道绑定方式,但由于ByValue的优先级高于ByPropertyName,目前无法通过管道实现对该参数的ByPropertyName绑定。

即使管道左侧的对象带有Value属性,PowerShell仍会优先通过ByValue将整个对象绑定到-Value参数,而非提取对象的Value属性值进行绑定。

示例验证

$customObject = [PSCustomObject]@{
    Value = "Lorem ipsum"
}

$customObject | New-Item -Name BPN_value.txt

运行上述代码后,生成的BPN_value.txt文件内容为@{Value = "Lorem ipsum"}——这证明$customObject是作为一个整体通过ByValue绑定到-Value参数,而非使用其Value属性的具体值。


内容的提问来源于stack exchange,提问作者Eduardo Fernández

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 12:20:26