[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Powershell script to find specific software

Posted on 2014-03-31
19
Medium Priority
?
10,009 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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 41

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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
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 give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

656 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