tag:blogger.com,1999:blog-4985762676722907262.post6290237439751571902..comments2024-03-05T17:36:31.862+01:00Comments on Thoughts of Marcus<br>- Random ramblings of a BizTalk architect: "Clever" uninstall of msi packages/applications using PowerShellUnknownnoreply@blogger.comBlogger8125tag:blogger.com,1999:blog-4985762676722907262.post-6386584906587762422014-07-29T14:04:33.794+02:002014-07-29T14:04:33.794+02:00Just posted as anonymous, by mistake, also didnt c...Just posted as anonymous, by mistake, also didnt copy the right file haha. I would always use the "PSChildName" when uninstalling as it is the MSI GUID, Like below (obviously you can add in success checks etc):<br /><br />Function MSI-Uninstall($Product) { <br /><br />#Logging<br /><br />$ProdLog = $Product.Replace(" ", "_")<br />$UniLog = "C:\Windows\Logs\Software\$($ProdLog)_MSI_Uninstall.log"<br /><br /># Reboot suppresion - comment out if not needed<br />#<br />#$SupReb = "REMOVE=ALL REBOOT=ReallySuppress"<br />#<br /># Collects installed app data matching specified product<br /><br />$AppCollect = Get-ItemProperty "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*",` #32-Bit<br /> "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" #64-bit<br /><br />$RemProg = $AppCollect | Where { $_.DisplayName -like "*$($Product)*" } <br /><br /># Sets up arguments based on collected items - with logging<br /><br />$ArgList = "/x $(($RemProg).PSChildName) $($SupReb) /QN /L*V $($UniLog)"<br /><br /># Removes the above specified application<br /><br />If($RemProg -gt $Null){ Start-Process MSIExec $ArgList -Wait}<br /><br />}Max Wilkinsonnoreply@blogger.comtag:blogger.com,1999:blog-4985762676722907262.post-17841238392906751712014-07-29T13:58:21.150+02:002014-07-29T13:58:21.150+02:00I would use the PSChildName (MSI GUID) in these ca...I would use the PSChildName (MSI GUID) in these cases:<br /><br />Function MSI-Uninstall($Product) { <br /><br /># Reboot suppresion - comment out if not needed<br /><br />$SupReb = "REMOVE=ALL REBOOT=ReallySuppress"<br /><br /># Collects installed app data matching specified product<br /><br />$AppCollect = Get-ItemProperty "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*",` #32-Bit<br /> "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" #64-bit<br /><br />$RemProg = $AppCollect | Where { $_.DisplayName -like "*$($Product)*" } <br /><br /># Sets up arguments based on collected items - with logging<br /><br />$ArgList = "/x $(($RemProg).PSChildName) $($SupReb) /QN /L*V $($Log)"<br /><br /># Removes the above specified application<br />If($RemProg -gt $Null){ Start-Process MSIExec $ArgList -Wait}<br /><br />}Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4985762676722907262.post-20063706423625112892014-06-04T23:41:59.407+02:002014-06-04T23:41:59.407+02:00This is perfect. It helped me with a pattern match...This is perfect. It helped me with a pattern matching problem I was having with Remove-MSIApplications function from the Powershell App Deploy Toolkit. Added this function to my deployment script and called the function. Thank you so much!Joe Bugnihttps://www.blogger.com/profile/10366785505147311645noreply@blogger.comtag:blogger.com,1999:blog-4985762676722907262.post-327730001250306572013-10-31T23:36:13.285+01:002013-10-31T23:36:13.285+01:00This is great, this is exactly what I was looking ...This is great, this is exactly what I was looking for. Thanks! I tried using Get-WMIObject to get the program but it took several minutes. Then I read about all of the pitfalls.Anonymoushttps://www.blogger.com/profile/15004560591362934729noreply@blogger.comtag:blogger.com,1999:blog-4985762676722907262.post-20386821008796322512013-09-18T16:24:35.150+02:002013-09-18T16:24:35.150+02:00Ok.
Without testing it, you should be able to exec...Ok.<br />Without testing it, you should be able to execute it like this:<br />Invoke-Command -computer $computer -ScriptBlock { Uninstall-Program "Java" }<br /><br />Where you replace "Java" with the correct application name.<br /><br />For information on how to include custom written functions in your scripts, this is a pretty good guide: http://blogs.technet.com/b/heyscriptingguy/archive/2010/08/10/how-to-reuse-windows-powershell-functions-in-scripts.aspxMarcus Rangellhttps://www.blogger.com/profile/15559593687829270987noreply@blogger.comtag:blogger.com,1999:blog-4985762676722907262.post-71364991818391156332013-09-18T15:02:12.319+02:002013-09-18T15:02:12.319+02:00@Marcus, I am familiar with Powershell Remoting, I...@Marcus, I am familiar with Powershell Remoting, I guess I'm not sure how to use your script in general, even on a local machine. I could not get it to work, I'm not even sure how to input the variable for $name because usually I do this in the script with something like $name = 'java'.<br /><br /> I have a script that does something similar to this:<br />--------------------------------------------<br />$computers = Get-Content 'C:\computerlist.txt'<br />$program = 'java'<br />foreach ($computer in $computers) {<br /> Invoke-Command -ComputerName $computer -ScriptBlock {$app = Get-WmiObject -Class Win32_Product | Where-Object { <br /> $_.Name -like "*$($using:program)*" } <br /> $app.Uninstall()<br /> } <br />}<br />--------------------------------------------<br />But I would like to make yours work, just need a quick tip on how to run it, and how it gets the $name populated so it knows what software to look for. Then I can work on incorporating it into ps remoting. Thanks Marcus!commdude24https://www.blogger.com/profile/14955890078289571425noreply@blogger.comtag:blogger.com,1999:blog-4985762676722907262.post-3071077740995281442013-09-18T14:41:39.907+02:002013-09-18T14:41:39.907+02:00There are as far as I know a number of ways to do ...There are as far as I know a number of ways to do that. It all depends on your setup and preferences, but google PowerShell Remoting for instance for an input on how to do what you want.Marcus Rangellhttps://www.blogger.com/profile/15559593687829270987noreply@blogger.comtag:blogger.com,1999:blog-4985762676722907262.post-72572200959640893642013-09-18T13:58:52.540+02:002013-09-18T13:58:52.540+02:00Can you give an example of how to use this script ...Can you give an example of how to use this script to uninstall a program, say Java, from a list computers? Something along the lines of <br /><br />foreach ($computer in $computers) {yourscript.ps1 uninstall-program (Java) }<br /><br /> ? Thanks!commdude24https://www.blogger.com/profile/14955890078289571425noreply@blogger.com