myITforum.com Community Forum myITforum.com Community Forum

Home  Forums  Blogs  Live Support chat  Search Articles  Wiki  FAQ  Email Lists  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Photo Gallery  Member List  Search  Calendars  FAQ  Ticket List  Log Out

All Forums RSS Feed Subscription:


  


need help with add remove programs search script

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
  Printable Version
All Forums >> [Scripting Technologies] >> Windows PowerShell >> need help with add remove programs search script Page: [1]
Login
Message << Older Topic   Newer Topic >>
need help with add remove programs search script - 9/5/2008 6:23:12 PM   
phenry194

 

Posts: 196
Score: 0
Joined: 3/30/2007
Status: offline
I have a script where I search the registry for an entry (guid) for add/remove programs to see if an app has been installed (no particular entry in the directory structure to make the distinction between versions, so I have to query the registry instead).  This is to look for .net 2.0 sp1.  I did a test where I entered a guid for a different program.  I tested the heck out of it to ensure it worked.  I then changed the guid so it would look for .net 2.0 sp1 and I am getting "generic failure" when it runs in powershell on the machines that actually have it installed.  Can anyone help me figure out what I am doing wrong?  After I tested the script about a bazillion times, the ONLY thing I changed was the guid. I confirmed it is spelled correctly.  Help?  here is the script.  thanks!

# Set the hotfix to search for:
$AddRemoveProgram = "{B508B3F1-A24A-32C0-B310-85786919EF28}"
# Get input list:
$Computers = get-content "c:\temp\laptops2.txt"
# Set output file:
$LogFile = "f:\powershell\AddRemoveProgram.log"
foreach ($Computer in $Computers)
{
# " DEBUG: " + $Computer
# Get the AddRemoveProgram info using WMI:
$Results = get-wmiobject -query "SELECT * FROM Win32_product WHERE IdentifyingNumber='$AddRemoveProgram'" -computername $Computer
$NextResult = "Unknown/Error"
# Loop through $Results and look for a match:
foreach ($objItem in $Results)
{
# " DEBUG: " + $objItem.IdentifyingNumber
$NextResult = "Not Installed"
if ($objItem.IdentifyingNumber -eq $AddRemoveProgram)
{
$NextResult = "Installed"
break;
}
}

# Output is tab-delimited:
$Output = "$Computer .Net2.0SP1 $NextResult"
Write-Host $Output
Add-Content $LogFile -value $Output
}
Post #: 1
RE: need help with add remove programs search script - 9/11/2008 9:41:50 AM   
SAPIENScripter

 

Posts: 100
Score: 0
Joined: 5/15/2007
From: SAPIEN Technologies
Status: offline
Can you use WBEMTest to connect to one of the computers in the list and run your query?  Do you still get an error?  We need to see if this is a WMI issue or PowerShell.  I know that the Win32_Product class is very slow/

_____________________________

Jeffery Hicks
Microsoft MVP - Windows PowerShell
http://blog.SAPIEN.com
coming soon: Managing Active Directory with Windows PowerShell: TFM
followme: http://www.twitter.com/jeffHicks

(in reply to phenry194)
Post #: 2
RE: need help with add remove programs search script - 9/11/2008 2:41:15 PM   
phenry194

 

Posts: 196
Score: 0
Joined: 3/30/2007
Status: offline
I'm not too good with wbemtest.  Can you please provide some steps for me to go through and check this?  Thanks.  : )

(in reply to SAPIENScripter)
Post #: 3
RE: need help with add remove programs search script - 9/11/2008 2:57:30 PM   
SAPIENScripter

 

Posts: 100
Score: 0
Joined: 5/15/2007
From: SAPIEN Technologies
Status: offline
click Start- Run and type WBEMTest.
click connect
In the namespace enter \\SOMECOMPUTER\root\cimv2 and click Connect
This will take you back to the main program. Click Query and paste this is: SELECT * FROM Win32_product WHERE IdentifyingNumber='{B508B3F1-A24A-32C0-B310-85786919EF28}'
click apply and wait.
You should get a result which you can double click to see its properties. If this works, then try this in powerShell:

get-wmiobject -query "SELECT * FROM Win32_product WHERE IdentifyingNumber='{B508B3F1-A24A-32C0-B310-85786919EF28}'" -computer SOMENAME




_____________________________

Jeffery Hicks
Microsoft MVP - Windows PowerShell
http://blog.SAPIEN.com
coming soon: Managing Active Directory with Windows PowerShell: TFM
followme: http://www.twitter.com/jeffHicks

(in reply to phenry194)
Post #: 4
RE: need help with add remove programs search script - 9/12/2008 2:24:11 PM   
phenry194

 

Posts: 196
Score: 0
Joined: 3/30/2007
Status: offline
I did as you suggested and got ERROR:  Number 0x80041001 Facility WMI Description Generic Failure.  I clicked on more information and it opened a window that had abstract CIM_BOOLEAN TRUE listed under qualifiers.

(in reply to SAPIENScripter)
Post #: 5
RE: need help with add remove programs search script - 9/12/2008 3:24:31 PM   
SAPIENScripter

 

Posts: 100
Score: 0
Joined: 5/15/2007
From: SAPIEN Technologies
Status: offline
Did you get the error in WBEMTest?  I hate generic errors.  Can you try another machine that you know has the product you're looking for? It may be that WMI is hosed on one machine.  Another way to test is use the same query in WBEMTest but look for another GUID that you know is installed.  It might be worth repeating the WBEMTest locally on the machine you are querying if that's possible as well.

_____________________________

Jeffery Hicks
Microsoft MVP - Windows PowerShell
http://blog.SAPIEN.com
coming soon: Managing Active Directory with Windows PowerShell: TFM
followme: http://www.twitter.com/jeffHicks

(in reply to phenry194)
Post #: 6
RE: need help with add remove programs search script - 9/19/2008 2:21:46 PM   
phenry194

 

Posts: 196
Score: 0
Joined: 3/30/2007
Status: offline
Hi, sorry I am just now getting back to you.  I got sidetracked with putting out some fires.  I am now back at it.  I tried the wbemtest on the actual machine with the app and it worked just fine.  Then I tried it again from the original machine that wbemtest generated a generic error (yes I got the error in wbemtest itself).  Anyway, it decided to work this time (go figure).  Therefore, I took the next step and ran the query in powershell per your directions and it worked correctly.  After that I tried my script again and it worked this time!  I don't know what was going on!  Maybe I needed to fall back on M$'s old fallback and reboot.  I don't know.  Anyway, it works now.  Thanks for your help with this.  BTW, do you know of a way where I could incorporate a ping or timeout or something so that it can return an "offline" message or something to that effect?  If not, no worries.  I have a script that does that, but when I try to incorporate it into this script, it generates a multitude of errors, and I currently don't know enough about Powershell to determine a resolution.  Thanks.  : )

(in reply to SAPIENScripter)
Post #: 7
RE: need help with add remove programs search script - 9/20/2008 10:07:58 AM   
martylist

 

Posts: 41
Score: 0
Joined: 6/10/2005
From: Colorado, USA
Status: offline
Post the latest version of what you have so far (that's not working) and we'll try to help.

(in reply to phenry194)
Post #: 8
RE: need help with add remove programs search script - 9/23/2008 2:55:56 PM   
phenry194

 

Posts: 196
Score: 0
Joined: 3/30/2007
Status: offline
OK, here is what I have used when looking for a file.  I didn't write it, I just edit it as needed depending on what I am looking for.  It pings the machine, puts a message on the screen if it can't reach it via ping, and dumps the information of if a file is installed or not into an excel spreadsheet.  What I would like to do is incorporate the ping function into the script above so it doesn't dump a entry into the log saying it's not installed just because it is offline.  I just haven't managed to find a way to combine the two scripts so it will work.  Here you go.  Thanks.  : )

## *********** Beginning of function Pingme   ***********
function PingMe ($pc)
{
$ping = new-object System.Net.NetworkInformation.Ping
  $rslt = $ping.send("$pc")
  if ($rslt.status –eq “Success”) {
                                    write-host (“ping $pc worked”) -foregroundcolor "Yellow"
                                    return $true
                                  }
         else {
                ""
               write-warning “$pc is not reachable”
               return $false
              }
}   
# End of function PingMe
############################################################
$ErrorActionPreference = "SilentlyContinue"
$EXobj = New-Object -comobject Excel.Application
$EXobj.visible = $True
$book = $EXobj.Workbooks.Add()
$col = $book.Worksheets.Item(1)
$col.Cells.Item(1,1) = "Machine Name"
$col.Cells.Item(1,2) = "WSE 3.0"
$dd = $col.UsedRange
$dd.Interior.ColorIndex = 19
$dd.Font.ColorIndex = 11
$dd.Font.Bold = $True
$dd.EntireColumn.AutoFit()
$row = 2
foreach ($pc in get-content c:\temp\counterPCs.txt)
      {
        $online=PingMe($pc)
         if ($online -eq $true)
           {
              $newpath="\\$pc\c$\program files\Microsoft WSE\v3.0\wse.config"
 get-item $newpath  

 if ($? -eq $true)
                {
                        $col.Cells.Item($row,1) = $pc
                        $col.Cells.item($row,2) = "installed"
                }                     
 
 else
                        {
                          $col.Cells.Item($row,1) = $pc
                          $col.Cells.item($row,2) = "Not installed"
                        }
                   $row = $row + 1
              }
   
          }

(in reply to martylist)
Post #: 9
RE: need help with add remove programs search script - 9/24/2008 12:50:08 PM   
phenry194

 

Posts: 196
Score: 0
Joined: 3/30/2007
Status: offline
Hey, I am getting the same problem again.  I ran wbemtest on the machine with the entry and get and error name: 0x80041010, facility: wmi, description: invalid class.  I tried the old registry entry that didn't work, then did work, now doesn't work again.  I did this because I was going to do another report on another registry entry (same structure) and it didn't work.  When I run the test in powershell I get the generic failure message.  I try the old and the new registry entry.  Why is this being so sporadic?  This is driving me absolutely nuts that I think I can get some information for someone and then I can't. 

(in reply to phenry194)
Post #: 10
RE: need help with add remove programs search script - 9/24/2008 5:43:31 PM   
phenry194

 

Posts: 196
Score: 0
Joined: 3/30/2007
Status: offline
OK, I added the PingMe function to the beginning of the script and then right after the beginning of the first foreach loop I put the line PingMe ($Computer), so it pings it before it looks for the guid in the registry.  This doesn't put anything in the log, but it puts something on the screen.  I found out that why the wbemtest isn't always consistent, is that on some of the machines WMI is corrupted, which I believe someone mentioned in this thread somewhere or I read it somewhere.  Does anyone have any information on how to correct wmi corruption or is that a rebuild type of thing on the individual machines?  The reason I am asking is with wmi corruption, running any powershell scripts that query wmi would be pretty useless.

(in reply to phenry194)
Post #: 11
RE: need help with add remove programs search script - 9/24/2008 9:40:33 PM   
martylist

 

Posts: 41
Score: 0
Joined: 6/10/2005
From: Colorado, USA
Status: offline
 I doubt you will be able to "correct WMI corruption" unless you know what is wrong.  If you want to start over with a fresh repository: http://www.microsoft.com/technet/community/en-us/management/wmi_faq.mspx
Q. How do I rebuild the repository?A. If you delete or rename the repository, the first WMI operation will force Winmgmt to rebuild the repository. Only MOFs marked for autorecover will be "re-mofcomp'd" (meaning you may lose some static data unless you have it backed up somewhere else). From the command line, type: net stop winmgmt /y
rename %windir%\system32\wbem\repository %windir%\system32\wbem\repository.old
net start winmgmt More info:
http://www.google.com/search?hl=en&q=%28wbem+OR+wmi%29+%28corrupt+OR+repair+OR+rebuild%29+repository 
An update is available that improves the stability of the Windows Management Instrumentation repository in Windows XP
http://support.microsoft.com/kb/933062
 

(in reply to phenry194)
Post #: 12
RE: need help with add remove programs search script - 9/25/2008 12:25:05 PM   
phenry194

 

Posts: 196
Score: 0
Joined: 3/30/2007
Status: offline
OK, thanks.  I found some similar information last night and did some testing there.  It fixed one machine but not another.  I'll keep fighting with this thing.  Thanks for your help.  : )

(in reply to martylist)
Post #: 13
Page:   [1]
All Forums >> [Scripting Technologies] >> Windows PowerShell >> need help with add remove programs search script Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts



  
Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.250