Is "Dollar-sign" optional in powershell "$()"? -
i've seen example setting timestamps (creationtime, lastaccesstime, lastwritetime) of file powershell:
ps>$(get-item test.txt).lastwritetime=$(get-date "01/01/2020") which seems work.
this page: http://ss64.com/ps/syntax-operators.html powershell operators says "$( )" "subexpression operator".
but seems work without "$" like:
ps>(get-item test.txt).lastwritetime=(get-date "01/01/2020") and powershell examples i've seen omit "$" when using parenthesis.
so, "dollar-sign" optional in powershell "$()" ? or there difference with/without "$" i'm not seeing.
is "$()" , "()" 2 different operators happen both valid uses in examples have shown?
you need $ sign denote sub expression if use multiple statements or statement embedded in string. parenthesis without $ grouping operator.
$($x = 1; $y =2; $x + $y).tostring() //3 ($x = 1; $y =2; $x + $y).tostring() // invalid syntax ($x = 1 + 2).tostring() //3 "$(1 +2)" //3
Comments
Post a Comment