$ComputerName = hostname Function Get-NonMSIApplication($productDisplayname) { $Msg="无软件"+$productDisplayname $regPathX86 = 'HKLM:SoftwareMicrosoftWindowsCurrentVersionUninstall' $regPathX64 = 'HKLM:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall' $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 mpSoftwareList"+ $ComputerName +".txt" #Write-Output $Msg|Out-File -filepath $Path $Msg >>$Path } import-csv -path .Blacklist.csv -UseCulture |ForEach-Object { Get-NonMSIApplication $_.blacklist}