我正在编写一个脚本,如果应用程序有较低版本或未安装,则必须安装它,但.msi的路径必须在变量
中。$msiSciteInstaller="path_to.msi"
$flag=0
$list=Get-ItemProperty HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall* | Where-Object -Property Displayname -Match "Scite"
foreach ( $listItem in $list ){
$flag+1 > $null
Write-Host ( " * Scite Installation Detected ")
Write-Host ( " * Scite version : "+$listItem.DisplayVersion.ToString())
if ($listItem.DisplayVersion -cle 6.0){
Write-Host ( " * Warning Vulnerability Detected" )
$msiSciteInstaller
}else{
Write-Host (" * Out of danger")
exit
}
}
if ( $flag -eq 0 ){
Write-Host "Not installed, so it´s gonna be installed"
$msiSciteInstaller
}
powershell在遇到包含裸值表达式的语句时(如$msiSciteInstaller
单独在一行中)的默认行为是对其求值并输出结果。
要调用字符串作为命令,使用调用操作符(&
):
& $msiSciteInstaller