February 2007 - Posts
We have a lot of “non standard” servers for whatever reasons. In order to facilitate the DST patch push. I put together an Ad Hoc script to push DST patch to server otherwise can’t be pushed through SMS or Opsware.
First I download psexec.exe from http://www.microsoft.com/technet/sysinternals/utilities/psexec.mspx
Then I run the following VBS script on my computer. What this script does is to copy the “DST” folder to the targeted servers. Then I will use psexec to kick off the dst.bat file on each target server.
dst.vbs:
******************************************************************
On Error Resume Next
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set InputFile = oFSO.OpenTextFile("C:\MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine
sSourceFolder = "C:\DST"
sDestFolderName= "DST"
sDestFolder = "\\" & strComputer & "\C$\" & sDestFolderName
oFSO.CopyFolder sSourceFolder, sDestFolder
Set objShell = CreateObject("WScript.Shell")
objShell.Run("%comspec% /K psexec.exe \\" & strComputer & " -i C:\dst\dst.bat"), 1, True
Loop
InputFile.Close
*********************************************************************
Here is the contents of DST folder:
dst.bat
OSVER.EXE
TimeZoneupd.reg (NT)
TimeZoneUpdate.exe (NT)
Windows2000-KB931836-x86-ENU.EXE
WindowsServer2003-KB931836-x86-ENU.exe
The OSVER.EXE is from Bill Stewart's Site. OSVER allows a batch file to perform operating system platform checking. It can differentiate between Windows 95, Windows 98, Windows Me, Windows NT 4.0, Windows 2000, Windows XP, and Windows Server 2003.
I use Windows OS detection script by Doc Rice as a template and modified it to create my dst.bat file. What it does is to check the Windows OS version on the remote targets and then install the applicable patch.
dst.bat:
**************************************************************
@echo off
for /f "tokens=*" %%i in ('c:\dst\osver.exe') do set windowsversion=%%i
echo This operating system is %windowsversion%.
echo.
if "%windowsversion%" == "Windows NT 4.0" goto windowsnt
if "%windowsversion%" == "Windows 2000" goto windows2000
if "%windowsversion%" == "Windows Server 2003" goto windows2003
:windowsnt
call c:\dst\TimeZoneUpdate.exe
goto end
:windows2000
call C:\dst\Windows2000-KB931836-x86-ENU.EXE /quiet /norestart
goto end
:windows2003
call c:\dst\WindowsServer2003-KB931836-x86-ENU.exe /quiet /norestart
goto end
:end
****************************************************************
Thanks Bill Stewart and Doc Rice for their contribution!
Here is a powershell script translated from my previous VB script –
http://myitforum.com/cs2/blogs/yli628/archive/2007/01/12/vb-script-to-get-symantec-antivirus-client-version-and-virus-definition-date.aspx
In order to access remote registry. I use the OpenRemoteBaseKey method available on the RegistryKey .Net class. That's a really cool thing about PowerShell. It exposes the power of .Net on the commandline. You can access .Net types, methods and properties and it use them to build up solutions you need.
For a key to be opened remotely, both the server and client machines must be running the remote registry service, and have remote administration enabled!
Below is the script:
$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) = "Machine Name"
$c.Cells.Item(1,2) = "Parent Server"
$c.Cells.Item(1,3) = "SAV Version"
$c.Cells.Item(1,4) = "Virus Definition"
$c.Cells.Item(1,5) = "Rev Number"
$c.Cells.Item(1,6) = "Status"
$c.Cells.Item(1,7) = "Report Time Stamp"
$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$intRow = 2
$colComputers = get-content C:\Myworkplace\Clientlist.txt
foreach ($strComputer in $colComputers)
{
$c.Cells.Item($intRow,1) = $strComputer
Function GetRegInfo
{
$key="Software\INTEL\LANDesk\VirusProtect6\CurrentVersion"
$regkey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $strComputer)
$regKey = $regKey.OpenSubKey($key)
$c.Cells.Item($intRow,2) = $regKey.GetValue("parent")
$productver = $regKey.GetValue("ProductVersion")
Switch ($productver)
{
328336375 {$SavVersion ="10.1.5.5010"}
23528424 {$SavVersion = "10.0.0.359"}
65537001 {$SavVersion = "10.0.1.1000"}
65995753 {$SavVersion = "10.0.1.1007"}
66061289 {$SavVersion = "10.0.1.1008"}
131073002 {$SavVersion = "10.0.2.2000"}
131138538 {$SavVersion = "10.0.2.2001"}
131728362 {$SavVersion = "10.0.2.2010"}
132383722 {$SavVersion = "10.0.2.2020"}
132449258 {$SavVersion = "10.0.2.2021"}
25822194 {$SavVersion = "10.1.0.394"}
25953266 {$SavVersion = "10.1.0.396"}
26215410 {$SavVersion = "10.1.0.400"}
26280946 {$SavVersion = "10.1.0.401"}
65536905 {$SavVersion = "9.0.5.1000"}
72090503 {$SavVersion = "9.0.3.1100"}
65536903 {$SavVersion = "9.0.3.1000"}
65536902 {$SavVersion = "9.0.2.1000"}
65536901 {$SavVersion = "9.0.1.1000"}
22152068 {$SavVersion = "9.0.0.338"}
21562155 {$SavVersion = "8.1.1.329"}
21168939 {$SavVersion = "8.1.1.323"}
20906795 {$SavVersion = "8.1.1.319"}
20579115 {$SavVersion = "8.1.1.314"}
54068001 {$SavVersion = "8.1.0.825"}
29950753 {$SavVersion = "8.0.1.457"}
614597408 {$SavVersion = "8.0.0.9378"}
614335264 {$SavVersion = "8.0.0.9374"}
29229856 {$SavVersion = "8.0.0.446"}
28640032 {$SavVersion = "8.0.0.437"}
28443424 {$SavVersion = "8.0.0.434"}
28115744 {$SavVersion = "8.0.0.429"}
27853600 {$SavVersion = "8.0.0.425"}
85197700 {$SavVersion = "7.60.926"}
61997817 {$SavVersion = "7.6.1.946"}
61473529 {$SavVersion = "7.6.1.938"}
60949241 {$SavVersion = "7.6.1.930"}
60687096 {$SavVersion = "7.6.1.926"}
55509743 {$SavVersion = "7.5.1.847"}
48366268 {$SavVersion = "7.0.0"}
}
$c.Cells.Item($intRow,3) = $SavVersion
}
GetRegInfo
Function GetDefInfo
{
$x = Test-path "\\$strcomputer\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat"
if($x -eq "True")
{
$y = get-content "\\$strcomputer\c$\Program Files\Common Files\Symantec Shared\VirusDefs\definfo.dat"
$z = $y[1]
$dtyear = $z.substring(8,4)
$dtmonth = $z.substring(12,2)
$dtday = $z.substring(14,2)
$Rev = $z.substring(16,3)
$ddate = "$dtmonth" + "/"+ "$dtday" + "/" + "$dtyear"
$DateVirDefs =[datetime]$ddate
$c.Cells.Item($intRow,4) = $DateVirDefs
$c.Cells.Item($intRow,5) = $Rev
}
Else
{
$c.Cells.Item($intRow,4) = "Information can't be found"
}
$now = Get-date
$dtdiff = $now - $DatevirDefs
Write-host $dtdiff
If ($dtdiff -gt 1)
{
$c.Cells.Item($intRow,6) = "OK"
}
Else
{
$c.Cells.Item($intRow,6) = "Need Attention!"
}
$c.Cells.Item($intRow,7) = $now
}
GetDefInfo
$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()
cls
Starting in the spring of 2007, daylight saving time (DST) start dates and end dates for the United States will change to comply with the Energy Policy Act of 2005. DST dates in the United States will start three weeks earlier (2:00 A.M. on the second Sunday in March) and will end one week later (2:00 A.M. on the first Sunday in November).
The below Microsoft Technet article describes how to modify the time zone data for SQL Server Notification Services to account for the United States DST change.
http://support.microsoft.com/?kbid=931815&SD=tech
Here is a VB script to read clients list from a txt file and then get McAfee agent information.
On Error Resume Next
Const ForReading = 1
Const HKEY_LOCAL_MACHINE = &H80000002
x = 2
'Create an Excel Work Sheet
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = "Machine Name"
objExcel.Cells(1, 2).Value = "Product"
objExcel.Cells(1, 3).Value = "McAfee Version"
objExcel.Cells(1, 4).Value = "McAfee Scan Engine"
objExcel.Cells(1, 5).Value = "Virus Definition"
objExcel.Cells(1, 6).Value = "Virus Definition Date"
objExcel.Cells(1, 7).Value = "Report Time Stamp"
objExcel.Range("A1:G1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
'Read machine names from a txt file
Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("MachineList.Txt")
Do While Not (InputFile.atEndOfStream)
strComputer = InputFile.ReadLine
intRow = x
objExcel.Cells(intRow, 1).Value = strComputer
GetRegInfo
objExcel.Cells(intRow, 7).Value = Now()
set strValue = Nothing
set dwValue = Nothing
set strSavVersion = Nothing
set objFSO = Nothing
Set objFile = Nothing
'Set objDatFile = Nothing
Set dtDefDate = Nothing
Set strRevNumber= Nothing
x = x + 1
Loop
Wscript.Echo "Done"
'*********************************************************************************************************
'Get information from Registry
Sub GetRegInfo
Set oReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Network Associates\TVD\VirusScan Enterprise\CurrentVersion"
strProduct = "Product"
strProductVer = "szProductVer"
strEngineVer = "szEngineVer"
strVirDefVer = "szVirDefVer"
strVirDefDate = "szVirDefDate"
oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strProduct,strValue1
objExcel.Cells(intRow, 2).Value = strValue1
oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strProductVer,strValue2
objExcel.Cells(intRow, 3).Value = strValue2
oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strEngineVer,strValue3
objExcel.Cells(intRow, 4).Value = strValue3
oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strVirDefVer,strValue4
objExcel.Cells(intRow, 5).Value = strValue4
oReg.GetStringValue _
HKEY_LOCAL_MACHINE,strKeyPath,strVirDefDate,strValue5
objExcel.Cells(intRow, 6).Value = strValue5
End Sub
Here is a VB script to read clients from a txt file and fetch themto a dictionary and ping test them, get their current site code and reassign their site code.
Option Explicit
On Error Resume Next
Dim objDictionary
Dim objFSO
Dim objTextFile
Dim strNextLine
Dim strComputer
Dim result
Dim objItem
Dim TxtFile
Dim i
Dim Dping
Dim Pinged
Dim pingresult
Dim arrPingResult
Dim u
Dim oCCMNamespace
Dim smsClient
Dim inparam
Dim Newresult
Dim NewSite
Const ForReading = 1
'fetch clients list from a txt file to a dictionary
TxtFile = "C:\Myworkplace\Clientlist.txt"
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
(TxtFile, ForReading)
i = 0
Do Until objTextFile.AtEndofStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
For Each objItem in objDictionary
strComputer = objDictionary.Item(objItem)
Set Dping = Wscript.Createobject("Dynu.Ping")
Pinged = False
'ping clients
pingresult = DPing.ping(strComputer, 1, 1, 2000)
arrPingResult = Split(PingResult,vbCRLF)
For u = 0 To UBound(arrPingResult)
If InStr(1,arrPingResult(u),"bytes=1",1) > 0 Then
Pinged = True
'get the current site code
set oCCMNamespace = GetObject("winmgmts://" & strComputer & "/root/ccm")
Set smsClient = oCCMNamespace.Get("SMS_Client")
Set result = smsClient.ExecMethod_("GetAssignedSite")
WScript.Echo strComputer & " Current Assigned Site is: " & result.sSiteCode
' Reassign the site code
Set inParam =smsClient.Methods_.Item("SetAssignedSite").inParameters.SpawnInstance_()
inParam.sSiteCode = "004"
Set Newresult = smsClient.ExecMethod_("SetAssignedSite", inParam)
Set NewSite = smsClient.ExecMethod_("GetAssignedSite")
WScript.Echo strComputer & " New Assigned Site is : " & NewSite.sSiteCode
End If
Next
If Pinged = False Then
WScript.Echo("Unable to ping " & strComputer)
End if
Next