Solved

Powershell script to find specific software

Posted on 2014-03-31
19
5,902 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
Comment Utility
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
Comment Utility
Try this:

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

Author Comment

by:WellingtonIS
Comment Utility
It writes to the registry
0
 
LVL 9

Expert Comment

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

Author Comment

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

Expert Comment

by:rfportilla
Comment Utility
Ok.  Please remember to assign points accordingly.
0
 

Author Comment

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

Expert Comment

by:Delete
Comment Utility
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
Comment Utility
Will that work on all machines or I need to add a name of a machine?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 39

Expert Comment

by:footech
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I don't think you can do invoke-command without enable-psremoting.
0
 
LVL 7

Expert Comment

by:Delete
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I had to tweak a little but it worked. Thankx sorry I took so long
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now