2011-10-29 3 views
1

PowerShell을 처음 사용하고 여러 응용 프로그램을 제거하는 방법을 찾고 있습니다. 설치 제거하려는 텍스트 파일에 응용 프로그램 목록이 있습니다.다중 응용 프로그램을 제거하려면 powershell을 사용 하시겠습니까?

# Retrieve names of all softwares to un-install and places in variable $app 

$App = Get-Content "C:\temp\un-installApps.txt" 

# Cycle through each of the softwares to un-install and store in the WMI variable 

Foreach ($AppName in $App) 
{ 
    $AppTmp = Get-WmiObject -query "Select * from win32_product WHERE Name like" + $AppName 
    $AppNames = $AppNames + $AppTmp 
} 

foreach ($Application in $AppNames) 
{ 
    msiexec /uninstall $Application.IdentifyingNumber 
} 

다음 줄이 문제

$AppTmp = Get-WmiObject -query "Select * from win32_product WHERE Name like" + $AppName 
$AppNames = $AppNames + $AppTmp" 

내가이 작업을 얻을 수있는 방법 어떤 아이디어가 발생합니다 다음 코드는 내가 지금까지 가지고있어?

답변

3

like과 응용 프로그램 이름 사이에 공백이 없기 때문에 응용 프로그램 이름 주위에 작은 따옴표가 있어야한다고 생각합니다. 해당 부분은 like '" + $AppName + "'"처럼 보입니다.

$App = Get-Content "C:\temp\un-installApps.txt" 

gwmi win32_product| 
    where { $App -contains $_.Name }| 
    foreach { $_.Uninstall() } | out-null 
+0

무효 나 문제 발생, 그래서 난이 사용 :

그러나이 같은 더 간단하게 전체 스크립트를 할 수 $ 응용 프로그램 = 가져 오기-내용 "C : \ 임시 \ 유엔 - installApp을 .txt " gwmi win32_product | 여기서 {$ App -contains $ _. Name} | foreach {$ _. Uninstall()} – resolver101

+0

@manojlds 편집으로 시도해보십시오. 파이프 라인을 괄호 안에 싸면'[void]'는 효과가있었습니다. – Rynant

+0

"다시 부팅하지 마십시오"일반 명령 줄 플래그가 있습니까? 아니면 해당 프로그램이 구체적입니까? (스크립트가 작동하고 있지만 기대하지 않을 때 컴퓨터가 재부팅되었습니다!) – granadaCoder

관련 문제