Home > Blockchain >  PowerShell cannot find files ending in .EXE
PowerShell cannot find files ending in .EXE

Time:01-23

I have a PowerShell script program that is suppose to find a file on my computer and once it is found display results. The file in question can be the full name or a partial. If the file doesn't exist a message with output that.

Problem: It seems that files/application ending in .msi will be found but if the files/application ends in .exe it will not be found. How do I fix this?

$ADObjects = Get-ADComputer -filter {(name -like "Your PC Name goes here")};

$ADObjects | ForEach {
    $computerName = $_.name;
    Write-Output $computerName;
    $Versions = (Get-WmiObject -Class Win32_Product -ComputerName $computerName| Where-Object {$_.name -like "FireFox"});   # Finds all versions of the program

    $Count = ($Versions | Measure-object).count;
    if ($Count -eq 0) {
        Write-Output "$computerName does not have this application.";
    }
    else {
    
        Write-Output $Versions;

        #$Versions.unistall();    # Uncommenting this line will uninstall the versions listed by the line above
    }
}

CodePudding user response:

this is to find files that endes with exe to add to your line of code

Where-Object { $_.Name -Match '.*\.exe$' }

CodePudding user response:

Here is a quick way to find all the .exe files in the Program Files folder of your computer:

$gci *.exe -path 'C:\Program Files\' -recurse

You can refine this to search only for files that contain the word "Firefox".

HOWEVER, it appears that you are not really trying to find files, but WIN32 products. They are not the same thing. If you don't know what you are looking for, it's going to be awfully hard to tell you how to look.

CodePudding user response:

Get-package is faster and will list both msi and program installs. Msi installs can be piped to uninstall-package. You'd have to use invoke-command to run it remotely in parallel.

invoke-command comp1,comp1,comp3 { get-package *firefox* }
  •  Tags:  
  • Related