Function Get-SavVerWmi{
trap{
break
}
$computer = $args[0]
$namespace = "root\DEFAULT"
$HKLM = 2147483650
$oreg = get-wmiobject -list -namespace $namespace -ComputerName $computer | where-object { $_.name -eq "StdRegProv" }
If($Error){$Error.Clear();break}
$strKeyPath = "SOFTWARE\Symantec\SharedDefs"
$strValueName = "DEFWATCH_10"
$strvalue = ($oreg.GetStringValue($HKLM,$strKeyPath,$strValueName)).svalue
$SavYear = $strvalue
$SavYear = $SavYear.SubString($SavYear.Length - 12,12)
$SavYear = $SavYear.SubString(0,4)
$SavMonth = $strvalue
$SavMonth = $SavMonth.SubString($SavMonth.Length - 12,12)
$SavMonth = $SavMonth.SubString(4,2)
$SavDay = $strvalue
$SavDay = $SavDay.SubString($SavDay.Length - 12,12)
$SavDay = $SavDay.SubString(6,2)
$SavRevision = $strvalue.SubString($strvalue.Length - 3,3)
$SavDate = $SavYear + "-" + $SavMonth + "-" + $SavDay
$DefVer = $SavDate + " rev. " + $SavRevision
$DefVer
$strKeyPath = "SOFTWARE\Intel\DLLUsage\VP6"
$strValueName = "C:\Program Files\Symantec AntiVirus\Rtvscan.exe"
$strvalue = ($oreg.GetStringValue($HKLM,$strKeyPath,$strValueName)).svalue
$RtvscanVer = $strValue
$RtvscanVer
}
更新另外一个的版本:
Function Get-SavVerNet{
trap{
break
}
$computer = $args[0]
$hkey = [Microsoft.Win32.RegistryHive]::LocalMachine
$key = "SOFTWARE\Symantec\SharedDefs"
$value = "DEFWATCH_10"
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($hkey, $Computer)
$regKey = $reg.OpenSubKey($key)
$strvalue = $regKey.GetValue($value)
$SavYear = $strvalue
$SavYear = $SavYear.SubString($SavYear.Length - 12,12)
$SavYear = $SavYear.SubString(0,4)
$SavMonth = $strvalue
$SavMonth = $SavMonth.SubString($SavMonth.Length - 12,12)
$SavMonth = $SavMonth.SubString(4,2)
$SavDay = $strvalue
$SavDay = $SavDay.SubString($SavDay.Length - 12,12)
$SavDay = $SavDay.SubString(6,2)
$SavRevision = $strvalue.SubString($strvalue.Length - 3,3)
$SavDate = $SavYear + "-" + $SavMonth + "-" + $SavDay
$DefVer = $SavDate + " rev. " + $SavRevision
$DefVer
$key = "SOFTWARE\Intel\DLLUsage\VP6"
$value = "C:\Program Files\Symantec AntiVirus\Rtvscan.exe"
$regKey = $reg.OpenSubKey($key)
$strvalue = $regKey.GetValue($value)
$RtvscanVer = $strValue
$RtvscanVer
}
使用方法:Get-SavVerWmi 10.100.1.111
目前脚本并不完善,还需逐步进行修改!
两个版本的速度比较:
PS C:\> measure-command {get-savvernet 10.100.1.1}
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 7
Ticks : 79867
TotalDays : 9.24386574074074E-08
TotalHours : 2.21852777777778E-06
TotalMinutes : 0.000133111666666667
TotalSeconds : 0.0079867
TotalMilliseconds : 7.9867
PS C:\> measure-command {get-savverwmi 10.100.1.1}
Days : 0
Hours : 0
Minutes : 0
Seconds : 4
Milliseconds : 824
Ticks : 48240262
TotalDays : 5.58336365740741E-05
TotalHours : 0.00134000727777778
TotalMinutes : 0.0804004366666667
TotalSeconds : 4.8240262
TotalMilliseconds : 4824.0262
诶,以后能不用wmi,就尽量不用了吧:(