代码之家  ›  专栏  ›  技术社区  ›  V Krishan

无法运行PowerShell卸载脚本

  •  3
  • V Krishan  · 技术社区  · 8 年前

    write-host $command
    

    它按预期工作。以下是我的完整脚本:

    # Get uninstall strings from registry, looking for the msiexec option
    $applist = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall  |
        Get-ItemProperty |
            Where-Object {$_.DisplayName -match "Microsoft Visio Standard 2013" -and $_.UninstallString -match "msiexec"} |
                Select-Object -Property DisplayName, UninstallString
    
    # Check for any aplications requiring uninstall and output their names
    if ($applist) {
        foreach ($app in $applist) {
            Write-host "$($app.DisplayName) has been detected for uninstall"
        }
    
        Write-host "Attempting to uninstall application(s)"
    
        # Uninstall each application that has been identified
        foreach ($app in $applist) {
            try {
                 $uninst = $app.UninstallString
                 $pos = $uninst.IndexOf(" ")
                 $leftPart = $uninst.Substring(0, $pos)
                 $rightPart = $uninst.Substring($pos+1)
                 $command = """$rightPart /qn /L*V ""C:\UninstallVisio.txt"""""
                 write-host $command
                $uninstall = (Start-Process "msiexec.exe" -ArgumentList $command -Wait -Passthru).ExitCode
    
                if($uninstall.ExitCode -ne 0) {
                    write-host "attempting XML config uninstall"
                    #**still to be worked on**
                }
            } catch {
                write-host "Unable to uninstall $_.Name Please view logs" 
                Continue
            }
        }
    }
    Exit
    # Exit script as no apps to uninstall
    else {
        write-host "No application(s) detected for uninstall"
        Exit
    }
    
    3 回复  |  直到 8 年前
        1
  •  2
  •   Aravinda    8 年前

    而不是这个

    $command = "$uninst /qn /L*V ""C:\UninstallVisio.txt"""
    

    尝试

    $command = @(
        $uninst
        "/qn"
        "/L*V"
        '"C:\UninstallVisio.txt"'
         )
    

    来源:见最后一个示例 https://kevinmarquette.github.io/2016-10-21-powershell-installing-msi-files/

        2
  •  1
  •   V Krishan    8 年前
    #Get uninstall strings from registry, looking for the msiexec option
    $applist = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall  |
        Get-ItemProperty |
            Where-Object {$_.DisplayName -match "Microsoft Visio Standard 2013" -and $_.UninstallString -match "msiexec"} |
                Select-Object -Property DisplayName, UninstallString
    
    #Check for any aplications requiring uninstall and output their names
    if ($applist){
    foreach ($app in $applist){
    Write-host "$($app.DisplayName) has been detected for uninstall"
    }
    
    
    Write-host "Attempting to uninstall application(s)"
    
    
    #Uninstall each application that has been identified
    foreach ($app in $applist){
    try
    {
            $uninst = $app.UninstallString
            $pos = $uninst.IndexOf(" ")
            $leftPart = $uninst.Substring(0, $pos)
            $rightPart = $uninst.Substring($pos+1)
            $command = @(
            $rightPart
            "/qn"
            "/L*V"
            '"C:\UninstallVisio.txt"'
             )
            write-host $command
            $uninstall = (Start-Process "msiexec.exe" -ArgumentList $command -Wait -Passthru).ExitCode
            If($uninstall.ExitCode -ne 0){
            write-host "attempting XML config uninstall"
            }
           }
    
    catch{
    write-host "Unable to uninstall $_.Name Please view logs" 
    Continue
        }
    Exit
    }
    }
    #Exit script as no apps to uninstall
    else {
    write-host "No application(s) detected for uninstall"
    Exit
    }
    
        3
  •  0
  •   vte    8 年前

    看起来您正在尝试运行msiexec。带有ArgumentList“msiexec.exe/x{ProductCode}”的exe。

    Powershell正在尝试以“msiexec.exe msiexec.exe/x{ProductCode}”的形式运行您的命令

    推荐文章