我需要在if内部使用here-string语句。但是,当我查看变量内部时,我看到true而不是$true表达式$($row.'Secondary Network Adapter' -eq 'Y')将被$true或$false替换。
$row = @{
SecondaryNetworkAdapter = "Y"
}
$code1 = @'
if($($row.SecondaryNetworkAdapter -eq 'Y')){
Set-NetIPInterface -InterfaceAlias '$nic1Name' -AutomaticMetric disabled -InterfaceMetric 5
}
'@然后,我运行以下行:
$ExecutionContext.InvokeCommand.ExpandString($code1)输出:
if(True){ Set-NetIPInterface -InterfaceAlias 'LAN‘-AutomaticMetric禁用-InterfaceMetric 5}
致以亲切的问候,
发布于 2020-06-21 10:32:02
在表达式之前添加一个转义文本$:
if(`$$($row.SecondaryNetworkAdapter -eq 'Y')){https://stackoverflow.com/questions/62497284
复制相似问题