What is the abbreviated `.` expression in a PowerShell pipeline?

I am looking at a block of code that I used (from another question ) and I was not able to figure out what . in .{process presents in this snippet (comments deleted):

 Get-ItemProperty $path | .{process{ if ($_.DisplayName -and $_.UninstallString) { $_ } }} | Select-Object DisplayName, Publisher, InstallDate, DisplayVersion, HelpLink, UninstallString | Sort-Object DisplayName 

I know what % For-EachObject and ? is a shorthand for Where or Where-Object , but the question remains:

What is contraction . ?

+6
source share
2 answers

. is a dot sourcing statement that runs a script in the current scope, and not in a new scope, such as a call statement (i.e. & ).

This second segment calls the script block, and an extended function is defined in this script block. An extended function iterates through each element in the pipeline and selectively passes it.

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

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

. - point source operator. I have never seen this used this way, but it is identical to using & (the call operator) in this context.

+4
source

Source: https://habr.com/ru/post/989162/


All Articles