In powershell what does the syntax $x = . { ... } mean? How is it different from $x = @( ... ) From what I can tell they both create an array of the provided values but their output is slightly different.
I came across it in this script https://powershell.one/tricks/filesystem/filesystemwatcher when the author defines the handlers in the async example. Is there any significance to doing it that way? Other async examples for filewatcher use similar code.
$x = @(1,2,3)
$y = . {1,2,3}
@($x,$y) | foreach-object {
$_
$_.GetType()
}
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
1,2,3
True True Object[] System.Array
1
2
3
Non Trivial Example
$handlers = . {
Register-ObjectEvent -InputObject $watcher -EventName Changed -Action $Action
Register-ObjectEvent -InputObject $watcher -EventName Created -Action $Action
Register-ObjectEvent -InputObject $watcher -EventName Deleted -Action $Action
Register-ObjectEvent -InputObject $watcher -EventName Renamed -Action $Action
}