foreach循环字符串中的数组返回整数而不是单个变量

时间:2017-11-03 06:56:13

标签: windows powershell windows-installer

我正在创建一个像这样的数组

$softwareguid = get-wmiobject -class Win32_Product | Where-Object -FilterScript {$_.Name -like "ESET*"};

然后迭代执行msiexec静默删除,但无法构造变量以执行invoke-expression

代码:

foreach ($remove in $softwareguid){ $uninstallcmd = "Detected"$remove.Name"with GUID"$remove.IdentifyingNumber;}

导致以下错误:

enter image description here

1 个答案:

答案 0 :(得分:0)

您需要将字符串插值包装在子表达式 $()中:

$uninstallcmd = "Detected $($remove.Name) with GUID $($remove.IdentifyingNumber)";