none
Find a program RRS feed

  • Question

  • Hello i am hoping some one could help me with my code. The goal of this code is to find if a program is installed echo "Installed" and start uninstalling program. If the program is not installed do nothing and move to do something else.

    $sofware = "Java";
    $installed = ((Set-location HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall*).DisplayName -match "Java").Length -gt 0

    if(-Not $installed) {
            Write-Host "'$sofware' NOT installed.";

    } else {
            Write-Host "'$sofware' is installed."
    }

    When i run this it displays entire code, and does not display individual answer. What am i doing wrong?

    Tuesday, September 10, 2019 2:24 AM

All replies

  • Please look in the Gallery for scripts that will do what you ask.

    https://gallery.technet.microsoft.com/


    \_(ツ)_/

    Tuesday, September 10, 2019 4:14 AM
  • Please look in the Gallery for scripts that will do what you ask.

    https://gallery.technet.microsoft.com/


    \_(ツ)_/

    if you don't have anything useful to say don't say anything at all. get off my threat, i am looking for help and not smart ass comments.
    Tuesday, September 10, 2019 4:20 AM
  • Please refrain formabusive comments or your account may be suspended.

    THe cde you posted is not useful form much of anything and makes it clear that you have no experience with PowerShell.

    THe Gallery has numerous scripts that can find program entries in the registry.  It takes many more that three lines.

    You can also use the WMI class "Win32_Product" to get an installed program and uninstall it.


    \_(ツ)_/

    Tuesday, September 10, 2019 4:24 AM
  • Yes i don't have much experience, and that's why i am here looking for help. instead i am being treated by someone who thinks that he is better then someone because that someone is asking questions. i looked at the forum and did not found anything that can be useful to me. again, if you don't want to be helpful then don't. i am sure other members will be more helpful.
    Tuesday, September 10, 2019 4:31 AM
  • The link is not a forum it is a repository and you have to search it for scripts.

    Please carefully review the following links to set your expectation for posting in technical forums.

    Learning to script properly with PowerShell


    \_(ツ)_/

    Tuesday, September 10, 2019 4:35 AM
  • hi Eugene1978,

    effectively you code doesn't run well.

    Set-Location is not the appropriate cmdlet (Sets the current working location to a specified location)

    Get-ItemProperty : Gets the properties of a specified item. It seems better.

    try this one :

    $software = "steam"
    $Key = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$software"
    if ($null -ne (Get-ItemProperty -Path $key -name DisplayName)) # if the key exist, the return is not null.
        { 
        $Installed = $True # do something with this variable if you want
        Write-host "$software is installed" -ForegroundColor Green
    
        }
    else {
        $installed = $false # do something else with this variable is you want
        Write-Host "$software in not installed" -ForegroundColor Yellow
        }

    I've tested with another program on my computer, but it's the principle : reusable code :-)

    Olivier


    Wednesday, September 11, 2019 6:18 PM
  • $software = "steam"

    $Key = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$software"
    if ($null -ne (Get-ItemProperty -Path $key -name DisplayName)) # if the key exist, the return is not null.
        { 
        $Installed = $True # do something with this variable if you want
        Write-host "$software is installed" -ForegroundColor Green
    
        }
    else {
        $installed = $false # do something else with this variable is you want
        Write-Host "$software in not installed" -ForegroundColor Yellow
        }


    To expand the "principal" which is also refered to as a design pattern we would do it like this with PowerShell.  Note that "null"  valueds are always "False" ($false).

    $software = "steam"
    $Key = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$software"
    if(Get-ItemProperty -Path $key -name DisplayName){ # if the key exist, the return is not null.
        # "true" or not null path
        Write-host "$software is installed" -ForegroundColor Green   
    }else{
        # "false" or null path
        Write-Host "$software in not installed" -ForegroundColor Yellow
    }
    Note that my PS editor fixes the non-standard hanging code style to the more standard dropped block style.  This is less prone to error and les prone to visual misinterpretation.


    \_(ツ)_/

    Wednesday, September 11, 2019 6:31 PM
  • Thank you :)
    Wednesday, September 11, 2019 9:51 PM