header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Best way to get remote software installed info?
Last Post 26 Nov 2008 01:58 AM by halr9000. 7 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
MattGUser is Offline
New Member
New Member
Posts:20
Avatar

--
25 Nov 2008 03:30 PM  
So with Shay and Hal's (and others) help I have been able to remotely query my servers with WMI and import the details into my CMDB.  Now for the last and seemingly most difficult challenge before continuing onto extracting data from the VM VI Toolkit......How do I extract the installed software from each server?   I searched and it appears that the PSINFO method seems to be the easiest?  Based on this I have the following code:

add-pssnapin Quest.ActiveRoles.ADManagement
    Connect-QADService -Service DCSRV1
    $AD = Get-QADComputer -ldapfilter '(&(!(userAccountControl:1.2.840.113556.1.4.803:=2))(|(operatingSystem=*Server*)(&(operatingSystem=*NT*))))'|Sort-Object


$field1 = @{Name="name";Expression={$_.Name}}
$field2 = @{Name="SoftwareNmae";Expression={$item}}

$AD |foreach {
   
    $name = $_.name
    $ping = gwmi win32_pingstatus -filter "address='$name'"
    if($ping.statusCode -eq 0){
       
        $psinfoOutput = c:\psinfo.exe -s \\$name
        foreach ($item in $psinfooutput){
        WHAT DO I DO HERE TO PRODUCE OUTPUT FOR EXPORT-CSV?
            }
        }
    } | export-csv c:\software.csv -noType 


So I want my csv output to be:  software name, servername.

Thanks,
-MattG
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
25 Nov 2008 06:33 PM  
First, let me say that I appreciate that you are creating separate threads for each question, rather than lump them all into one "project". That is much more beneficial to others who may read these posts later.

Psinfo (and the rest of the sysinternals stuff) is really cool. But it is just using WMI to obtain this information. It may be easier to do that as well.

PS > $b = gwmi Win32_Product
PS > $b | gm -memberType property


   TypeName: System.Management.ManagementObject#root\cimv2\Win32_Product

Name              MemberType Definition
----              ---------- ----------
Caption           Property   System.String Caption {get;set;}
Description       Property   System.String Description {get;set;}
IdentifyingNumber Property   System.String IdentifyingNumber {get;set;}
InstallDate       Property   System.String InstallDate {get;set;}
InstallDate2      Property   System.String InstallDate2 {get;set;}
InstallLocation   Property   System.String InstallLocation {get;set;}
InstallState      Property   System.Int16 InstallState {get;set;}
Name              Property   System.String Name {get;set;}
PackageCache      Property   System.String PackageCache {get;set;}
SKUNumber         Property   System.String SKUNumber {get;set;}
Vendor            Property   System.String Vendor {get;set;}
Version           Property   System.String Version {get;set;}
__CLASS           Property   System.String __CLASS {get;set;}
__DERIVATION      Property   System.String[] __DERIVATION {get;set;}
__DYNASTY         Property   System.String __DYNASTY {get;set;}
__GENUS           Property   System.Int32 __GENUS {get;set;}
__NAMESPACE       Property   System.String __NAMESPACE {get;set;}
__PATH            Property   System.String __PATH {get;set;}
__PROPERTY_COUNT  Property   System.Int32 __PROPERTY_COUNT {get;set;}
__RELPATH         Property   System.String __RELPATH {get;set;}
__SERVER          Property   System.String __SERVER {get;set;}
__SUPERCLASS      Property   System.String __SUPERCLASS {get;set;}


PS > $b | select Caption, Version -first 3 | ft -autosize

Caption                                      Version
-------                                      -------
Mobipocket Creator 4.2                       4.2.35
Windows Installer PowerShell Extensions      1.0.0.0
Microsoft Popfly Explorer Beta (1.0.30319.0) 1.0.30319.0
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
25 Nov 2008 06:36 PM  
BTW, enumerating this WMI class in particular is notoriously slow. There's also some drawbacks because it will only show apps that installed a certain way (perhaps via MSI package, I don't recall). I'm hoping that Shay or someone will elaborate on the other ways to find this info. :)
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
MattGUser is Offline
New Member
New Member
Posts:20
Avatar

--
25 Nov 2008 08:13 PM  
Unfortunately, the win32_product does not work on Windows 2003 R2 servers by default. You need to install/enable it. That is why I am going down the road of using the info that PSINFO returns.

Any suggestions on the syntax to produce the export-csv output with psiinfo would be great.

Thanks,
-MattG
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
25 Nov 2008 08:19 PM  
Try this: $a = psinfo -s $apps = $a[19..($a.length)]
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
25 Nov 2008 08:42 PM  
Grr...still formatting issues with the editor. And I'm not paying attention today. Ok, how about this:
$complist = $env:computername
foreach ( $comp in $complist ) {
    $a = psinfo -s \\$comp
    $a | ForEach-Object {
        $out = New-Object psobject
        $out | Add-Member -memberType NoteProperty -name Computer -value $comp
        $out | Add-Member -memberType NoteProperty -name Software -value $_
        Write-Output $out
    } | Export-Csv c:\tmp\file.csv
}
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
MattGUser is Offline
New Member
New Member
Posts:20
Avatar

--
25 Nov 2008 10:22 PM  
Here is the final software script using your suggestions:

add-pssnapin Quest.ActiveRoles.ADManagement
    Connect-QADService -Service DCSRV1
    $AD = Get-QADComputer -ldapfilter '(&(!(userAccountControl:1.2.840.113556.1.4.803:=2))(|(operatingSystem=*Server*)(&(operatingSystem=*NT*))))'|Sort-Object
 
$AD |foreach {
    $name = $_.name
    $ping = gwmi win32_pingstatus -filter "address='$name'"
  
    if($ping.statusCode -eq 0){
        $a = c:\psinfo -s applications \\$name
        $a | ForEach-Object {
            #Remove any dupes, extraneous PSINFO output, Updates, KBs, and Hotfixes
            If (($previousname -eq $_) -or ($_ -clike "System information for \\*") -or ($_ -clike "Applications:") -or (!$_) -or ($_ -clike "*Update for*") -or ($_ -clike "*(KB*")-or ($_ -clike "*Hotfix*")){
                } else
                {
                $out = New-Object psobject
                $out | Add-Member -memberType NoteProperty -name Computer -value $name
                $out | Add-Member -memberType NoteProperty -name Software -value $_
                Write-Output $out
                }
                $previousname = $_
                }
            }
        }| Export-Csv c:\software.csv -notype



Thanks again.
 My focus is now on getting the VMware VM/Host particulars,  so expect to hear from me soon with a different hat on :)

-MattG
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
26 Nov 2008 01:58 AM  
Awesome, glad it's working for you. See ya on communities.vmware.com. :)
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer