简体   繁体   中英

Powershell script to scan domain for PCs with Quicktime and uninstall with log

I know this must be a simple script to pull off, but I'm kinda out of my element with Powershell. I like to learn it, but having an incredibly hard time trying to figure this one out. I've searched here and all over but I have just a hodge podge set of scripts that do and don't work, they especially don't when put together.

I'm trying to come up with a Powershell script to scan our domain for PCs that have any version of Quicktime installed. If it's found then uninstall, either way I'm looking to have it export to a log file with the computer name and if it was uninstalled or can't connect. The below script works, but it shows the GENUS info and there's nothing to identify it with the PC it was run on. If the software isn't on there, the script give me "You cannot call a method on a null-valued expression." on the second line.

$app = Get-WmiObject -Class Win32_Product -ComputerName (Get-Content "C:\Users\name\Desktop\pstest\test2list.txt") | Where-Object {$_.Name -like “*Quicktime*”}
$app.Uninstall() | Out-File C:\Users\name\Desktop\pstest\test2listout.txt

Answer was given by Anthony...

https://blogs.technet.microsoft.com/heyscriptingguy/2011/12/14/use-powershell-to-find-and-uninstall-software/

Using...

gwmi win32_product | ft name, version, ident*

I can find all the software installed. I used the foreach uninstaller and mixed with other scripts I found. I get all computers to run it at the same time, but ran it manually and it worked, for me at least.

$qtVer = Get-ChildItem -Path HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall, HKLM:\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -match "quicktime" } | Select-Object -Property DisplayName, UninstallString

ForEach ($ver in $qtVer) {

 If ($ver.UninstallString) { $uninst = $ver.UninstallString $uninst = $uninst -replace "/I", "/x " Start-Process cmd -ArgumentList "/c $uninst /quiet /norestart" -NoNewWindow } } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM