Solved

Powershell script to find specific software

Posted on 2014-03-31
19
8,201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.

695 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