$ComputerName = hostname
Function Get-NonMSIApplication($productDisplayname) 
{
    $Msg="无软件"+$productDisplayname
    $regPathX86 = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall'
    $regPathX64 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
    $regPath = ($regPathX64,$regPathX86)
    Get-ChildItem ( foreach { $regPath})| foreach { 
        $product =  Get-ItemProperty $_.PSPath
         if($product.DisplayName -like ('*'+$productDisplayname+'*') )
            {
             $Msg=""
             $product.UninstallString = $product.UninstallString + " /quiet /norestart"
            Start-Process  (cmd /c $product.UninstallString ) -Wait
             if((Test-Path $_.PSPath ))
                { 
                   $Msg = $Msg + '卸载'+ $product.DisplayName +'软件失败'+"|"
                 }
             else
                {
                  $Msg = $Msg + '卸载'+ $product.DisplayName +'软件成功'+"|"
                 }
            }
  }
    $Path="\\V12CNDCZ01DCSP2\tmp\SoftwareList\"+ $ComputerName +".txt"  
    #Write-Output $Msg|Out-File -filepath $Path
    $Msg >>$Path
}
import-csv -path .\Blacklist.csv -UseCulture |ForEach-Object { Get-NonMSIApplication $_.blacklist}

  

posted on 2020-09-20 08:52  vmsky  阅读(501)  评论(0编辑  收藏  举报