A few weeks ago I found myself in a community where someone told me that he did an uninstall of an application on 35 workstations.
Now how did he do that? Through SCCM? RES Automation Manager? Altiris?
No, he went to every device and did it by hand because this customer did not have an automation tool in place.
Now, going to every device and do it by hand is something I would very much dislike… and there are days I wouldn’t even let an intern do it. Instead I would give them an objective: Automate the uninstallation of the application without using additional tools and only use what is available to you.
Since I don’t have an intern anymore, and it wasn’t my customer, there was no need for me to do this… but it got me thinking…
I found this nice little script from Ed ‘the scripting guy’ Wilson where he uses PowerShell to make an inventory of all applications installed in his environment.
Since his script only searches on devices specified in a file, I did some tweaking to search all devices from AD and use those instead of the content of the file.
$computers = Get-ADComputer
$array = @()
foreach($pc in $computers){
$computername=$pc.computername
#Define the variable to hold the location of Currently Installed Programs
$UninstallKey=”SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall”
#Create an instance of the Registry Object and open the HKLM base key
$reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey(‘LocalMachine’,$computername)
#Drill down into the Uninstall key using the OpenSubKey Method
$regkey=$reg.OpenSubKey($UninstallKey)
#Retrieve an array of string that contain all the subkey names
$subkeys=$regkey.GetSubKeyNames()
#Open each Subkey and use GetValue Method to return the required values for each
foreach($key in $subkeys){
$thisKey=$UninstallKey+”\\”+$key
$thisSubKey=$reg.OpenSubKey($thisKey)
$obj = New-Object PSObject
$obj | Add-Member -MemberType NoteProperty -Name “ComputerName” -Value $computername
$obj | Add-Member -MemberType NoteProperty -Name “DisplayName” -Value $($thisSubKey.GetValue(“DisplayName”))
$obj | Add-Member -MemberType NoteProperty -Name “DisplayVersion” -Value $($thisSubKey.GetValue(“DisplayVersion”))
$obj | Add-Member -MemberType NoteProperty -Name “InstallLocation” -Value $($thisSubKey.GetValue(“InstallLocation”))
$obj | Add-Member -MemberType NoteProperty -Name “Publisher” -Value $($thisSubKey.GetValue(“Publisher”))
$array += $obj
}
}
$array | Where-Object { $_.DisplayName } | select ComputerName, DisplayName, DisplayVersion, Publisher | ft –auto
Now that you know which applications are installed, you can use the following script to uninstall them
# Usage: RemoveApplication.ps1 “Microsoft Office 2007”
function Remove-Application ($ApplicationName) { $Application = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match “$ApplicationName” } $Application.Uninstall() }