Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Why doesnt this script work?

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,63412
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> Why doesnt this script work?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Why doesnt this script work? - 8/13/2008 12:32:48 AM   
  spooter

 

Posts: 17
Score: 0
Joined: 11/14/2007
Status: offline
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 -- 8/13/2008 12:34:18 AM >


_____________________________

Regards
Spooter
 
 
Post #: 1
 
 RE: Why doesnt this script work? - 8/13/2008 4:52:21 AM   
  turranx


Posts: 42
Score: 0
Joined: 2/7/2006
Status: offline
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

(in reply to spooter)
 
 
Post #: 2
 
 RE: Why doesnt this script work? - 8/27/2008 1:09:55 AM   
  SAPIENScripter


Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
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

(in reply to turranx)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> Why doesnt this script work? 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