Solved

Powershell script to find specific software

Posted on 2014-03-31
19
7,031 Views
Last Modified: 2014-04-10
Is there a way to search Powershell for a specific software?
Get -ADComputer - Filter {Software - like ...??
0
Comment
Question by:WellingtonIS
  • 8
  • 5
  • 3
  • +2
19 Comments
 
LVL 9

Expert Comment

by:rfportilla
ID: 39966798
Short answer is yes; it can be done.  The question is in how you want to detect it.  

How do you want to test for the existence of this software?  There are many ways to do this, but it depends on how the software is installed.  Some software registers in the registry while others only create a program folder and still others install themselves as a service.
0
 
LVL 7

Expert Comment

by:Delete
ID: 39966855
Try this:

gwmi win32_product -Filter {Name like "%SoftwareName%"}
0
 

Author Comment

by:WellingtonIS
ID: 39966948
It writes to the registry
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 9

Expert Comment

by:rfportilla
ID: 39966954
Then Justin F's solution should work.  Try it and let us know.  :-)  Thanks.
0
 

Author Comment

by:WellingtonIS
ID: 39967023
gwmi win32_product -Filter {Name like "%SoftwareName%"}  > C:\software.csv is when I used.
0
 
LVL 9

Expert Comment

by:rfportilla
ID: 39967063
Ok.  Please remember to assign points accordingly.
0
 

Author Comment

by:WellingtonIS
ID: 39967250
I must not have the software name correct becuase I'm not getting any data.
0
 
LVL 7

Expert Comment

by:Delete
ID: 39967261
If you do the below command it will pull the name of all installed software.  Make sure you see your software listed, and that you are spelling it the same way that it is listed.

gwmi win32_product | Select-Object Name


As a note, when you are searching for your specific software using the command I previously gave, you don't have to put the whole name and instead can just put the first word.
0
 

Author Comment

by:WellingtonIS
ID: 39967270
Will that work on all machines or I need to add a name of a machine?
0
 
LVL 40

Expert Comment

by:footech
ID: 39967281
I wouldn't use Win32_Product except in testing scenarios.  There are issues with using this because it causes every MSI installation to undergo a consistency check.  Here's a sample link which describes some issues (randomly picked from a google search - others are available).
http://myitforum.com/cs2/blogs/gramsey/archive/2011/01/25/win32-product-is-evil.aspx
I understand the temptation to use it because it is so easy, but...

I would recommend just doing registry queries for the info.  Here's another thread here with a script which gets info from the registry (though my personal preference would be to rework it to use PS Remoting).
http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28274088.html
0
 
LVL 7

Expert Comment

by:Delete
ID: 39967286
That will work on any machine that you are running the command on.  If you are trying to run the command against remote computers then it would need to be modified depending on how you are reading in the computers.  

If you are wanting to run it against remote computers then let me know if you are going to be reading them in from Active Directory or a from a list and I will update the command.
0
 

Author Comment

by:WellingtonIS
ID: 39967302
OK Basically I'm trying to query all machines in my domain for a specific software. That's why I posted the Get -ADComputer - Filter {Software - like ...??  I thought I could add software instead of "operatingsystem"  Active Directory.
0
 
LVL 7

Expert Comment

by:Delete
ID: 39967400
Good catch footech.  

Try the below

Get-ADComputer -Filter * | ForEach-Object {Invoke-Command -ComputerName $_.name -ScriptBlock {Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  ? {$_.displayname -like "Microsoft*"} | Select-Object Displayname}}

Open in new window

0
 

Author Comment

by:WellingtonIS
ID: 39967580
WinRM cannot process the request. The following error occured while using Kerbe
ros authentication: The network path was not found.
 Possible causes are:
  -The user name or password specified are invalid.
  -Kerberos is used when no authentication method and no user name are specifie
d.
  -Kerberos accepts domain user names, but not local user names.
  -The Service Principal Name (SPN) for the remote computer name and port does
not exist.
  -The client and remote computers are in different domains and there is no tru
st between the two domains.
 After checking for the above issues, try the following:
  -Check the Event Viewer for events related to authentication.
  -Change the authentication method; add the destination computer to the WinRM
TrustedHosts configuration setting or use HTTPS transport.
 Note that computers in the TrustedHosts list might not be authenticated.
   -For more information about WinRM configuration, run the following command:
winrm help config. For more information, see the about_Remote_Troubleshooting H
elp topic.
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39967698
I don't think you can do invoke-command without enable-psremoting.
0
 
LVL 7

Expert Comment

by:Delete
ID: 39968271
The command works on my test network without issue.  I made a few tweaks to make the output better.

Get-ADComputer -filter * | ForEach-Object {Invoke-Command -ComputerName $_.Name -ScriptBlock {Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  ? {$_.displayname -like "Microsoft*"}} | ft Displayname, PSComputerName -AutoSize}

Open in new window



A few questions regarding the error your receiving:

1. Given the errors you are receiving, is WinRM enabled on all of your systems?  The command "WinRM QuickConfig" would need to be ran on all servers/workstations.

2. Are you running your PowerShell instance as an Admin (actually right clicking and running powershell as an Administrator)?

3. Are you running the script with a Domain account that has local admin rights across all servers and workstations?

4. If you replace "-filter *" for an actual computer name does it work?
0
 

Author Comment

by:WellingtonIS
ID: 39969013
I'm not sure if WRMRm is enabled I'd have to look.  I'm running powershell by right clicking and run as admin.  I'm running the script with my account - last question I'll get back to you.
0
 
LVL 14

Accepted Solution

by:
Justin Yeung earned 500 total points
ID: 39969366
I don't know how much computer object that you have in your environment, it might take a while to complete.

$OutPath = "c:\Your.csv"
$Software = "Example: *Microsoft*"

$Computers = Get-Adcomputer -Filter * 
foreach ($Computer in $Computers)
{
$Ping = Test-Connection -ComputerName $Computer.Name -Quiet -Count 1 
if ($Ping -eq $true)
{
try
{
$MachineName = $Computer.Name 
Get-WmiObject -Class Win32_Product -ComputerName $computer.name -ErrorAction Stop | ? {$_.Name -like $Software} | Select-Object @{N="ComputerName";E={$Computer.Name}},Vendor,Name | Export-Csv $OutPath -Append
}
Catch
{
Write-Host "Unable to Obtain WMI Object of $MachineName" 
}
}
}
If ($Ping -eq $False)
{
Write-Host "The $MachineName is not pingable" 
}

Open in new window

0
 

Author Closing Comment

by:WellingtonIS
ID: 39991744
I had to tweak a little but it worked. Thankx sorry I took so long
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Utilizing an array to gracefully append to a list of EmailAddresses
A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question