PowerShell 3.0 中的$PSItem


在PowerShell中,变量“$_”有一个很重要的用途,它就像一个占位符一样,代表着从管道中流过的当前元素。例如:

Get-ChildItem $env:windir | Where-Object { $_.Length -gt 1MB }

但是在PowerShell 3.0 中上述的那个变量还有一个别名,而且更具描述性。

Get-ChildItem $env:windir | Where-Object { $PSItem.Length -gt 1MB }

更方便的是,在PowerShell 3.0 中,无论是$PSItem还是“$_” 都可以省略,写成下面的格式。

Get-ChildItem $env:windir | Where-Object Length -gt 1MB

原文链接:http://powershell.com/cs/blogs/tips/archive/2012/10/23/psitem-in-powershell-v3.aspx

本文链接: https://www.pstips.net/psitem-in-powershell-v3.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

关于 Mooser Lee

我是一个Powershell的爱好者,创建了PowerShell中文博客,热衷于Powershell技术的搜集和分享。本站部分内容来源于互联网,不足之处敬请谅解,并欢迎您批评指正。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注