Link to home
Start Free TrialLog in
Avatar of Sleestack90
Sleestack90

asked on

PowerShell 1.0 Script Error

I have the following script which runs and provides output, however it also give me an error message:

$computersToQuery = ("COMPUTER1", "COMPUTER2")

$softwareInventory = @{}
foreach ($computer in $computersToQuery) {
   $psinfoOutput = C:\WINDOWS\system32\psinfo.exe -s Applications \\$computer

   $foundSoftwareInventory = 0
   $computerName = ""
   foreach ($item in $psinfoOutput) {
      if ($foundSoftwareInventory -eq 1) {
         # Force the results to a string
         # Remove any single quotes which interfere with T-SQL statements
         # Load the result into a hash whereby removing any duplicates
         [string]$softwareInventory[$computerName][$item.Replace("'","")] = ""
      }

      if ($item -like "System information for *") {
         $computerName = $item.Split("\")[2].TrimEnd(":")
      } elseif ($item -eq "Applications:") {
         $foundSoftwareInventory = 1
         $softwareInventory[$computerName] = @{}
      }
   }
}

foreach ($computer in $softwareInventory.Keys) {
   foreach ($softwareItem in $softwareInventory[$computer].Keys) {
      $computer + ":" + $softwareItem
   }
}


Here is the result of running the script:

PS C:\Scripts> C:\Scripts\Software.ps1
psinfo.exe :
At C:\Scripts\Software.ps1:5 char:50
+    $psinfoOutput = C:\WINDOWS\system32\psinfo.exe <<<<  -s Applications \\$computer
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
PsInfo v1.77 - Local and remote system information viewer
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com


Querying information for COMPUTER1...
psinfo.exe :
At C:\Scripts\Software.ps1:5 char:50
+    $psinfoOutput = C:\WINDOWS\system32\psinfo.exe <<<<  -s Applications \\$computer
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
PsInfo v1.77 - Local and remote system information viewer
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com


Connecting to COMPUTER2...Querying information for COMPUTER2...
COMPUTER2:Security Update for Windows XP (KB971657) 1
COMPUTER2:SoundMAX 5.12.01.5246
COMPUTER2:Hotfix for Microsoft .NET Framework 3.5 SP1 (KB958484) 1
COMPUTER2:Microsoft .NET Framework 2.0 Service Pack 2 2.2.30729
COMPUTER2:Security Update for Windows XP (KB979482) 1
COMPUTER2:Microsoft .NET Framework 3.5 SP1 3.5.30729
COMPUTER2:Security Update for Windows XP (KB973354) 1
COMPUTER2:Security Update for Windows Media Player (KB978695)
COMPUTER2:Security Update for Windows XP (KB979309) 1
COMPUTER2:Security Update for Windows XP (KB974392) 1
COMPUTER2:Hotfix for Windows XP (KB954550-v5) 5
COMPUTER2:Security Update for Windows XP (KB975713) 1
COMPUTER2:Security Update for Windows XP (KB956844) 1
COMPUTER2:Update for Windows XP (KB955759) 1
COMPUTER2:Microsoft National Language Support Downlevel APIs
COMPUTER2:Microsoft Office Excel MUI (English) 2007 12.0.4518.1014
COMPUTER2:Microsoft English TTS Engine 2.0.1000.0
COMPUTER2:Security Update for Windows XP (KB952954) 1
COMPUTER2:Security Update for Windows XP (KB970238) 1
COMPUTER2:Security Update for Windows XP (KB970430) 1
COMPUTER2:Security Update for Windows XP (KB960225) 1
COMPUTER2:Microsoft Office Visio MUI (English) 2007 12.0.4518.1014
COMPUTER2:Microsoft Office PowerPoint MUI (English) 2007 12.0.4518.1014
COMPUTER2:Security Update for Windows XP (KB951066) 1
COMPUTER2:Security Update for Windows XP (KB981349) 1
COMPUTER2:Security Update for Windows XP (KB971961) 1
COMPUTER2:Security Update for Windows Media Player (KB979402)
COMPUTER2:Hotfix for Windows XP (KB961118) 1
COMPUTER2:Security Update for Windows XP (KB956744) 1
COMPUTER2:Update for Windows Internet Explorer 7 (KB980182) 1
COMPUTER2:Security Update for Windows XP (KB960803) 1
COMPUTER2:Windows XP Service Pack 3 20080414.031525
COMPUTER2:Security Update for Windows XP (KB952004) 1
COMPUTER2:Java(TM) 6 Update 20 6.0.200
COMPUTER2:Apple Software Update 2.1.2.120
COMPUTER2:Microsoft Office Proof (English) 2007 12.0.4518.1014
COMPUTER2:Update for Windows XP (KB951978) 1
COMPUTER2:Hotfix for Windows Media Format 11 SDK (KB929399)
COMPUTER2:Adobe Acrobat 8.2.2 Standard 8.2.2
COMPUTER2:Security Update for Windows XP (KB981852) 1
COMPUTER2:Security Update for Windows XP (KB941569)
COMPUTER2:Security Update for Windows XP (KB2160329) 1
COMPUTER2:Update for Windows XP (KB968389) 1
COMPUTER2:Security Update for Windows XP (KB978542) 1
COMPUTER2:Update for Microsoft .NET Framework 3.5 SP1 (KB963707) 1
COMPUTER2:Security Update for Windows XP (KB958869) 1
COMPUTER2:Security Update for Windows XP (KB975025) 1
COMPUTER2:Security Update for Windows XP (KB982665) 1
COMPUTER2:Security Update for Windows XP (KB978251) 1
COMPUTER2:TTS Wrapper 1.0.0.0
COMPUTER2:Hotfix for Windows XP (KB979306) 1
COMPUTER2:Security Update for Windows Search 4 - KB963093
COMPUTER2:Trend Micro Client/Server Security Agent 16.0.1331
COMPUTER2:Windows Media Format 11 runtime
COMPUTER2:Microsoft .NET Framework 3.0 Service Pack 2 3.2.30729
COMPUTER2:Microsoft Office Professional Hybrid 2007 12.0.4518.1014
COMPUTER2:Microsoft Office Proof (Spanish) 2007 12.0.4518.1014
COMPUTER2:Security Update for Windows XP (KB979559) 1
COMPUTER2:Hotfix for Microsoft .NET Framework 3.5 SP1 (KB953595) 1
COMPUTER2:Microsoft Office Access MUI (English) 2007 12.0.4518.1014
COMPUTER2:Security Update for Windows XP (KB972270) 1
COMPUTER2:Broadcom Gigabit Integrated Controller 8.10.07
COMPUTER2:Security Update for Windows XP (KB973507) 1
COMPUTER2:Security Update for Windows XP (KB980232) 1
COMPUTER2:Apple Application Support 1.2.1
COMPUTER2:Security Update for Windows XP (KB923789)
COMPUTER2:Security Update for Windows XP (KB978601) 1
COMPUTER2:Security Update for Windows XP (KB2115168) 1
COMPUTER2:Windows Search 4.0 04.00.6001.503
COMPUTER2:Security Update for Windows XP (KB975467) 1
COMPUTER2:Windows Internet Explorer 7 20070813.185237
COMPUTER2:Security Update for Windows XP (KB954459) 1
COMPUTER2:Security Update for Windows XP (KB959426) 1
COMPUTER2:Hotfix for Windows XP (KB952287) 1
COMPUTER2:WebFldrs XP 9.50.7523
COMPUTER2:Security Update for Windows XP (KB969947) 1
COMPUTER2:Windows Genuine Advantage Notifications (KB905474) 1.9.0040.0
COMPUTER2:Security Update for Windows XP (KB923561) 1
COMPUTER2:Security Update for Windows XP (KB980195) 1
COMPUTER2:Security Update for Windows Media Player (KB973540)
COMPUTER2:Security Update for Windows XP (KB973904) 1
COMPUTER2:Security Update for Windows XP (KB974318) 1
COMPUTER2:Security Update for Windows Internet Explorer 7 (KB982381) 1
COMPUTER2:Update for Windows XP (KB980182) 1
COMPUTER2:QuickTime 7.66.71.0
COMPUTER2:Windows Genuine Advantage Validation Tool (KB892130) 1.7.0069.2
COMPUTER2:Microsoft Office Visio Standard 2007 12.0.4518.1014
COMPUTER2:Security Update for Windows XP (KB978037) 1
COMPUTER2:Java Auto Updater 2.0.2.1
COMPUTER2:Security Update for Windows XP (KB979683) 1
COMPUTER2:Security Update for Windows XP (KB955069) 1
COMPUTER2:Apple Mobile Device Support 3.0.0.102
COMPUTER2:Microsoft Office Outlook MUI (English) 2007 12.0.4518.1014
COMPUTER2:Security Update for Windows XP (KB978338) 1
COMPUTER2:Security Update for Windows Internet Explorer 7 (KB2183461) 1
COMPUTER2:2007 Microsoft Office system 12.0.4518.1014
COMPUTER2:Hotfix for Windows XP (KB915800-v4) 4
COMPUTER2:Update for Windows XP (KB973687) 1
COMPUTER2:Intel(R) Graphics Media Accelerator Driver 6.14.10.4543
COMPUTER2:Security Update for Windows XP (KB950762) 1
COMPUTER2:Security Update for Windows XP (KB971468) 1
COMPUTER2:Microsoft Internationalized Domain Names Mitigation APIs
COMPUTER2:Microsoft Office Proofing (English) 2007 12.0.4518.1014
COMPUTER2:Security Update for Windows Media Player (KB952069)
COMPUTER2:Security Update for Windows XP (KB978706) 1
COMPUTER2:Security Update for Windows XP (KB975562) 1
COMPUTER2:Security Update for Windows XP (KB977914) 1
COMPUTER2:Update for Windows XP (KB967715) 1
COMPUTER2:Microsoft Office Publisher MUI (English) 2007 12.0.4518.1014
COMPUTER2:Security Update for Windows XP (KB2229593) 1
COMPUTER2:Security Update for Windows Internet Explorer 7 (KB938127-v2) 2
COMPUTER2:Security Update for Windows XP (KB969059) 1
COMPUTER2:Security Update for Windows XP (KB977165-v2) 2
COMPUTER2:Security Update for Windows XP (KB950974) 1
COMPUTER2:VNC Free Edition 4.1.2 4.1.2
COMPUTER2:Update for Windows XP (KB973815) 1
COMPUTER2:Adobe Acrobat 8.2.2 - CPSID_53952
COMPUTER2:Security Update for Windows XP (KB977816) 1
COMPUTER2:Security Update for Windows XP (KB2286198) 1
COMPUTER2:Microsoft Visual C++ 2008 Redistributable Package 1.0.0
COMPUTER2:Microsoft Streets & Trips 2010 17.0.19.2900
COMPUTER2:Microsoft .NET Framework 3.5 SP1
COMPUTER2:Security Update for Windows XP (KB974112) 1
COMPUTER2:Microsoft Office Proof (French) 2007 12.0.4518.1014
COMPUTER2:Security Update for Windows XP (KB981997) 1
COMPUTER2:Adobe Acrobat  8 Standard - English, Frantais, Deutsch 8.2.2
COMPUTER2:Microsoft Office Shared MUI (English) 2007 12.0.4518.1014
COMPUTER2:Microsoft Office Access database engine 2007 (English) 12.0.4518.1031
COMPUTER2:Microsoft Office Access Setup Metadata MUI (English) 2007 12.0.4518.1014
COMPUTER2:Security Update for Windows XP (KB946648) 1
COMPUTER2:Security Update for Windows XP (KB975561) 1
COMPUTER2:Security Update for Windows XP (KB956572) 1
COMPUTER2:Security Update for Windows XP (KB980436) 1
COMPUTER2:Security Update for Windows XP (KB961501) 1
COMPUTER2:Security Update for Windows XP (KB974571) 1
COMPUTER2:Security Update for Windows XP (KB951376-v2) 2
COMPUTER2:Security Update for Windows XP (KB982214) 1
COMPUTER2:Security Update for Windows XP (KB950760) 1
COMPUTER2:Security Update for Windows XP (KB956803) 1
COMPUTER2:Security Update for Windows XP (KB973869) 1
COMPUTER2:iTunes 9.1.0.79
COMPUTER2:Security Update for Windows XP (KB975560) 1
COMPUTER2:Update for Windows XP (KB971737) 1
COMPUTER2:Microsoft Office Shared Setup Metadata MUI (English) 2007 12.0.4518.1014
COMPUTER2:Security Update for Windows XP (KB956802) 1
COMPUTER2:Security Update for Windows XP (KB960859) 1
COMPUTER2:Security Update for Windows XP (KB951748) 1
COMPUTER2:SAPI Wrapper 1.0.0.0
COMPUTER2:Security Update for Windows XP (KB958644) 1
COMPUTER2:Hotfix for Windows XP (KB981793) 1
COMPUTER2:Security Update for Windows XP (KB2079403) 1
COMPUTER2:Windows Genuine Advantage Validation Tool (KB892130)
COMPUTER2:Security Update for Windows Media Player (KB954155)
COMPUTER2:Security Update for Windows XP (KB978262) 1
COMPUTER2:Bonjour 2.0.0.34
COMPUTER2:Security Update for Windows Media Player (KB968816)
COMPUTER2:Security Update for Windows XP (KB980218) 1
COMPUTER2:Microsoft Software Update for Web Folders  (English) 12 12.0.4518.1014
COMPUTER2:Microsoft Office Word MUI (English) 2007 12.0.4518.1014
COMPUTER1:3ivx MPEG-4 5.0.2 (remove only) 5.0.2
COMPUTER1:Mitel 5000 DB Programming AVDAP Monitor
COMPUTER1:Security Update for Microsoft Office Visio Viewer 2007 (KB973709)
COMPUTER1:Windows Live Essentials 14.0.8089.0726
COMPUTER1:Security Update for Windows XP (KB981997) 1
COMPUTER1:Mitel 5000 DB Programming DB Test
COMPUTER1:Intel(R) Graphics Media Accelerator Driver 6.14.10.4410
COMPUTER1:Windows Live Essentials 14.0.8089.726
COMPUTER1:Security Update for Microsoft Office system 2007 (972581)
COMPUTER1:Hotfix for Windows XP (KB979306) 1
COMPUTER1:WatchGuard Mobile VPN with SSL client 11.0
COMPUTER1:Adobe Acrobat  8 Standard - English, Frantais, Deutsch 8.2.4
COMPUTER1:Microsoft Office Professional Hybrid 2007 12.0.6425.1000
COMPUTER1:Hotfix for Microsoft .NET Framework 3.5 SP1 (KB953595) 1
COMPUTER1:Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.17 9.0.30729
COMPUTER1:Security Update for Windows XP (KB969947) 1
COMPUTER1:Security Update for Windows Internet Explorer 7 (KB982381) 1
COMPUTER1:Microsoft Silverlight 4.0.50524.0
COMPUTER1:Security Update for Windows XP (KB941569)
COMPUTER1:Security Update for Windows Internet Explorer 7 (KB938127-v2) 2
COMPUTER1:BlackBerry Device Software Updater 5.0.1.65
COMPUTER1:Security Update for Windows XP (KB975713) 1
COMPUTER1:Windows XP Service Pack 3 20080414.031525
COMPUTER1:Microsoft User-Mode Driver Framework Feature Pack 1.0
COMPUTER1:Security Update for Windows XP (KB946648) 1
COMPUTER1:Broadcom Gigabit Integrated Controller 8.10.07
COMPUTER1:Mitel 5000 DB Programming Remote Configuration
COMPUTER1:SoundMAX 5.12.01.5246
COMPUTER1:Microsoft English TTS Engine 2.0.1000.0
COMPUTER1:Security Update for Windows XP (KB958869) 1
COMPUTER1:Security Update for Windows Media Player (KB954155)
COMPUTER1:Microsoft Search Enhancement Pack 3.0.126.0
COMPUTER1:Security Update for Windows XP (KB960803) 1
COMPUTER1:Security Update for Windows Media Player (KB968816)
COMPUTER1:BlackBerry Desktop Software 5.0.1 5.0.1.37
COMPUTER1:Security Update for Windows Media Player (KB978695)
COMPUTER1:Java(TM) 6 Update 21 6.0.210
COMPUTER1:Security Update for Windows XP (KB978601) 1
COMPUTER1:MSN Toolbar Platform 4.0.0379.0
COMPUTER1:Update for Windows XP (KB980182) 1
COMPUTER1:Microsoft Office Proof (French) 2007 12.0.6425.1000
COMPUTER1:Security Update for Windows XP (KB975560) 1
COMPUTER1:Microsoft Office Proof (Spanish) 2007 12.0.6425.1000
COMPUTER1:Security Update for Windows XP (KB956744) 1
COMPUTER1:Security Update for Windows XP (KB975561) 1
COMPUTER1:Security Update for Windows XP (KB950762) 1
COMPUTER1:Mobile Broadband Generic Drivers 2.02.07.002.14
COMPUTER1:Windows Media Format 11 runtime
COMPUTER1:Microsoft .NET Framework 2.0 Service Pack 2 2.2.30729
COMPUTER1:Microsoft Office Outlook MUI (English) 2007 12.0.6425.1000
COMPUTER1:FreeFileSync v3.6
COMPUTER1:Security Update for Microsoft Office Word 2007 (KB2251419)
COMPUTER1:Microsoft UI Engine 4.0.0318.1
COMPUTER1:Security Update for Windows XP (KB978542) 1
COMPUTER1:Hotfix for Windows XP (KB981793) 1
COMPUTER1:Microsoft Office Proof (English) 2007 12.0.6425.1000
COMPUTER1:Security Update for Windows XP (KB974392) 1
COMPUTER1:Security Update for Windows XP (KB954459) 1
COMPUTER1:Security Update for Windows XP (KB960859) 1
COMPUTER1:Security Update for Windows Internet Explorer 7 (KB2183461) 1
COMPUTER1:Security Update for Windows XP (KB974112) 1
COMPUTER1:Security Update for CAPICOM (KB931906) 2.1.0.2
COMPUTER1:EMCO Remote Installer Starter
COMPUTER1:Nmap 4.76
COMPUTER1:Security Update for Windows XP (KB956802) 1
COMPUTER1:Easy CD & DVD Creator 6 6.0.0.171
COMPUTER1:Microsoft Choice Guard 2.0.48.0
COMPUTER1:Update for Windows XP (KB971737) 1
COMPUTER1:Security Update for Windows XP (KB950974) 1
COMPUTER1:Microsoft Compression Client Pack 1.0 for Windows XP 1
COMPUTER1:Security Update for Windows XP (KB958644) 1
COMPUTER1:Hotfix for Microsoft .NET Framework 3.5 SP1 (KB958484) 1
COMPUTER1:Security Update for Windows XP (KB951376-v2) 2
COMPUTER1:Microsoft Office Visio Standard 2007 12.0.6425.1000
COMPUTER1:Security Update for Windows XP (KB923789)
COMPUTER1:Security Update for Windows XP (KB978262) 1
COMPUTER1:Segoe UI 14.0.4327.805
COMPUTER1:Security Update for Windows XP (KB971657) 1
COMPUTER1:Microsoft Office PowerPoint MUI (English) 2007 12.0.6425.1000
COMPUTER1:Microsoft Office Visio 2007 Service Pack 2 (SP2)
COMPUTER1:Security Update for Windows XP (KB977165-v2) 2
COMPUTER1:Windows Driver Package - Inter-Tel Incorporated TAP-Win32 Adapter 5000m (09/13/2006 9.00.00.0004) 09/13/2006 9.00.00.0004
COMPUTER1:Mitel 5000 DB Programming MOH Converter Utility
COMPUTER1:Microsoft Office Access Setup Metadata MUI (English) 2007 12.0.6425.1000
COMPUTER1:Update for Microsoft Office Powerpoint 2007 Help (KB963669)
COMPUTER1:Security Update for Windows XP (KB969059) 1
COMPUTER1:Security Update for Windows Search 4 - KB963093
COMPUTER1:Microsoft .NET Framework 3.0 Service Pack 2 3.2.30729
COMPUTER1:Windows Live ID Sign-in Assistant 6.500.3165.0
COMPUTER1:MSN Toolbar 4.0.0379.0
COMPUTER1:Windows Live Messenger 14.0.8089.0726
COMPUTER1:UberIcon 1.0.4
COMPUTER1:Update for Windows XP (KB968389) 1
COMPUTER1:Adobe Flash Player 10 ActiveX 10.1.53.64
COMPUTER1:IIS 6.0 Resource Kit Tools 6.00.0000
COMPUTER1:Security Update for 2007 Microsoft Office System (KB982331)
COMPUTER1:Security Update for Windows XP (KB970238) 1
COMPUTER1:Windows Genuine Advantage Validation Tool (KB892130)
COMPUTER1:Security Update for Windows XP (KB979309) 1
COMPUTER1:LogMeIn 4.0.982
COMPUTER1:Command WorkStation 5.1.1.04 5.1.1.04
COMPUTER1:Security Update for Windows XP (KB977816) 1
COMPUTER1:Update for Microsoft Office Word 2007 Help (KB963665)
COMPUTER1:Update for Microsoft .NET Framework 3.5 SP1 (KB963707) 1
COMPUTER1:Security Update for Windows XP (KB982665) 1
COMPUTER1:Security Update for Windows XP (KB2286198) 1
COMPUTER1:Security Update for Microsoft Office PowerPoint 2007 (KB982158)
COMPUTER1:Security Update for Windows XP (KB977914) 1
COMPUTER1:Microsoft Software Update for Web Folders  (English) 12 12.0.6425.1000
COMPUTER1:Update for Windows XP (KB961503) 1
COMPUTER1:Adobe Acrobat 8.2.4 Standard 8.2.4
COMPUTER1:Security Update for Windows XP (KB970430) 1
COMPUTER1:MSVCRT 14.0.1468.721
COMPUTER1:Client 9.00.000
COMPUTER1:Security Update for Windows XP (KB975467) 1
COMPUTER1:Security Update for Windows XP (KB960225) 1
COMPUTER1:Security Update for Windows XP (KB973507) 1
COMPUTER1:Security Update for Windows XP (KB951066) 1
COMPUTER1:Microsoft Office 2007 Service Pack 2 (SP2)
COMPUTER1:BlackBerry« Media Sync 3.0.0.39
COMPUTER1:Update for Windows XP (KB943729)
COMPUTER1:Security Update for Windows XP (KB981349) 1
COMPUTER1:Security Update for Windows XP (KB974318) 1
COMPUTER1:Security Update for Windows XP (KB952004) 1
COMPUTER1:Microsoft SQL Server 2008 R2 Report Builder 3.0 10.50.1352.12
COMPUTER1:Windows Management Framework Core
COMPUTER1:Update for Microsoft Office Excel 2007 Help (KB963678)
COMPUTER1:LMS v9.0 9.00.000
COMPUTER1:Adobe Flash Player 10 Plugin 10.1.53.64
COMPUTER1:Security Update for Microsoft Office system 2007 (KB974234)
COMPUTER1:Security Update for Windows XP (KB980436) 1
COMPUTER1:Security Update for Windows XP (KB956572) 1
COMPUTER1:Security Update for Windows XP (KB978338) 1
COMPUTER1:Microsoft Visual C++ 2005 Redistributable 8.0.59193
COMPUTER1:WebFldrs XP 9.50.7523
COMPUTER1:OGA Notifier 2.0.0048.0 2.0.0048.0
COMPUTER1:Security Update for Windows XP (KB981852) 1
COMPUTER1:Microsoft Office Proofing Tools 2007 Service Pack 2 (SP2)
COMPUTER1:Mozilla Firefox (3.6.6) 3.6.6 (en-US)
COMPUTER1:Security Update for Windows XP (KB956844) 1
COMPUTER1:Windows Resource Kit Tools 5.2.3790
COMPUTER1:Hotfix for Windows XP (KB915800-v4) 4
COMPUTER1:BlackBerry Device Software v4.5.0 for the BlackBerry 8330 smartphone 4.5.0.175 (Platform 3.4.0.55)
COMPUTER1:Compatibility Pack for the 2007 Office system 12.0.6514.5001
COMPUTER1:VZAccess Manager for Novatel 6.9.8
COMPUTER1:Update for Microsoft Office 2007 Help for Common Features (KB963673)
COMPUTER1:Microsoft Office Publisher MUI (English) 2007 12.0.6425.1000
COMPUTER1:Collaboration Client 2.0 4.4.3.0
COMPUTER1:Security Update for Windows XP (KB971468) 1
COMPUTER1:Trend Micro Client/Server Security Agent 16.0.1331
COMPUTER1:CCleaner 2.30
COMPUTER1:Security Update for Microsoft Office Excel 2007 (KB982308)
COMPUTER1:PHP 5.3.2 5.3.2
COMPUTER1:Security Update for Windows XP (KB979683) 1
COMPUTER1:Microsoft Default Manager 2.1.54.0
COMPUTER1:Update for Microsoft Office Outlook 2007 Help (KB963677)
COMPUTER1:Security Update for Windows XP (KB2160329) 1
COMPUTER1:Windows Internet Explorer 7 20070813.185237
COMPUTER1:Update for Windows XP (KB955759) 1
COMPUTER1:Security Update for Windows XP (KB982214) 1
COMPUTER1:Microsoft Visual C++ 2005 Redistributable 8.0.56336
COMPUTER1:Security Update for Windows Media Player (KB973540)
COMPUTER1:Microsoft .NET Framework 1.1 1.1.4322
COMPUTER1:winpcap-nmap 4.02
COMPUTER1:Windows Live Call 14.0.8064.0206
COMPUTER1:Microsoft Office Word MUI (English) 2007 12.0.6425.1000
COMPUTER1:Windows Genuine Advantage Validation Tool (KB892130) 1.7.0069.2
COMPUTER1:Security Update for Microsoft Office Access 2007 (KB979440)
COMPUTER1:Microsoft Office Visio MUI (English) 2007 12.0.6425.1000
COMPUTER1:Security Update for Windows XP (KB961501) 1
COMPUTER1:Microsoft Visual C++ 2008 Redistributable - x86 9.0.21022 9.0.21022
COMPUTER1:Security Update for Windows XP (KB980232) 1
COMPUTER1:Microsoft .NET Framework 3.5 SP1
COMPUTER1:Hotfix for Windows XP (KB932716-v2) 2
COMPUTER1:Hotfix for Windows XP (KB954550-v5) 5
COMPUTER1:Security Update for Windows XP (KB978037) 1
COMPUTER1:Security Update for Windows XP (KB974571) 1
COMPUTER1:Security Update for Windows XP (KB2079403) 1
COMPUTER1:Microsoft .NET Framework 3.5 SP1 3.5.30729
COMPUTER1:Microsoft Office Access MUI (English) 2007 12.0.6425.1000
COMPUTER1:Microsoft .NET Framework 1.1
COMPUTER1:Microsoft Office Shared Setup Metadata MUI (English) 2007 12.0.6425.1000
COMPUTER1:Windows Server 2003 Administration Tools Pack 5.2.3790
COMPUTER1:Security Update for 2007 Microsoft Office System (KB976321)
COMPUTER1:Update for Windows XP (KB973815) 1
COMPUTER1:Hotfix for Windows Media Format 11 SDK (KB929399)
COMPUTER1:Update for Microsoft Office Access 2007 Help (KB963663)
COMPUTER1:Security Update for Windows XP (KB971961) 1
COMPUTER1:Security Update for Windows XP (KB980218) 1
COMPUTER1:Update for 2007 Microsoft Office System (KB967642)
COMPUTER1:2007 Microsoft Office system 12.0.6425.1000
COMPUTER1:Security Update for Windows XP (KB973869) 1
COMPUTER1:Update for Microsoft Windows (KB971513)
COMPUTER1:Windows Media Player 11
COMPUTER1:Microsoft Internationalized Domain Names Mitigation APIs
COMPUTER1:Security Update for Windows XP (KB955069) 1
COMPUTER1:Microsoft .NET Framework 1.1 Security Update (KB979906)
COMPUTER1:Security Update for Windows XP (KB980195) 1
COMPUTER1:Security Update for Windows XP (KB979559) 1
COMPUTER1:Mitel 5000 DB Programming Diagnostics Monitor
COMPUTER1:Security Update for 2007 Microsoft Office System (KB969559)
COMPUTER1:SAPI Wrapper 1.0.0.0
COMPUTER1:Security Update for Windows XP (KB959426) 1
COMPUTER1:Microsoft Office Excel MUI (English) 2007 12.0.6425.1000
COMPUTER1:Update for Windows XP (KB967715) 1
COMPUTER1:MSXML 6.0 Parser (KB927977) 6.00.3890.0
COMPUTER1:Microsoft Office Shared MUI (English) 2007 12.0.6425.1000
COMPUTER1:Security Update for Windows XP (KB923561) 1
COMPUTER1:Mitel 5000 DB Programming 3.2.4.54
COMPUTER1:Update for Microsoft Office Script Editor Help (KB963671)
COMPUTER1:Update for Windows Internet Explorer 7 (KB980182) 1
COMPUTER1:Security Update for Microsoft Office Outlook 2007 (KB980376)
COMPUTER1:Security Update for Windows XP (KB972270) 1
COMPUTER1:Security Update for Windows XP (KB975025) 1
COMPUTER1:Adobe Acrobat 8.2.4 - CPSID_83708
COMPUTER1:Security Update for Windows XP (KB978706) 1
COMPUTER1:Security Update for Microsoft Office InfoPath 2007 (KB979441)
COMPUTER1:Update for Outlook 2007 Junk Email Filter (kb2279264)
COMPUTER1:Update for Windows XP (KB973687) 1
COMPUTER1:Windows Live Communications Platform 14.0.8098.930
COMPUTER1:Security Update for Windows XP (KB973904) 1
COMPUTER1:Security Update for Windows XP (KB975562) 1
COMPUTER1:Update for Windows XP (KB951978) 1
COMPUTER1:Java Auto Updater 2.0.2.4
COMPUTER1:Security Update for Windows XP (KB978251) 1
COMPUTER1:Security Update for 2007 Microsoft Office System (KB982312)
COMPUTER1:Security Update for Windows Media Player 11 (KB954154)
COMPUTER1:Microsoft Virtual PC 2007 6.0.156.0
COMPUTER1:Security Update for Windows XP (KB973354) 1
COMPUTER1:Security Update for Windows XP (KB976323) 1
COMPUTER1:Microsoft Base Smart Card Cryptographic Service Provider Package
COMPUTER1:Security Update for Microsoft Office Publisher 2007 (KB982124)
COMPUTER1:Security Update for 2007 Microsoft Office System (KB2277947)
COMPUTER1:Hotfix for Windows XP (KB961118) 1
COMPUTER1:Update for Microsoft Office Publisher 2007 Help (KB963667)
COMPUTER1:Security Update for Windows XP (KB979482) 1
COMPUTER1:Security Update for Windows XP (KB956803) 1
COMPUTER1:Security Update for Microsoft Office Visio 2007 (KB982127)
COMPUTER1:Microsoft RichCopy 4.0 4.0.216
COMPUTER1:Security Update for Windows XP (KB950760) 1
COMPUTER1:Mitel 5000 DB Programming Upload Utility
COMPUTER1:Microsoft Application Error Reporting 12.0.6012.5000
COMPUTER1:Security Update for Windows XP (KB2115168) 1
COMPUTER1:Microsoft National Language Support Downlevel APIs
COMPUTER1:Hotfix for Windows XP (KB952287) 1
COMPUTER1:Security Update for Windows XP (KB952954) 1
COMPUTER1:Security Update for Windows Media Player (KB952069)
COMPUTER1:Microsoft Office Proofing (English) 2007 12.0.4518.1014
COMPUTER1:Security Update for Windows XP (KB2229593) 1
COMPUTER1:Security Update for Windows XP (KB951748) 1
COMPUTER1:Windows Genuine Advantage Notifications (KB905474) 1.9.0040.0
COMPUTER1:VNC Free Edition 4.1.2 4.1.2
COMPUTER1:Windows Search 4.0 04.00.6001.503
COMPUTER1:Hotfix for Windows Media Player 11 (KB939683)
COMPUTER1:Microsoft Visual C++ 2008 ATL Update kb973924 - x86 9.0.30729.4148 9.0.30729.4148
Avatar of rwskas
rwskas
Flag of United States of America image

Not exactly sure why that error is appearing, I am not conviced it has to do with Powershell though.
To suppress it, add the code blow in your foreach loop prior to $psinfooutput

Trap { Continue }
Avatar of Sleestack90
Sleestack90

ASKER

@rwskas:  no dice sir, still the same errors.

here is what i did to be sure i understood you correctly:

$computersToQuery = ("COMPUTER1", "COMPUTER2")

$softwareInventory = @{}
foreach ($computer in $computersToQuery) {
  Trap { Continue } $psinfoOutput = C:\WINDOWS\system32\psinfo.exe -s Applications \\$computer

   $foundSoftwareInventory = 0
   $computerName = ""
   foreach ($item in $psinfoOutput) {
      if ($foundSoftwareInventory -eq 1) {
         # Force the results to a string
         # Remove any single quotes which interfere with T-SQL statements
         # Load the result into a hash whereby removing any duplicates
         [string]$softwareInventory[$computerName][$item.Replace("'","")] = ""
      }

      if ($item -like "System information for *") {
         $computerName = $item.Split("\")[2].TrimEnd(":")
      } elseif ($item -eq "Applications:") {
         $foundSoftwareInventory = 1
         $softwareInventory[$computerName] = @{}
      }
   }
}

foreach ($computer in $softwareInventory.Keys) {
   foreach ($softwareItem in $softwareInventory[$computer].Keys) {
      $computer + ":" + $softwareItem
   }
}
Do this:
$softwareInventory = @{}
foreach ($computer in $computersToQuery) {
  Trap { Continue }
$psinfoOutput = C:\WINDOWS\system32\psinfo.exe -s Applications \\$computer
Same:

psinfo.exe :
At C:\Scripts\Software.ps1:6 char:47
+ $psinfoOutput = C:\WINDOWS\system32\psinfo.exe <<<<  -s Applications \\$computer
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
PsInfo v1.77 - Local and remote system information viewer
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com


Querying information for R18DELL...
psinfo.exe :
At C:\Scripts\Software.ps1:6 char:47
+ $psinfoOutput = C:\WINDOWS\system32\psinfo.exe <<<<  -s Applications \\$computer
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
PsInfo v1.77 - Local and remote system information viewer
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com


Connecting to R19DELL...Querying information for R19DELL...

Here it provides the query details....noteven sure if this is a big deal because it's going to write all of these to a database, but i would like it to be as clean as possible.
I am stumped.. I can copy and paste that script and run it without any issues. The only thing I see different is you run psinfo v 1.77 and I run v 1.75
i'm attempting to write this to the database this evening, i'll post more tomorrow and we may have something else to work off of.
Change this line:
$psinfoOutput = C:\WINDOWS\system32\psinfo.exe -s Applications \\$computer

to this:
$psinfoOutput=invoke-expression "C:\WINDOWS\system32\psinfo.exe -s Applications \\$computer"
*** that's all one line ;) ... don't forget the quotes.
 
Same deal:

psinfo.exe :
At line:1 char:31
+ C:\WINDOWS\system32\psinfo.exe <<<<  -s Applications \\COMPUTER1
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
PsInfo v1.77 - Local and remote system information viewer
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com


Querying information for COMPUTER1...
psinfo.exe :
At line:1 char:31
+ C:\WINDOWS\system32\psinfo.exe <<<<  -s Applications \\COMPUTER2
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
PsInfo v1.77 - Local and remote system information viewer
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com


Connecting to COMPUTER2...Querying information for COMPUTER2...

************Here is pulls up the data as normal: COMPUTERNAME: SOFTWARE

***************************************************************************************************************************
The End goal being this code:

# Open the database connection
$dbConn = new-object System.Data.SqlClient.SqlConnection "server=SERVERNAME;database=BGInfo;Integrated Security=True"
$dbConn.Open()
$sqlQuery = $dbConn.CreateCommand()

# Get all known computers
$sqlQuery.CommandText = "select distinct Host_Name from BGinfoTable"
$reader = $sqlQuery.ExecuteReader()
$computersToQuery = @()
while ($reader.Read()) {
   $computersToQuery += $reader["Computer"]
}

# Close the database connection
$dbConn.Close()

$softwareInventory = @{}
foreach ($computer in $computersToQuery) {
   $psinfoOutput = C:\WINDOWS\system32\psinfo.exe -s Applications \\$computer

   $foundSoftwareInventory = 0
   $computerName = ""
   foreach ($item in $psinfoOutput) {
      if ($foundSoftwareInventory -eq 1) {
         # Force the results to a string
         # Remove any single quotes which interfere with T-SQL statements
         # Load the result into a hash whereby removing any duplicates
         [string]$softwareInventory[$computerName][$item.Replace("'","")] = ""
      }

      if ($item -like "System information for *") {
         $computerName = $item.Split("\")[2].TrimEnd(":")
      } elseif ($item -eq "Applications:") {
         $foundSoftwareInventory = 1
         $softwareInventory[$computerName] = @{}
      }
   }
}

$dbConn = new-object System.Data.SqlClient.SqlConnection "server=SERVERNAME;database=BGInfo;Integrated Security=True"
$dbConn.Open()
$sqlQuery = $dbConn.CreateCommand()

foreach ($computer in $softwareInventory.Keys) {
   foreach ($softwareItem in $softwareInventory[$computer].Keys) {
      "Loading-" + $computer + ":" + $softwareItem

      # Try an Insert than an Update
      trap {
         $sqlQuery.CommandText = "update SoftwareInventory set AuditDate = getdate() where  Computer = '" + $computer + "' and Software = '" + $softwareItem + "'"
         $result = $sqlQuery.ExecuteNonQuery()
         continue
      }

      $sqlQuery.CommandText = "insert into Inventory..SoftwareInventory (Computer,Software,AuditDate) values ('" + $computer + "','" + $softwareItem + "',getdate())"
      $result = $sqlQuery.ExecuteNonQuery()
   }
}

$dbConn.Close()

****************************************************************************************************************************
Which Creates this result:

Connecting to ...Querying information for ...
psinfo.exe :
At C:\Scripts\SoftwareAudit.ps1:19 char:50
+    $psinfoOutput = C:\WINDOWS\system32\psinfo.exe <<<<  -s Applications \\$computer
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
PsInfo v1.77 - Local and remote system information viewer
Copyright (C) 2001-2009 Mark Russinovich
Sysinternals - www.sysinternals.com


Connecting to ...Querying information for ...
Loading-:3ivx MPEG-4 5.0.2 (remove only) 5.0.2
Loading-:Mitel 5000 DB Programming AVDAP Monitor
Loading-:Security Update for Microsoft Office Visio Viewer 2007 (KB973709)
Loading-:Windows Live Essentials 14.0.8089.0726
Loading-:Security Update for Windows XP (KB981997) 1
Loading-:Mitel 5000 DB Programming DB Test
Loading-:Intel(R) Graphics Media Accelerator Driver 6.1
This is more of a long shot than anything... but may be worth a try
Add "psinfo" as a System or User variable
In System Properties (Rigth click My Computer -> properties)
Select 'Advanced'
Select 'Environment Variables'
Under 'System Variables'
Select 'New'
Variable Name: psinfo
Variable Value: C:\Windows\System32\psinfo.exe
Select 'OK'
Select 'OK'
Select 'OK'

In your script, change $psinfoinfooutput = .. to the code snippet below


$psinfoOutput = psinfo -s Applications \\$computer

Open in new window

The following code with correctly pull from my BGinfo data base using the Host_Name field (a predetermined field through BGinfo).

The BGinfo grabs all the computer names when people log in after arriving to work. This script pulls the names and runs the software audit.

Now I am attempting to write the software audit results back into another database table called SotwareInventory........

I am having some trouble with this part because I am hopeless with SQL. Any ideas here?


Also, the errors I mentioned above are due to PSinfo no being installed on every computer....but it doens't need to be...all of this works without installing it everywhere.
Open the database connection
$dbConn = new-object System.Data.SqlClient.SqlConnection "server=SQLSERVER;database=BGInfo;Integrated Security=True"
$dbConn.Open()
$sqlQuery = $dbConn.CreateCommand()

# Get all known computers
$sqlQuery.CommandText = "select distinct Host_Name from BGinfoTable"
$reader = $sqlQuery.ExecuteReader()
$computersToQuery = @()
while ($reader.Read()) {
   $computersToQuery += $reader["Host_Name"]
}

# Close the database connection
$dbConn.Close()

$softwareInventory = @{}
foreach ($computer in $computersToQuery) {
   $psinfoOutput = C:\WINDOWS\system32\psinfo.exe -s Applications \\$computer

   $foundSoftwareInventory = 0
   $computerName = ""
   foreach ($item in $psinfoOutput) {
      if ($foundSoftwareInventory -eq 1) {
         # Force the results to a string
         # Remove any single quotes which interfere with T-SQL statements
         # Load the result into a hash whereby removing any duplicates
         [string]$softwareInventory[$computerName][$item.Replace("'","")] = ""
      }

      if ($item -like "System information for *") {
         $computerName = $item.Split("\")[2].TrimEnd(":")
      } elseif ($item -eq "Applications:") {
         $foundSoftwareInventory = 1
         $softwareInventory[$computerName] = @{}
      }
   }
}

$dbConn = new-object System.Data.SqlClient.SqlConnection "server=SQLSERVER;database=BGInfo;Integrated Security=True"
$dbConn.Open()
$sqlQuery = $dbConn.CreateCommand()

foreach ($computer in $softwareInventory.Keys) {
   foreach ($softwareItem in $softwareInventory[$computer].Keys) {
      $computer + ":" + $softwareItem

      # Try an Insert than an Update
      trap {
         $sqlQuery.CommandText = "update SoftwareInventory set AuditDate = getdate() where  Computer = '" + $computer + "' and Software = '" + $softwareItem + "'"
         $result = $sqlQuery.ExecuteNonQuery()
         continue
      }

      $sqlQuery.CommandText = "insert into Inventory..SoftwareInventory (Computer,Software,AuditDate) values ('" + $computer + "','" + $softwareItem + "',getdate())"
      $result = $sqlQuery.ExecuteNonQuery()
   }
}

$dbConn.Close()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sleestack90
Sleestack90

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial