deleting with powershell

This topic contains 7 replies, has 4 voices, and was last updated by  Curtis Smith 4 days, 3 hours ago.

  • Author
    Posts
  • #84064

    Steve
    Participant

    I need to delete all msi files in the windows installer folder with the author of crowdstrike

    Remove-item -path c:\windows\installer I dont get how to target author or even digital signature

    is there a way? -filter maybe

    Thank you

  • #84065

    Olaf Soyk
    Participant

    As far as I know there is no build in way to get the information you asked for from an MSI file. You might take a look at this link. It may help you How to get MSI file information with PowerShell

  • #84074

    Steve
    Participant

    I just went with the *.msi option as it doesnt matter really if i keep any of the other MSI's since its a bunch of VDI linkedclones

    although if anyone knows of a way i would love to know for future reference.

    Thank you

  • #84076

    js
    Participant

    It's ridiculously hard to work with the WindowsInstaller.Installer (msi) com object in powershell. I would call a vbscript from powershell or just use vbscript.

  • #84080

    Curtis Smith
    Participant

    You could use the Shell.Application ComObject to read the .msi metadata.

    cls
    $folder = "C:\windows\Installer\"
    $objShell = New-Object -ComObject Shell.Application
    $objFolder = $objShell.namespace($folder)
    $objFolder.Items() | 
    Where-Object {$_.Name -like "*.msi"} |
    ForEach-Object {
        [pscustomobject]@{
            $objFolder.getDetailsOf($folder, 0) = $objFolder.getDetailsOf($_, 0);
            $objFolder.getDetailsOf($folder, 20) = $objFolder.getDetailsOf($_, 20)
            $objFolder.getDetailsOf($folder, 185) = $objFolder.getDetailsOf($_, 185)
        }
    } |
    Where-Object {$_.Authors -eq "crowdstrike"} |
    ForEach-Object {
        $_
        #Do something
    }
  • #84164

    Steve
    Participant

    i tried to use the vb script and add a obj.deletefile at the end i keep getting

    line 2
    char 1
    error invalid character
    800A0408
    microsoft vbscript compilation error

    any ideas why its barking at me?

  • #84191

    js
    Participant

    Here's how I get the target of msi shortcuts. Call the vbscript and then store the result in a powershell variable:

    $targetpath = cscript /nologo gettarget.vbs someshortcut.lnk
    

    Where gettarget.vbs looks like:

    Dim MSITarget
    Set Msi = CreateObject("WindowsInstaller.Installer")
    Set MSITarget = Msi.ShortcutTarget(wscript.arguments(0))
    Wscript.Echo Msi.ComponentPath(MSITarget.StringData(1), MSITarget.StringData(3))
    
  • #84194

    Curtis Smith
    Participant

    Hey Steve,
    What VBScript are you referring to? What I provided was PowerShell, not VBScript.

You must be logged in to reply to this topic.