2011-12-15 2 views
0

게시자 이름으로 소프트웨어를 제거 할 수 있습니까? 나는 그것을하는 다른 방법을 시도했으나 할 수 없었다. 이름을 사용하여 제거 할 수 있지만 일부 프로그램 이름은 일치하지 않지만 게시자는 동일합니다.Powershell이 ​​(가) 설치된 응용 프로그램을 제거합니다.

Get-WmiObject -Class Win32_Product -ComputerName $PCNumber -Filter "Publisher LIKE '%$Publisher%'" | Foreach-Object { 

    Write-Host 
    Write-Host "Uninstalling: $($_.Name)" 
    Write-Host 

    $rv = $_.Uninstall().ReturnValue 

    if($rv -eq 0) 
    { 
     $remove = "$drive\Program Files\software\"; 
     if ((Test-Path "$remove")){ 
      Remove-Item $remove -Recurse -Force 
     } 

     $remove = "$drive\Program Files (x86)\software\"; 
     if ((Test-Path "$remove")){ 
      Remove-Item $remove -Recurse -Force 
     } 

     Write-Host "$($_.Name) uninstalled sucessfully" 
    } 
    else 
    { 
     Write-Host "There was an error ($rv) uninstalling $($_.Name)" 
    } 
} 

나는 이것을 시도했지만 실패했다.

답변

0
$products = gwmi -class win32_product -filter "Vendor like 'Microsoft%'" 
if ($products) { 
    foreach ($product in $products) { 
     $product 
     # Processing here... 
    } 
} 
+0

이 작동합니다. 당신의 답변에 감사드립니다. Get-WmiObject -Class Win32_Product -ComputerName "." -Filter "Microsoft % '와 같은 공급 업체 | Foreach-Object { 쓰기 호스트 쓰기 호스트 "제거 : $ ($ _. 이름)" 쓰기 호스트 } – hello

관련 문제