문제

거기에 간단한 방법으로 후크 표준프로그램 추가/제거'기능을 사용하여 PowerShell 제거 기존 응용 프로그램?또는지 확인하려면 응용 프로그램이 설치되어 있습니까?

도움이 되었습니까?

해결책

$app = Get-WmiObject -Class Win32_Product | Where-Object { 
    $_.Name -match "Software Name" 
}

$app.Uninstall()

편집: Rob 찾을 수행하는 다른 방법으로 필터 매개변수:

$app = Get-WmiObject -Class Win32_Product `
                     -Filter "Name = 'Software Name'"

다른 팁

편집:수 년 동안 이 응답을 받고있는 꽤 몇 가지 늦게 집에 가서 만들고있다.를 추가하고 싶 일부 의견.나는 사용되지 않습 PowerShell,이후 하지만 난 기억 관찰하는 몇 가지 문제점:

  1. 많은 경우 경기 1 위해 아래 스크립트,그것은 작동하지 않으며 추가해야 합니다 PowerShell 필터는 결과를 제한 1.내가 믿 -First 1 하지만 나는 확실하지 않다.무료 편집할 수 있습니다.
  2. 는 경우 응용 프로그램이 설치되어 있지 않으로 MSI 그것은 작동하지 않습니다.그 이유는 기록되었으로 아래에 이를 수정하기 때문에 MSI 제거를 위해 개입하지 않고 항상하지 않은 기본적으로 사용하는 경우 기본 설치 제거 문자열입니다.

를 사용하 WMI 개체 걸립니다.이것은 매우 빠르다면 당신은 단지의 이름을 알려는 프로그램을 제거합니다.

$uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "SOFTWARE NAME" } | select UninstallString
$uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "SOFTWARE NAME" } | select UninstallString

if ($uninstall64) {
$uninstall64 = $uninstall64.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$uninstall64 = $uninstall64.Trim()
Write "Uninstalling..."
start-process "msiexec.exe" -arg "/X $uninstall64 /qb" -Wait}
if ($uninstall32) {
$uninstall32 = $uninstall32.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$uninstall32 = $uninstall32.Trim()
Write "Uninstalling..."
start-process "msiexec.exe" -arg "/X $uninstall32 /qb" -Wait}

를 해결하는 두 번째 방법을 제프 힐만의 게시물에,당신은 하거나 수행:

$app = Get-WmiObject 
            -Query "SELECT * FROM Win32_Product WHERE Name = 'Software Name'"

$app = Get-WmiObject -Class Win32_Product `
                     -Filter "Name = 'Software Name'"

을 조금 추가 이 게시물에,나는 할 수 있도록 필요한 소프트웨어를 제거에서 여러 서버에 있습니다.내가 사용하는 제프의 대답을 이끌어 나이:

첫째는 서버 목록,내가 사용하는 광고 쿼리,하지만 당신을 제공할 수 있는 컴퓨터 이름 배열 그러나 당신이 원하는:

$computers = @("computer1", "computer2", "computer3")

그때 나는 루프를 통해 그들을 추가하여 컴퓨터 매개 변수는 멋 쿼리:

foreach($server in $computers){
    $app = Get-WmiObject -Class Win32_Product -computer $server | Where-Object {
        $_.IdentifyingNumber -match "5A5F312145AE-0252130-432C34-9D89-1"
    }
    $app.Uninstall()
}

나는 사용한다.속성에 대한 대신의 이름을 확실히 있었을 제거하고 올바른 응용 프로그램.

내가 찾는 것 Win32_Product 클래스지 않는 것이 좋기 때문에 그것을 트리거 수리지 않는 쿼리를 최적화되어 있습니다.

내가 발견 이 게시물 에서 Sitaram Pamarthi 스크립트와 함께 제거하는 경우 응용 프로그램을 알입니다.그는 또한 공급 다른 스크립트를 검색에 대한 앱이 정말 빠르 .

사이:.\제거합니다.ps1-GUID {C9E7751E-88ED-36CF-B610-71A1D262E906}

[cmdletbinding()]            

param (            

 [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
 [string]$ComputerName = $env:computername,
 [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Mandatory=$true)]
 [string]$AppGUID
)            

 try {
  $returnval = ([WMICLASS]"\\$computerName\ROOT\CIMV2:win32_process").Create("msiexec `/x$AppGUID `/norestart `/qn")
 } catch {
  write-error "Failed to trigger the uninstallation. Review the error message"
  $_
  exit
 }
 switch ($($returnval.returnvalue)){
  0 { "Uninstallation command triggered successfully" }
  2 { "You don't have sufficient permissions to trigger the command on $Computer" }
  3 { "You don't have sufficient permissions to trigger the command on $Computer" }
  8 { "An unknown error has occurred" }
  9 { "Path Not Found" }
  9 { "Invalid Parameter"}
 }
function Uninstall-App {
    Write-Output "Uninstalling $($args[0])"
    foreach($obj in Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") {
        $dname = $obj.GetValue("DisplayName")
        if ($dname -contains $args[0]) {
            $uninstString = $obj.GetValue("UninstallString")
            foreach ($line in $uninstString) {
                $found = $line -match '(\{.+\}).*'
                If ($found) {
                    $appid = $matches[1]
                    Write-Output $appid
                    start-process "msiexec.exe" -arg "/X $appid /qb" -Wait
                }
            }
        }
    }
}

그것은 이 방법:

Uninstall-App "Autodesk Revit DB Link 2019"

나는 내 자신의 작은 공헌이다.내가 필요로 제거하는 패키지 목록에서 동일한 컴퓨터입니다.이것은 스크립트를 내놓았다.

$packages = @("package1", "package2", "package3")
foreach($package in $packages){
  $app = Get-WmiObject -Class Win32_Product | Where-Object {
    $_.Name -match "$package"
  }
  $app.Uninstall()
}

이를 증명하는 것은 도움이 될 수 있습니다.

참고하는 내가 빚을 데이비드 Stetler 신용을 위한 이 스크립트를 기반으로 하므로 그분의 것입니다.

여기에는 쉘 스크립트를 사용하여 msiexec:

echo "Getting product code"
$ProductCode = Get-WmiObject win32_product -Filter "Name='Name of my Software in Add Remove Program Window'" | Select-Object -Expand IdentifyingNumber
echo "removing Product"
# Out-Null argument is just for keeping the power shell command window waiting for msiexec command to finish else it moves to execute the next echo command
& msiexec /x $ProductCode | Out-Null
echo "uninstallation finished"

한 줄의 코드:

get-package *notepad* |% { & $_.Meta.Attributes["UninstallString"]}

에 따라 제프 힐만의 대답:

여기에 기능을 추가할 수 있습니다 그냥 당신 profile.ps1 나에서 정의 현재 PowerShell 세션:

# Uninstall a Windows program
function uninstall($programName)
{
    $app = Get-WmiObject -Class Win32_Product -Filter ("Name = '" + $programName + "'")
    if($app -ne $null)
    {
        $app.Uninstall()
    }
    else {
        echo ("Could not find program '" + $programName + "'")
    }
}

당신하고 싶었거 Notepad++.단지 유형이 PowerShell:

> uninstall("notepad++")

단식 Get-WmiObject 약간의 시간이 걸릴 수 있습니다,그래서 인내심을 갖고 기다려 주십시오.

를 사용:

function remove-HSsoftware{
[cmdletbinding()]
param(
[parameter(Mandatory=$true,
ValuefromPipeline = $true,
HelpMessage="IdentifyingNumber can be retrieved with `"get-wmiobject -class win32_product`"")]
[ValidatePattern('{[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}}')]
[string[]]$ids,
[parameter(Mandatory=$false,
            ValuefromPipeline=$true,
            ValueFromPipelineByPropertyName=$true,
            HelpMessage="Computer name or IP adress to query via WMI")]
[Alias('hostname,CN,computername')]
[string[]]$computers
)
begin {}
process{
    if($computers -eq $null){
    $computers = Get-ADComputer -Filter * | Select dnshostname |%{$_.dnshostname}
    }
    foreach($computer in $computers){
        foreach($id in $ids){
            write-host "Trying to uninstall sofware with ID ", "$id", "from computer ", "$computer"
            $app = Get-WmiObject -class Win32_Product -Computername "$computer" -Filter "IdentifyingNumber = '$id'"
            $app | Remove-WmiObject

        }
    }
}
end{}}
 remove-hssoftware -ids "{8C299CF3-E529-414E-AKD8-68C23BA4CBE8}","{5A9C53A5-FF48-497D-AB86-1F6418B569B9}","{62092246-CFA2-4452-BEDB-62AC4BCE6C26}"

그것은 완전히 테스트,하지만 그것을 실행하에 PowerShell4.

이 PS1 파일로 그것은 여기에서 볼 수 있습니다.그것을 검색하의 모든 시스템 광고 고 제거하려고 여러 응용 프로그램에서 모든 시스템입니다.

사용합니다.을 검색에 대한 소프트웨어의 원인 데이비드 Stetlers 입력합니다.

지 않 테스트:

  1. 를 추가하지 않 id 를 부르의 함수에서 스크립트,대신 시작하는 스크립트와 매개변수의 Id
  2. 스크립트를 호출하는 더 후 1 대의 컴퓨터 이름 자동으로 검색하는 기능
  3. 에서 데이터를 검색하는 파이프
  4. IP 주소를 사용하는 시스템을 연결해

그것이 무엇을 하지 않았다:

  1. 지 않는 모든 정보를 제공하는 경우 소프트웨어를 실제로 발견되었다는 어떤 주어진 시스템입니다.
  2. 그것은 포기하지 않는 모든 정보에 대한 오류나 성공의 설치 제거.

할 수 없었을 사용하여 제거().하는 오류를 말하는 메소드 호출에 대한 표현이 있는 NULL 값이 가능하지 않습니다.대신 사용을 제거-WmiObject 을 달성하는 동일합니다.

주의:컴퓨터 없이 주어진 이름이 그것을 제거에서 소프트웨어 모든 시스템에서 활성 디렉토리에 있습니다.

대부분의 내 프로그램 스크립트에서 이 게시물을 했습니다.하지만 내가 직면했던 기존 프로그램을 제거할 수 없을 사용하여 msiexec.exe 또 Win32_Product 클래스입니다.(어떤 이유에서 나는 종료 0 하지만 이 프로그램은 아직 거기)

나의 솔루션을 사용하여 win32_process 클래스:

도움으로부터 nickdnk 이 명령은 제거 exe 파일 경로:

64 비트:

[array]$unInstallPathReg= gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match $programName } | select UninstallString

32 비트:

 [array]$unInstallPathReg= gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match $programName } | select UninstallString

당신은 깨끗한 결과 문자열:

$uninstallPath = $unInstallPathReg[0].UninstallString
$uninstallPath = $uninstallPath -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$uninstallPath = $uninstallPath .Trim()

당신은 언제든 관련 프로그램을 제거 exe 파일 경로 이 명령을 사용할 수 있습니다:

$uninstallResult = (Get-WMIObject -List -Verbose | Where-Object {$_.Name -eq "Win32_Process"}).InvokeMethod("Create","$unInstallPath")

$uninstallResult-이 종료 코드입니다.0 은 성공

위 명령을 실행할 수도 있습니다 원격으로 내가 그것을 사용하여 명령을 호출하지만 믿는 추가 주 컴퓨터 이름을 작업 할 수 있습

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top