Why doesnt this script work?

Author Message
spooter

  • Total Posts : 17
  • Scores: 0
  • Reward points : 0
  • Joined: 11/14/2007
  • Status: offline
Why doesnt this script work? Wednesday, August 13, 2008 1:32 AM (permalink)
0
Hi all,

I have tried using the script from http://myitforum.com/cs2/blogs/yli628/archive/2007/07/24/poweshell-script-to-check-mcafee-virus-definition.aspx but cant seem to get it working.

$erroractionpreference = "SilentlyContinue"
$a = New-Object -comobject Excel.Application
$a.visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
$c.Cells.Item(1,1) = "Server Name"
$c.Cells.Item(1,2) = "AV Product"
$c.Cells.Item(1,3) = "Version"
$c.Cells.Item(1,4) = "Scan Engine"
$c.Cells.Item(1,5) = "Virus Definition"
$c.Cells.Item(1,6) = "Virus Definition Date"
$c.Cells.Item(1,7) = "Repository Server"
$c.Cells.Item(1,8) = "Report Time Stamp"
$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$intRow = 2
$colComputers = get-content C:\PS\ComputerList.txt
foreach ($strComputer in $colComputers)
{
$c.Cells.Item($intRow,1)  = $strComputer
Function GetRegInfo
{
$key="SOFTWARE\Network Associates\TVD\VirusScan Enterprise\CurrentVersion"
$regkey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $strComputer)
$regKey = $regKey.OpenSubKey($key)
$Product = $regKey.GetValue("Product")
$c.Cells.Item($intRow,2)  = $Product
$productver  = $regKey.GetValue("szProductVer")
$c.Cells.Item($intRow,3) = $Productver
$ScanEngine = $regKey.GetValue("szEngineVer")
$c.Cells.Item($intRow,4) = $ScanEngine
$VirDefVer = $regKey.GetValue("szVirDefVer")
$c.Cells.Item($intRow,5) = $VirDefVer
$virDefDate = $regKey.GetValue("szVirDefDate")
$c.Cells.Item($intRow,6) = $virDefDate
}
GetRegInfo
Function GetSiteInfo
{
$x = Test-path "\\$strcomputer\c$\Documents and Settings\All Users\Application Data\McAfee\Common Framework\UpdateHistory.ini"
if($x -eq "True")
{
$y = get-content "\\$strcomputer\c$\Documents and Settings\All Users\Application Data\McAfee\Common Framework\UpdateHistory.ini"
$z = $y[3]
$SiteServer = $z.substring(19,($z.length-19))
}
$c.Cells.Item($intRow,7) = $SiteServer.ToUpper()
}
GetSiteInfo
$c.Cells.Item($intRow,8) = Get-date

$intRow = $intRow + 1

}
$d.EntireColumn.AutoFit()
cls

The script runs and Microsoft Excel Open but no information gets populated.  I am using Microsoft Excel 2003 is this why?

Thanks all.
<message edited by spooter on Wednesday, August 13, 2008 1:34 AM>
Regards
Spooter
 
#1
    turranx

    • Total Posts : 59
    • Scores: 0
    • Reward points : 0
    • Joined: 2/7/2006
    • Location: Cincinnati, OH
    • Status: offline
    RE: Why doesnt this script work? Wednesday, August 13, 2008 5:52 AM (permalink)
    0
    Are there any computer names populating the file C:\PS\ComputerList.txt ?

    When all else fails, begin inserting statements that echo information to the screen.  Print statements that tell you what part of the code is going to execute / is executing / did execute so you can track its progress.  Also echo the data from key variables.  That will tell you what is working and what is not.
    Microsoft Windows 2000 Scripting Guide - The best book for newbie scripters
    http://www.myspace.com/Evil__Overlord
     
    #2
      SAPIENScripter

      • Total Posts : 283
      • Scores: 2
      • Reward points : 0
      • Joined: 11/1/2006
      • Location: SAPIEN Technologies
      • Status: offline
      RE: Why doesnt this script work? Wednesday, August 27, 2008 2:09 AM (permalink)
      0
      It looks like you are redefining an object:

      $regkey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $strComputer)
      $regKey = $regKey.OpenSubKey($key)

      Try this:
      $regBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $strComputer)
      $regKey = $regBase.OpenSubKey($key)

      I would also try just the PowerShell code at a PS prompt:

      $strcomputer=$env:computername
      $key= "SOFTWARE\Network Associates\TVD\VirusScan Enterprise\CurrentVersion"
      $regbase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $strComputer)
      $regKey = $regbase.OpenSubKey($key)
      $Product = $regKey.GetValue("Product")
      $Product

      Do you get a product listed? This will be for the local computer.  Change $strComputer to a remote computer and try again.  Make sure this part is working then tackle the rest of the script.
      Jeffery Hicks
      Windows PowerShell MVP
      SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

      Follow Me: http://www.twitter.com/JeffHicks
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • 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
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9