如何在双引号字符串中使用对象的属性?我有以下代码:$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;当我尝试使用字符串执行命令中的一个属性时:& "$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'"它只使用$DatabaseSettings而不是$DatabaseSettings[0].DatabaseName,这是无效的。我的解决办法是将它复制到一个新变量中。如何以双引号字符串直接访问对象的属性?
3 回答
慕后森
TA贡献1802条经验 获得超5个赞
$foo = 2"$foo"
"2"
$foo = 2'$foo'
$()
:
$foo = 1,2,3"$foo[1]" # yields "1 2 3[1]""$($foo[1])" # yields "2"$bar = "abc""$bar.Length" # yields "abc.Length""$($bar.Length)" # yields "3"
$( )
慕姐4208626
TA贡献1852条经验 获得超7个赞
$()
:
ToString()
...\$LogFileName.ldf
...\
$LogFileName
ldf
, $null
添加回答
举报
0/150
提交
取消