0

I am making a small script for uninstalling the 7 Zip software from my servers, for that I have to find the 7 Zip software and un-install using the script.

On some windows servers I am able to find the software however on many of them I am unable to find them although they are installed as I can see it from the appwiz.cpl.

I cannot use Get-ItemProperty remotely, as WinRM is not configured correctly in the environment. So being too lazy I am trying create a powershell script to find the 7 Zip software and uninstall it.

$servers= Get-Content "C:\Server.txt"
Foreach($server in $servers)
{
    $ZipSoft= get-wmiobject win32_Product | where {$_.Name -like "*7-Zip*"}
    $ZipSoft.Uninstall()
}

I have tried to find individually on those servers however it does not gives me the output even no errors, other installed software I can find using the above. Any idea about this why I am not able to find it on those servers?

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
Ishan Sharma
  • 21
  • 2
  • 8
  • "I cannot use Get-ItemProperty as I need to run it on 100+ servers." - what do you mean by this? – Mathias R. Jessen May 08 '20 at 16:14
  • Get-ItemProperty does not allow me to run on list of servers for that I have to use invoke-command for which I have to fix winRM issues on all servers. That's why I said I do not want to use Get-ItemProperty – Ishan Sharma May 08 '20 at 16:19
  • Ah, gotcha! [You can still query the remote registry service without PowerShell Remoting though](https://stackoverflow.com/questions/15069130/get-remote-registry-value) – Mathias R. Jessen May 08 '20 at 16:29
  • Yeap I have this option as well, but I was wondering why my above script is not providing me the required information. Even when I try below command-let on a single server it does not provide me any information ``` get-wmiobject win32_Product | where {$_.Name -like "*7-Zip*"} ``` Not sure what is wrong in here. – Ishan Sharma May 08 '20 at 16:33
  • Probably because the application is registered under a different product name, like "7 Zip File Manager" instead of "7-Zip"? Query one of the servers for the full list and manually go through it to see if you can find anything related to 7 xip – Mathias R. Jessen May 08 '20 at 16:35
  • Yes I tried the same, but no luck... I tried this for other software it's working. I tried with "*zip*", "*7*" and even with the vendor name "*igvor*" but did not find it anywhere. However when I check though GUI it is installed. – Ishan Sharma May 08 '20 at 16:38

1 Answers1

0

The wmi class win32_product is slow and incomplete. It may only list msi installs. It also verifies every msi when it runs.

get-package 7-zip*  # powershell 5 only

Name              Version Source ProviderName
----              ------- ------ ------------
7-Zip 19.00 (x64) 19.00          Programs
js2010
  • 23,033
  • 6
  • 64
  • 66
  • But it is showing for few servers, but on most it's not providing the information, where I can see through GUI it is installed. Same version of 7 Zip is also installed on the servers. Also PackageManagement module needs to be installed on server inorder to use get-package command-let. But my query is for win32_Product. – Ishan Sharma May 08 '20 at 16:50
  • Win32_product comes up empty for me. Did you use an msi installer on some servers? get-package comes with powershell 5. – js2010 May 08 '20 at 16:58
  • I used Get-Package but says no package found : ``` PS C:\Windows\system32> Get-Package "7-Zip*" Get-Package : No package found for '7-Zip*'. At line:1 char:1 + Get-Package "7-Zip*" + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Microsoft.Power...lets.GetPackage:GetPackage) [Get-Package], Exception + FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage ``` – Ishan Sharma May 08 '20 at 17:32
  • Any other suggestions now on this... As when I ran get-package it also provided the same ourput. – Ishan Sharma May 11 '20 at 16:42
  • I don't know. Did you install it just by unzipping it on some servers? Maybe just look for the exe. – js2010 May 11 '20 at 17:09
  • I used the installation exe file to use 7 zip. – Ishan Sharma May 12 '20 at 08:16