Quantcast
Channel: How can you use an object's property in a double-quoted string? - Stack Overflow
Viewing all articles
Browse latest Browse all 6

How can you use an object's property in a double-quoted string?

$
0
0

I have the following code:

$DatabaseSettings = @();$NewDatabaseSetting = "" | select DatabaseName, DataFile, LogFile, LiveBackupPath;$NewDatabaseSetting.DatabaseName = "LiveEmployees_PD";$NewDatabaseSetting.DataFile = "LiveEmployees_PD_Data";$NewDatabaseSetting.LogFile = "LiveEmployees_PD_Log";$NewDatabaseSetting.LiveBackupPath = '\\LiveServer\LiveEmployeesBackups';$DatabaseSettings += $NewDatabaseSetting;

When I try to use one of the properties in a string execute command:

& "$SQlBackupExePath\SQLBackupC.exe" -I $InstanceName -SQL `"RESTORE DATABASE $DatabaseSettings[0].DatabaseName FROM DISK = '$tempPath\$LatestFullBackupFile' WITH NORECOVERY, REPLACE, MOVE '$DataFileName' TO '$DataFilegroupFolder\$DataFileName.mdf', MOVE '$LogFileName' TO '$LogFilegroupFolder\$LogFileName.ldf'"

It tries to just use the value of $DatabaseSettings rather than the value of $DatabaseSettings[0].DatabaseName, which is not valid.
My workaround is to have it copied into a new variable.

How can I access the object's property directly in a double-quoted string?


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>