Powershell script to find specific software

Is there a way to search Powershell for a specific software?
Get -ADComputer - Filter {Software - like ...??
WellingtonISAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Justin YeungConnect With a Mentor Senior Systems EngineerCommented:
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
 
rfportillaCommented:
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
 
DeleteCommented:
Try this:

gwmi win32_product -Filter {Name like "%SoftwareName%"}
0
Building an Effective Phishing Protection Program

Join Director of Product Management Todd OBoyle on April 26th as he covers the key elements of a phishing protection program. Whether you’re an old hat at phishing education or considering starting a program -- we'll discuss critical components that should be in any program.

 
WellingtonISAuthor Commented:
It writes to the registry
0
 
rfportillaCommented:
Then Justin F's solution should work.  Try it and let us know.  :-)  Thanks.
0
 
WellingtonISAuthor Commented:
gwmi win32_product -Filter {Name like "%SoftwareName%"}  > C:\software.csv is when I used.
0
 
rfportillaCommented:
Ok.  Please remember to assign points accordingly.
0
 
WellingtonISAuthor Commented:
I must not have the software name correct becuase I'm not getting any data.
0
 
DeleteCommented:
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
 
WellingtonISAuthor Commented:
Will that work on all machines or I need to add a name of a machine?
0
 
footechCommented:
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
 
DeleteCommented:
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
 
WellingtonISAuthor Commented:
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
 
DeleteCommented:
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
 
WellingtonISAuthor Commented:
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
 
Justin YeungSenior Systems EngineerCommented:
I don't think you can do invoke-command without enable-psremoting.
0
 
DeleteCommented:
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
 
WellingtonISAuthor Commented:
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
 
WellingtonISAuthor Commented:
I had to tweak a little but it worked. Thankx sorry I took so long
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.