Home > Software design >  PowerShell opens the .msi instead of saving the path into a variabe [duplicate]
PowerShell opens the .msi instead of saving the path into a variabe [duplicate]

Time:09-30

I´m making an script that if an app has a lower version or is not intalled it must install it, but the path to the .msi must be in a variable

    $msiSciteInstaller="path_to.msi"
$flag=0
$list=Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | 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
}

CodePudding user response:

PowerShells default behavior when encountering a statement consisting of a naked value expression (like $msiSciteInstaller on a line on its own) is to evaluate it and output the result.

To invoke a string as a command, use the invocation operator (&):

& $msiSciteInstaller
  • Related