$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}