I have the following code:
$DatabaseSettings = @();
$NewDatabaseSetting = \"\" | select DatabaseName, DataFile, LogFile, LiveBackupPath;
$NewDatabaseSetting.
@Joey has the correct answer, but just to add a bit more as to why you need to force the evaluation with $()
:
Your example code contains an ambiguity that points to why the makers of PowerShell may have chosen to limit expansion to mere variable references and not support access to properties as well (as an aside: string expansion is done by calling the ToString()
method on the object, which can explain some "odd" results).
Your example contained at the very end of the command line:
...\$LogFileName.ldf
If properties of objects were expanded by default, the above would resolve to
...\
since the object referenced by $LogFileName
would not have a property called ldf
, $null
(or an empty string) would be substituted for the variable.