I would like to understand the difference between invoking a PowerShell scriptblock with an ampersand (&) versus doing so using a dot (.).
For example, if I have a scriptblock like so:
$scriptBlock = { Write-Host -Object "Hello, $message" }
and we invoke it using an ampersand (&) operator like so:
$message = "World"
& $scriptBlock
the output is:
Hello, World
Invoking the same scriptblock with a dot (.) operator also gives the exact same output.
$message = "World"
. &scriptBlock
I would like to know if there are any differences in these two approaches.