我正在创建一个像这样的数组
$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;}
导致以下错误:
答案 0 :(得分:0)
您需要将字符串插值包装在子表达式 $()
中:
$uninstallcmd = "Detected $($remove.Name) with GUID $($remove.IdentifyingNumber)";