What is the `.` shorthand for in a PowerShell pipeline?

前端 未结 2 421
北海茫月
北海茫月 2020-12-11 06:22

I\'m looking over a block of code I\'ve used (sourced from another question) and I haven\'t been able to figure out what the . in .{process represe

2条回答
  •  借酒劲吻你
    2020-12-11 06:44

    . is the dot sourcing operator, which runs a script in the current scope rather than a new scope like call operator (i.e. &).

    That second segment invokes a script block and in that script block defines an advanced function. The advanced function iterates each item in the pipeline and selectively passes it along.

    This is not really an idiomatic use. What this script is trying to achieve could be done in a simpler, more readable way by using Where-Object (often shortened to where or ?):

    Get-ItemProperty $path | where { $_.DisplayName -and $_.UninstallString }
    

提交回复
热议问题