#184029 - 2007-12-20 04:15 PM
Re: Disk Capacity/Free Space Script
[Re: rcurrao]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
These two lines: Right(' ' + $D_Capacities[$Index], 15) Right(' ' + $D_FreeSpace[$Index], 15) take the capacity and freespace STRING values, left pad them with spaces, and then take the rightmost 15 characters. Thus, it formats and displays in one step. To convert the bytes to K, M, or GBytes, you need to divide the numeric value by the appropriate value.
Keep in mind that the byte values are strings, so need to be converted to numbers. Since the actual values could exceed the limits of integer processing, we convert them to doubles, then divide by MB. As I indicated in my prior post, you can replace these lines with my example: Right(' ' + (CDbl($D_Capacities[$Index]) / 1048576.0), 15) Right(' ' + (CDbl($D_FreeSpace[$Index]) / 1048576.0), 15) The byte values are converted to double-precision numbers, divided by 1MB, then appended to a string of 15 spaces, then trimmed to 15 spaces. This "padding" makes the numbers right-justified in a 15-char wide column.
Note the ".0" at the end of the 1MB divisor - this assures that the division is DBL / DBL, maintaining precision. Kix automatically converts the result to a string, since a string is the first type being combined with the result of the calculation inside the quotes.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#184033 - 2007-12-20 05:10 PM
Re: Disk Capacity/Free Space Script
[Re: rcurrao]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
scratch that...I can not get the all my machines to enuermate in a loop.
I keep getting the results of my local machine.
Break On
; print the header
'Drv Capacity Free <!>' ?
;=====================================================
; Define the name of your test computer
; (later, enumerate a list of computers in a loop)
; $Computer = 'COMPUTER'
If Open(3, "C:\servers.TXT") = 1
$Computer = ReadLine(3)
While Not @ERROR
; reporting code goes here...
$Computer = ReadLine(3)
Loop
$ = Close(3)
EndIf
;=====================================================
; load the array from the computer
$aSysInfo = WMISysInfo($Computer)
If UBound($aSysInfo) = -1
'Bad computer name or no access!' ?
Quit 1
EndIf
; Examine the disk drives & capacities
$D_Letters = Split($aSysInfo[32], ',')
$D_Capacities = Split($aSysInfo[33], ',')
$D_FreeSpace = Split($aSysInfo[34], ',')
For $Index = 0 to UBound($D_Letters)
Left($D_Letters[$Index] + ' ', 4) ; 15 spaces between quotes
Right(' ' + CDbl($D_Capacities[$Index]) / 1048576.0, 15)
Right(' ' + CDbl($D_FreeSpace[$Index]) / 1048576.0, 15)
If CDbl($D_FreeSpace[$Index]) < 500000
' <Low!>'
EndIf
?
Next
Edited by rcurrao (2007-12-20 05:46 PM)
|
|
Top
|
|
|
|
#184045 - 2007-12-20 07:53 PM
Re: Disk Capacity/Free Space Script
[Re: rcurrao]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
Hmm - seems that is exactly what you asked for! 
If you call the function with no argument, you get the information from the local computer. You're calling it with $Computer, which is empty. Your loop read the contents of the file, assigning each name to $Computer, but then did nothing with it! The last read, which had no data, cleared $Computer, so when you finally called the WMISysInfo(), it had an empty argument and displayed the results of the local computer (only).
Here's what you really need - the code that actually does the work to be inside your enumeration loop! I also modified the error check, so that it complained (but didn't quit) if there was an error accessing the computer.
Break On
; print the header
'Drv Capacity Free <!>' ?
;=====================================================
; Define the name of your test computer
; (later, enumerate a list of computers in a loop)
; $Computer = 'COMPUTER'
If Open(3, "C:\servers.TXT") = 1
$Computer = ReadLine(3)
While Not @ERROR
; reporting code goes here... YES - THE CODE THAT DOES THE WORK!!
; load the array from the computer
$aSysInfo = WMISysInfo($Computer)
If UBound($aSysInfo) = -1
'Bad computer name or no access! (' $Computer ')' ?
Else
$Computer ?
; Examine the disk drives & capacities
$D_Letters = Split($aSysInfo[32], ',')
$D_Capacities = Split($aSysInfo[33], ',')
$D_FreeSpace = Split($aSysInfo[34], ',')
For $Index = 0 to UBound($D_Letters)
Left($D_Letters[$Index] + ' ', 4) ; 15 spaces between quotes
Right(' ' + CDbl($D_Capacities[$Index]) / 1048576.0, 15)
Right(' ' + CDbl($D_FreeSpace[$Index]) / 1048576.0, 15)
If CDbl($D_FreeSpace[$Index]) < 500000
' <Low!>'
EndIf
?
Next
EndIf
$Computer = ReadLine(3)
Loop
$ = Close(3)
EndIf
;=====================================================
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#184047 - 2007-12-20 08:12 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Glenn, I owe you a case of Upstates finest brew!
|
|
Top
|
|
|
|
#184085 - 2007-12-20 10:18 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Upstate, NY.
I can not get a results returned to me right now. Just coming back on screen with blank fields.
Break On
; print the header
'Drv Capacity Free <!>' ?
;=====================================================
; Define the name of your test computer
; (later, enumerate a list of computers in a loop)
; $Computer = 'COMPUTER'
If Open(3, "C:\servers.TXT") = 1
$Computer = ReadLine(3)
While Not @ERROR
; reporting code goes here... YES - THE CODE THAT DOES THE WORK!!
; load the array from the computer
$aSysInfo = WMISysInfo($Computer)
If UBound($aSysInfo) = -1
'Bad computer name or no access! (' $Computer ')' ?
Else
$Computer ?
; Examine the disk drives & capacities
$D_Letters = Split($aSysInfo[32], ',')
$D_Capacities = Split($aSysInfo[33], ',')
$D_FreeSpace = Split($aSysInfo[34], ',')
For $Index = 0 to UBound($D_Letters)
Left($D_Letters[$Index] + ' ', 4) ; 15 spaces between quotes
Right(' ' + CDbl($D_Capacities[$Index]) / 1048576.0, 15)
Right(' ' + CDbl($D_FreeSpace[$Index]) / 1048576.0, 15)
If CDbl($D_FreeSpace[$Index]) < 500000
' <Low!>'
EndIf
?
Next
EndIf
$Computer = ReadLine(3)
Loop
$ = Close(3)
EndIf
;=====================================================
; ==========================================================
; UDF Follows
; ==========================================================
;;
;;======================================================================
;;
;;FUNCTION WMISysInfo()
;;
;;ACTION Returns an array containing system information
;; from local or remote system
;;
;;AUTHOR Glenn Barnas
;;
;;VERSION 1.0 / 2007/10/20 - First release
;;
;;SYNTAX WMISysInfo([host] [,AuthPtr])
;;
;;PARAMETERS host - OPTIONAL - name of system to query
;;
;; AuthPtr - OPTIONAL - pre-authenticated WMI object pointer
;; Use WMIAuthentication() udf to create the AuthPtr value
;; AuthPtr is not needed if user has admin rights
;;
;;REMARKS Replaced independent OSInfo and HWInfo UDFs
;;
;;RETURNS 40 element array
;; 0 short/full operating system description
;; 1 kernel description (Win2K, WinXP, Win2K3, Vista)
;; 2 operating system role (workstation, member server, domain controller)
;; 3 operating system service pack level
;; 4 operating system build level
;; 5 uni/multi-processor type
;; 6 Computer Name
;; 7 registered owner,organization
;; 8 Serial Number
;; 9 Install Date - YYYY/MM/DD hh:mm:ss
;; 10 Local Date/Time - YYYY/MM/DD hh:mm:ss
;; 11 Last Boot Time - YYYY/MM/DD hh:mm:ss
;; 12 TimeZone info (Std, Daylight, Bias)
;; 13 Primary Domain Affiliation
;; 14 Installed Hotfix list
;; 15 OS Version (numeric)
;; 16 Future Use
;; 17 O/S Architecture
;; 18 Install Method (Clean, Upgrade, SysPrep)
;; 19 RAM/PageFile Info (location MinSize MaxSize)
;; 20 System Brand
;; 21 System Model
;; 22 System S/N
;; 23 System BIOS Revision
;; 24 Processor Type
;; 25 Processor Speed
;; 26 Processor Count (Physical)
;; 27 Processor Count (Logical)
;; 28 Processor Cores
;; 29 Physical Memory
;; 30 Fixed-Disk Labels, null if none
;; 31 Fixed-Disk Mount Point ("d:\" for drives, path for mounted volumes) (2K3 & higher)
;; 32 Fixed-Disk Drives (A:-Z:, or "MV:" for mounted Volumes)
;; 33 Fixed-Disk Capacities, bytes
;; 34 Fixed-Disk FreeSpace, bytes
;; 35 CD-ROM Disk List
;; 36 Connected Network Drives
;; 37 Hardware Architecture
;; 38 Future Use
;; 39 Future Use
;;
;;DEPENDENCIES WMI support
;;
;;TESTED WITH W2K, WXP, W2K3, Vista, X64
;;
;;EXAMPLES $Host = ''
;; $aHWI = WMIHWInfo($Host)
;; $Host ' has ' $aHWI[6] ' Physical/Logical processors!'
;;
;; $Host = 'server'
;; $objWMI = WMIAuthenticate('computer', 'userid', 'User-P@ss!')
;; $Up = WMIUptime($Host, $objWMI)
;; 'Secure host ' $Host ' has been up for ' $Up[0] ' days!'
;
Function WMISysInfo(OPTIONAL $_Target, OPTIONAL $_pAuth)
Dim $objWMIService, $colItems, $objItem ; WMI object vars
Dim $_SI[39] ; Var for return array
Dim $_, $_Delim, $_SRoot, $_WFile, $_OSVer
$_Target = IIf($_Target, $_Target, '.')
If InStr($_Target, '\') $_Target = Join(Split($_Target, '\'), '') EndIf
If $_pAuth
$objWMIService = $_pAuth
Else
$objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' + $_Target + '\root\cimv2')
If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
EndIf
; O/S SECTION #######################################################
; OperatingSystem =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each $objItem in $colItems
$_SRoot = '\\' + $_Target + '\' + Join(Split($objItem.SystemDirectory, ':'), Chr(36)) + '\'
$_SI[0] = Trim(Split($objItem.Name, '|')[0])
$_SI[15] = $objItem.Version
$_ = _osid($_SI[0], $_SI[15]) ; get kernel name, fix OS name
$_SI[0] = $_[0]
$_SI[1] = $_[1]
$_OSVer = Trim(Join(Split($_SI[15], '.', 2), '.'))
$_ = Split($objItem.CSDVersion, ' ')
$_SI[3] = $_[UBound($_)]
$_SI[4] = $objItem.BuildNumber
$_SI[5] = $objItem.BuildType
$_SI[6] = $objItem.CSName
$_SI[7] = $objItem.RegisteredUser + '/' + $objItem.Organization
$_SI[8] = $objItem.SerialNumber
; Translate the following in to standard date strings (yyyy/mm/dd hh:mm:ss)
$_ = $objItem.InstallDate
$_SI[9] = Left($_, 4) + '/' + SubStr($_, 5, 2) + '/' + SubStr($_, 7, 2) + ' '
+ SubStr($_, 9, 2) + ':' + SubStr($_, 11, 2) + ':' + SubStr($_, 13, 2)
$_ = $objItem.LocalDateTime
$_SI[10] = Left($_, 4) + '/' + SubStr($_, 5, 2) + '/' + SubStr($_, 7, 2) + ' '
+ SubStr($_, 9, 2) + ':' + SubStr($_, 11, 2) + ':' + SubStr($_, 13, 2)
$_ = $objItem.LastBootUpTime
$_SI[11] = Left($_, 4) + '/' + SubStr($_, 5, 2) + '/' + SubStr($_, 7, 2) + ' '
+ SubStr($_, 9, 2) + ':' + SubStr($_, 11, 2) + ':' + SubStr($_, 13, 2)
$_ = $objItem.OSArchitecture
$_SI[17] = IIf($_, $_, '32-bit')
Next
$colItems = 0
; Time Zone =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_TimeZone",,48)
For Each $objItem in $colItems
$_SI[12] = $objItem.StandardName + ' / ' + $objItem.DaylightName + ' / ' + Abs($objItem.Bias) / 60
Next
$colItems = 0
; Domain =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_NTDomain",,48)
For Each $objItem in $colItems
$_SI[13] = $objItem.DNSForestName + ',' + $objItem.DomainName
Next
$colItems = 0
; Hotfixes =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_QuickFixEngineering",,48)
For Each $objItem in $colItems
If InStr('KQ', Left($objItem.HotFixID, 1))
$_SI[14] = $_SI[14] + ' ' + $objItem.HotFixID
EndIf
Next
$_SI[14] = SubStr($_SI[14], 2) ; trim result
$colItems = 0
; PageFile =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_PageFile",,48)
For Each $objItem in $colItems
$_SI[19] = $_SI[19] + ' ' + $objItem.EightDotThreeFileName + ' ' + $objItem.InitialSize + ' ' + $objItem.MaximumSize
Next
$colItems = 0
; Check for build status
$_SI[18] = 'Clean'
$_WFile = $_SRoot + Chr(36) + 'winnt' + Chr(36) + '.inf'
If Exist($_WFile)
If ReadProfileString($_WFile, 'Data', 'StandardServerUpgrade') = 'yes' Or
ReadProfileString($_WFile, 'Data', 'WinNtUpgrade') = 'yes'
$_SI[18] = 'Upgrade'
EndIf
If ReadProfileString($_WFile, 'Unattended', 'InstallFilesPath')
$_SI[18] = 'SysPrep'
EndIf
EndIf
; HARDWARE SECTION #######################################################
; ComputerSystem =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each $objItem in $colItems
$_ = 'Standalone Workstation', 'Member Workstation', 'Standalone Server', 'Member Server', 'Backup Domain Controller',
'Primary Domain Controller'
$_SI[2] = $_[Val($objItem.DomainRole)]
$_SI[37] = Left($objItem.SystemType, 3)
$_SI[20] = $objItem.Manufacturer
$_SI[21] = $objItem.Model
$_SI[26] = $objItem.NumberOfProcessors
$_SI[29] = $objItem.TotalPhysicalMemory
$_ = CInt((CDbl($_SI[29]) + 655360.0) / 1048576.0)
$_SI[19] = '' + $_ + $_SI[19]
Next
$colItems = 0
; BIOS =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
For Each $objItem in $colItems
$_SI[22] = $objItem.SerialNumber
$_Delim = ''
For Each $_ in $objItem.BIOSVersion
$_SI[23] = $_SI[23] + $_Delim + $_
$_Delim = ','
Next
Next
$colItems = 0
; Processor =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_Processor",,48)
For Each $objItem in $colItems
$_SI[24] = Trim($objItem.Name)
$_SI[25] = $objItem.MaxClockSpeed
$_SI[27] = $objItem.NumberOfLogicalProcessors
$_SI[28] = $objItem.NumberOfCores
Next
$colItems = 0
; Disk Storage =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
For Each $objItem in $colItems
If $objItem.DriveType = 3 ; fixed disk
$_SI[30] = $_SI[30] + ',' + $objItem.VolumeName
$_SI[31] = $_SI[31] + ',' + $objItem.Caption + '\'
$_SI[32] = $_SI[32] + ',' + $objItem.Caption
$_SI[33] = $_SI[33] + ',' + $objItem.Size
$_SI[34] = $_SI[34] + ',' + $objItem.FreeSpace
EndIf
If $objItem.DriveType = 5 ; CD-ROM
$_SI[35] = $_SI[35] + ',' + $objItem.Caption
EndIf
If $objItem.DriveType = 4 ; Network Drive
$_SI[36] = $_SI[36] + ',' + $objItem.Caption + '=' + $objItem.ProviderName
EndIf
Next
$colItems = 0
If $_OSVer > 5.1 ; only supported on W2K3 and higher - return mounted volume info
$colItems = $objWMIService.ExecQuery("Select * from Win32_Volume",,48)
For Each $objItem in $colItems
If $objItem.DriveType = 3 And $objItem.DriveLetter = ''
$_SI[30] = $_SI[30] + ',' + $objItem.Label
$_SI[31] = $_SI[31] + ',' + $objItem.Caption
$_SI[32] = $_SI[32] + ',' + 'MV:'
$_SI[33] = $_SI[33] + ',' + $objItem.Capacity
$_SI[34] = $_SI[34] + ',' + $objItem.FreeSpace
EndIf
Next
EndIf
$colItems = 0
; trim leading "," from strings
For $_ = 30 to 36
$_SI[$_] = SubStr($_SI[$_], 2)
Next
; Return the array
$WMISysInfo= $_SI
Exit 0
EndFunction
; _osid - supporting function
; Identifies the release version (beta, RTM, Preview, etc), defines a "kernel short name",
; and removes special characters from the description string
Function _osid($_Vs, $_Vn)
Dim $_
Dim $_Srel ; string of release IDs
Dim $_Vmaj ; Major version number
Dim $_Vmin ; Minor version number
Dim $_Vrel ; Release number
Dim $_aR[1] ; Short (KernelID) name, Descriptive Name
$_ = Split($_Vn + '.0.0', '.', 3)
$_Vmaj = Val($_[0])
$_Vmin = Val($_[1])
$_Vrel = $_[2]
; clean up the O/S description string - remove special chars
$_Vs = Join(Split($_Vs, Chr(153)), '') ; (tm)
$_Vs = Join(Split($_Vs, Chr(169)), '') ; (c)
$_Vs = Join(Split($_Vs, Chr(174)), '') ; (r)
Select
Case $_Vmaj = 5 And $_Vmin = 0 ; Win2K
$_aR[1] = 'Win2K'
$_Srel = '1515=(Beta 2),2031=(Beta 3),2183=(Beta 3),2128=(Beta 3 RC2),2195=(RTM)'
$_ = InStr($_Srel, $_VRel)
If $_
$_ = Split(SubStr($_Srel, $_ + 5), ',')[0]
$_Vs = $_Vs + ' ' + $_
EndIf
Case $_Vmaj = 5 And $_Vmin = 1 ; WinXP
$_aR[1] = 'WinXP'
$_Srel = '2505=(RC1),2600=(RTM)'
$_ = InStr($_Srel, $_VRel)
If $_
$_ = Split(SubStr($_Srel, $_ + 5), ',')[0]
$_Vs = $_Vs + ' ' + $_
EndIf
Case $_Vmaj = 5 And $_Vmin = 2 ; Win2K3
$_aR[1] = 'Win2K3'
$_Srel = '3718=(Eval),3790=(RTM)'
$_ = InStr($_Srel, $_VRel)
If $_
$_ = Split(SubStr($_Srel, $_ + 5), ',')[0]
$_Vs = $_Vs + ' ' + $_
EndIf
Case $_Vmaj = 6 And $_Vmin = 0 ; Vista
$_aR[1] = 'Vista'
$_Srel = '6000=(RTM)'
$_ = InStr($_Srel, $_VRel)
If $_
$_ = Split(SubStr($_Srel, $_ + 5), ',')[0]
$_Vs = $_Vs + ' ' + $_
EndIf
Case 1
$_aR[1] = 'Unknown'
EndSelect
$_aR[0] = $_Vs
$_osid = $_aR
EndFunction
Edited by rcurrao (2007-12-20 10:25 PM)
|
|
Top
|
|
|
|
#184089 - 2007-12-20 10:34 PM
Re: Disk Capacity/Free Space Script
[Re: Mart]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Servers.txt
CWBCISPMSTR1
CWBCISPCONS1
CWBCISPCONS2
CWBCISPEPI1
CWBCISPELINK1
CWBERMSRV1
CWBCISPELINK1
SWBCISULMS
SWBCISPEXTCARE1
CWBCISQMSTR1
CWBCISQCONS1
CWBCISQEPI
CWBCISQELINK1
SWBCISQEXTCARE1
SWBCISMASTER
SWBCISCONS
SWBCISEPI
SWBCISELINK
SWBCISEXTCARE01
SWBCISMRPTST01
|
|
Top
|
|
|
|
#184092 - 2007-12-20 10:53 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
HA! Yeah, I found it by accident for sure. But it makes sense.
The UDF is as follows? Where does this get placed?
; Disk Storage =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
For Each $objItem in $colItems
If $objItem.DriveType = 3 ; fixed disk
$_SI[30] = $_SI[30] + ',' + $objItem.VolumeName
$_SI[31] = $_SI[31] + ',' + $objItem.Caption + '\'
$_SI[32] = $_SI[32] + ',' + $objItem.Caption
$_SI[33] = $_SI[33] + ',' + $objItem.Size
$_SI[34] = $_SI[34] + ',' + $objItem.FreeSpace
EndIf
If $objItem.DriveType = 5 ; CD-ROM
$_SI[35] = $_SI[35] + ',' + $objItem.Caption
EndIf
If $objItem.DriveType = 4 ; Network Drive
$_SI[36] = $_SI[36] + ',' + $objItem.Caption + '=' + $objItem.ProviderName
EndIf
Next
$colItems = 0
If $_OSVer > 5.1 ; only supported on W2K3 and higher - return mounted volume info
$colItems = $objWMIService.ExecQuery("Select * from Win32_Volume",,48)
For Each $objItem in $colItems
If $objItem.DriveType = 3 And $objItem.DriveLetter = ''
$_SI[30] = $_SI[30] + ',' + $objItem.Label
$_SI[31] = $_SI[31] + ',' + $objItem.Caption
$_SI[32] = $_SI[32] + ',' + 'MV:'
$_SI[33] = $_SI[33] + ',' + $objItem.Capacity
$_SI[34] = $_SI[34] + ',' + $objItem.FreeSpace
EndIf
Next
EndIf
$colItems = 0
; trim leading "," from strings
For $_ = 30 to 36
$_SI[$_] = SubStr($_SI[$_], 2)
Next
; Return the array
$WMISysInfo= $_SI
Exit 0
EndFunction
|
|
Top
|
|
|
|
#184095 - 2007-12-20 11:20 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
This is what it should look like:
Break On
; print the header
'Drv Capacity Free <!>' ?
;=====================================================
; Define the name of your test computer
; (later, enumerate a list of computers in a loop)
; $Computer = 'COMPUTER'
If Open(3, "C:\servers.TXT") = 0
$Computer = ReadLine(3)
While Not @ERROR
; reporting code goes here... YES - THE CODE THAT DOES THE WORK!!
; load the array from the computer
$aSysInfo = WMISysInfo($Computer)
@SERROR ?
UBound($aSysInfo) ?
If UBound($aSysInfo) = -1
'Bad computer name or no access! (' $Computer ')' ?
Else
$Computer ?
; Examine the disk drives & capacities
$D_Letters = Split($aSysInfo[32], ',')
$D_Capacities = Split($aSysInfo[33], ',')
$D_FreeSpace = Split($aSysInfo[34], ',')
For $Index = 0 to UBound($D_Letters)
Left($D_Letters[$Index] + ' ', 4) ; 15 spaces between quotes
Right(' ' + Int(CDbl($D_Capacities[$Index]) / 1048576.0), 15)
Right(' ' + Int(CDbl($D_FreeSpace[$Index]) / 1048576.0), 15)
If CDbl($D_FreeSpace[$Index]) < 500000
' <Low!>'
EndIf
?
Next
EndIf
$Computer = ReadLine(3)
Loop
$ = Close(3)
Else
@SERROR ?
EndIf
;=====================================================
; ==========================================================
; UDF Follows
; ==========================================================
;;
;;======================================================================
;;
;;FUNCTION WMISysInfo()
;;
;;ACTION Returns an array containing system information
;; from local or remote system
;;
;;AUTHOR Glenn Barnas
;;
;;VERSION 1.0 / 2007/10/20 - First release
;;
;;SYNTAX WMISysInfo([host] [,AuthPtr])
;;
;;PARAMETERS host - OPTIONAL - name of system to query
;;
;; AuthPtr - OPTIONAL - pre-authenticated WMI object pointer
;; Use WMIAuthentication() udf to create the AuthPtr value
;; AuthPtr is not needed if user has admin rights
;;
;;REMARKS Replaced independent OSInfo and HWInfo UDFs
;;
;;RETURNS 40 element array
;; 0 short/full operating system description
;; 1 kernel description (Win2K, WinXP, Win2K3, Vista)
;; 2 operating system role (workstation, member server, domain controller)
;; 3 operating system service pack level
;; 4 operating system build level
;; 5 uni/multi-processor type
;; 6 Computer Name
;; 7 registered owner,organization
;; 8 Serial Number
;; 9 Install Date - YYYY/MM/DD hh:mm:ss
;; 10 Local Date/Time - YYYY/MM/DD hh:mm:ss
;; 11 Last Boot Time - YYYY/MM/DD hh:mm:ss
;; 12 TimeZone info (Std, Daylight, Bias)
;; 13 Primary Domain Affiliation
;; 14 Installed Hotfix list
;; 15 OS Version (numeric)
;; 16 Future Use
;; 17 O/S Architecture
;; 18 Install Method (Clean, Upgrade, SysPrep)
;; 19 RAM/PageFile Info (location MinSize MaxSize)
;; 20 System Brand
;; 21 System Model
;; 22 System S/N
;; 23 System BIOS Revision
;; 24 Processor Type
;; 25 Processor Speed
;; 26 Processor Count (Physical)
;; 27 Processor Count (Logical)
;; 28 Processor Cores
;; 29 Physical Memory
;; 30 Fixed-Disk Labels, null if none
;; 31 Fixed-Disk Mount Point ("d:\" for drives, path for mounted volumes) (2K3 & higher)
;; 32 Fixed-Disk Drives (A:-Z:, or "MV:" for mounted Volumes)
;; 33 Fixed-Disk Capacities, bytes
;; 34 Fixed-Disk FreeSpace, bytes
;; 35 CD-ROM Disk List
;; 36 Connected Network Drives
;; 37 Hardware Architecture
;; 38 Future Use
;; 39 Future Use
;;
;;DEPENDENCIES WMI support
;;
;;TESTED WITH W2K, WXP, W2K3, Vista, X64
;;
;;EXAMPLES $Host = ''
;; $aHWI = WMIHWInfo($Host)
;; $Host ' has ' $aHWI[6] ' Physical/Logical processors!'
;;
;; $Host = 'server'
;; $objWMI = WMIAuthenticate('computer', 'userid', 'User-P@ss!')
;; $Up = WMIUptime($Host, $objWMI)
;; 'Secure host ' $Host ' has been up for ' $Up[0] ' days!'
;
Function WMISysInfo(OPTIONAL $_Target, OPTIONAL $_pAuth)
Dim $objWMIService, $colItems, $objItem ; WMI object vars
Dim $_SI[39] ; Var for return array
Dim $_, $_Delim, $_SRoot, $_WFile, $_OSVer
$_Target = IIf($_Target, $_Target, '.')
If InStr($_Target, '\') $_Target = Join(Split($_Target, '\'), '') EndIf
If $_pAuth
$objWMIService = $_pAuth
Else
$objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' + $_Target + '\root\cimv2')
If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
EndIf
; O/S SECTION #######################################################
; OperatingSystem =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each $objItem in $colItems
$_SRoot = '\\' + $_Target + '\' + Join(Split($objItem.SystemDirectory, ':'), Chr(36)) + '\'
$_SI[0] = Trim(Split($objItem.Name, '|')[0])
$_SI[15] = $objItem.Version
$_ = _osid($_SI[0], $_SI[15]) ; get kernel name, fix OS name
$_SI[0] = $_[0]
$_SI[1] = $_[1]
$_OSVer = Trim(Join(Split($_SI[15], '.', 2), '.'))
$_ = Split($objItem.CSDVersion, ' ')
$_SI[3] = $_[UBound($_)]
$_SI[4] = $objItem.BuildNumber
$_SI[5] = $objItem.BuildType
$_SI[6] = $objItem.CSName
$_SI[7] = $objItem.RegisteredUser + '/' + $objItem.Organization
$_SI[8] = $objItem.SerialNumber
; Translate the following in to standard date strings (yyyy/mm/dd hh:mm:ss)
$_ = $objItem.InstallDate
$_SI[9] = Left($_, 4) + '/' + SubStr($_, 5, 2) + '/' + SubStr($_, 7, 2) + ' '
+ SubStr($_, 9, 2) + ':' + SubStr($_, 11, 2) + ':' + SubStr($_, 13, 2)
$_ = $objItem.LocalDateTime
$_SI[10] = Left($_, 4) + '/' + SubStr($_, 5, 2) + '/' + SubStr($_, 7, 2) + ' '
+ SubStr($_, 9, 2) + ':' + SubStr($_, 11, 2) + ':' + SubStr($_, 13, 2)
$_ = $objItem.LastBootUpTime
$_SI[11] = Left($_, 4) + '/' + SubStr($_, 5, 2) + '/' + SubStr($_, 7, 2) + ' '
+ SubStr($_, 9, 2) + ':' + SubStr($_, 11, 2) + ':' + SubStr($_, 13, 2)
$_ = $objItem.OSArchitecture
$_SI[17] = IIf($_, $_, '32-bit')
Next
$colItems = 0
; Time Zone =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_TimeZone",,48)
For Each $objItem in $colItems
$_SI[12] = $objItem.StandardName + ' / ' + $objItem.DaylightName + ' / ' + Abs($objItem.Bias) / 60
Next
$colItems = 0
; Domain =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_NTDomain",,48)
For Each $objItem in $colItems
$_SI[13] = $objItem.DNSForestName + ',' + $objItem.DomainName
Next
$colItems = 0
; Hotfixes =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_QuickFixEngineering",,48)
For Each $objItem in $colItems
If InStr('KQ', Left($objItem.HotFixID, 1))
$_SI[14] = $_SI[14] + ' ' + $objItem.HotFixID
EndIf
Next
$_SI[14] = SubStr($_SI[14], 2) ; trim result
$colItems = 0
; PageFile =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_PageFile",,48)
For Each $objItem in $colItems
$_SI[19] = $_SI[19] + ' ' + $objItem.EightDotThreeFileName + ' ' + $objItem.InitialSize + ' ' + $objItem.MaximumSize
Next
$colItems = 0
; Check for build status
$_SI[18] = 'Clean'
$_WFile = $_SRoot + Chr(36) + 'winnt' + Chr(36) + '.inf'
If Exist($_WFile)
If ReadProfileString($_WFile, 'Data', 'StandardServerUpgrade') = 'yes' Or
ReadProfileString($_WFile, 'Data', 'WinNtUpgrade') = 'yes'
$_SI[18] = 'Upgrade'
EndIf
If ReadProfileString($_WFile, 'Unattended', 'InstallFilesPath')
$_SI[18] = 'SysPrep'
EndIf
EndIf
; HARDWARE SECTION #######################################################
; ComputerSystem =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each $objItem in $colItems
$_ = 'Standalone Workstation', 'Member Workstation', 'Standalone Server', 'Member Server', 'Backup Domain Controller', 'Primary Domain Controller'
$_SI[2] = $_[Val($objItem.DomainRole)]
$_SI[37] = Left($objItem.SystemType, 3)
$_SI[20] = $objItem.Manufacturer
$_SI[21] = $objItem.Model
$_SI[26] = $objItem.NumberOfProcessors
$_SI[29] = $objItem.TotalPhysicalMemory
$_ = CInt((CDbl($_SI[29]) + 655360.0) / 1048576.0)
$_SI[19] = '' + $_ + $_SI[19]
Next
$colItems = 0
; BIOS =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
For Each $objItem in $colItems
$_SI[22] = $objItem.SerialNumber
$_Delim = ''
For Each $_ in $objItem.BIOSVersion
$_SI[23] = $_SI[23] + $_Delim + $_
$_Delim = ','
Next
Next
$colItems = 0
; Processor =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_Processor",,48)
For Each $objItem in $colItems
$_SI[24] = Trim($objItem.Name)
$_SI[25] = $objItem.MaxClockSpeed
$_SI[27] = $objItem.NumberOfLogicalProcessors
$_SI[28] = $objItem.NumberOfCores
Next
$colItems = 0
; Disk Storage =======================================================
$colItems = $objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
For Each $objItem in $colItems
If $objItem.DriveType = 3 ; fixed disk
$_SI[30] = $_SI[30] + ',' + $objItem.VolumeName
$_SI[31] = $_SI[31] + ',' + $objItem.Caption + '\'
$_SI[32] = $_SI[32] + ',' + $objItem.Caption
$_SI[33] = $_SI[33] + ',' + $objItem.Size
$_SI[34] = $_SI[34] + ',' + $objItem.FreeSpace
EndIf
If $objItem.DriveType = 5 ; CD-ROM
$_SI[35] = $_SI[35] + ',' + $objItem.Caption
EndIf
If $objItem.DriveType = 4 ; Network Drive
$_SI[36] = $_SI[36] + ',' + $objItem.Caption + '=' + $objItem.ProviderName
EndIf
Next
$colItems = 0
If $_OSVer > 5.1 ; only supported on W2K3 and higher - return mounted volume info
$colItems = $objWMIService.ExecQuery("Select * from Win32_Volume",,48)
For Each $objItem in $colItems
If $objItem.DriveType = 3 And $objItem.DriveLetter = ''
$_SI[30] = $_SI[30] + ',' + $objItem.Label
$_SI[31] = $_SI[31] + ',' + $objItem.Caption
$_SI[32] = $_SI[32] + ',' + 'MV:'
$_SI[33] = $_SI[33] + ',' + $objItem.Capacity
$_SI[34] = $_SI[34] + ',' + $objItem.FreeSpace
EndIf
Next
EndIf
$colItems = 0
; trim leading "," from strings
For $_ = 30 to 36
$_SI[$_] = SubStr($_SI[$_], 2)
Next
; Return the array
$WMISysInfo= $_SI
Exit 0
EndFunction
; _osid - supporting function
; Identifies the release version (beta, RTM, Preview, etc), defines a "kernel short name",
; and removes special characters from the description string
Function _osid($_Vs, $_Vn)
Dim $_
Dim $_Srel ; string of release IDs
Dim $_Vmaj ; Major version number
Dim $_Vmin ; Minor version number
Dim $_Vrel ; Release number
Dim $_aR[1] ; Short (KernelID) name, Descriptive Name
$_ = Split($_Vn + '.0.0', '.', 3)
$_Vmaj = Val($_[0])
$_Vmin = Val($_[1])
$_Vrel = $_[2]
; clean up the O/S description string - remove special chars
$_Vs = Join(Split($_Vs, Chr(153)), '') ; (tm)
$_Vs = Join(Split($_Vs, Chr(169)), '') ; (c)
$_Vs = Join(Split($_Vs, Chr(174)), '') ; (r)
Select
Case $_Vmaj = 5 And $_Vmin = 0 ; Win2K
$_aR[1] = 'Win2K'
$_Srel = '1515=(Beta 2),2031=(Beta 3),2183=(Beta 3),2128=(Beta 3 RC2),2195=(RTM)'
$_ = InStr($_Srel, $_VRel)
If $_
$_ = Split(SubStr($_Srel, $_ + 5), ',')[0]
$_Vs = $_Vs + ' ' + $_
EndIf
Case $_Vmaj = 5 And $_Vmin = 1 ; WinXP
$_aR[1] = 'WinXP'
$_Srel = '2505=(RC1),2600=(RTM)'
$_ = InStr($_Srel, $_VRel)
If $_
$_ = Split(SubStr($_Srel, $_ + 5), ',')[0]
$_Vs = $_Vs + ' ' + $_
EndIf
Case $_Vmaj = 5 And $_Vmin = 2 ; Win2K3
$_aR[1] = 'Win2K3'
$_Srel = '3718=(Eval),3790=(RTM)'
$_ = InStr($_Srel, $_VRel)
If $_
$_ = Split(SubStr($_Srel, $_ + 5), ',')[0]
$_Vs = $_Vs + ' ' + $_
EndIf
Case $_Vmaj = 6 And $_Vmin = 0 ; Vista
$_aR[1] = 'Vista'
$_Srel = '6000=(RTM)'
$_ = InStr($_Srel, $_VRel)
If $_
$_ = Split(SubStr($_Srel, $_ + 5), ',')[0]
$_Vs = $_Vs + ' ' + $_
EndIf
Case 1
$_aR[1] = 'Unknown'
EndSelect
$_aR[0] = $_Vs
$_osid = $_aR
EndFunction
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#184232 - 2007-12-26 04:31 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Glenn, thanks again for all your assistance. I am sorry that it pretty much had to be spoon-fed to me. But I have learn quite a bit about the power of scripting.
One last caveat of this is that I am trying to include the volume name. Here is what I tried, but with no results.
Break On
; print the header
'Drv Label Capacity Free <!>' ?
;=====================================================
; Define the name of your test computer
; (later, enumerate a list of computers in a loop)
; $Computer = 'COMPUTER'
If Open(3, "C:\servers.TXT") = 0
$Computer = ReadLine(3)
While Not @ERROR
; reporting code goes here... YES - THE CODE THAT DOES THE WORK!!
; load the array from the computer
$aSysInfo = WMISysInfo($Computer)
@SERROR ?
UBound($aSysInfo) ?
If UBound($aSysInfo) = -1
'Bad computer name or no access! (' $Computer ')' ?
Else
$Computer ?
; Examine the disk drives & capacities
$D_Letters = Split($aSysInfo[32], ',')
$D_VolumeName = Split($aSysInfo[30], ',')
$D_Capacities = Split($aSysInfo[33], ',')
$D_FreeSpace = Split($aSysInfo[34], ',')
For $Index = 0 to UBound($D_Letters)
Left($D_Letters[$Index] + ' ', 4) ; 15 spaces between quotes
Right(' ' + Int(CDbl($D_Capacities[$Index]) / 1048576.0), 15)
Right(' ' + Int(CDbl($D_FreeSpace[$Index]) / 1048576.0), 15)
If CDbl($D_FreeSpace[$Index]) < 500000
' <Low!>'
EndIf
?
Next
EndIf
$Computer = ReadLine(3)
Loop
$ = Close(3)
Else
@SERROR ?
EndIf
|
|
Top
|
|
|
|
#184233 - 2007-12-26 05:07 PM
Re: Disk Capacity/Free Space Script
[Re: rcurrao]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
No problem - we're here because we enjoy this. 
You, however, do have one small problem.. Let me try to clarify a bit.
"$aSysInfo" is a array, basically a list of related data accessed by an index. Think of one column in a spreadsheet - a variable called $COL_A contains data in 20 rows. In Excel, the rows are numbered 1-20, but in Kix (and most programming languages) arrays are numbered 0-19. This is called "Zero-Based".
Think of the $aSysInfo in terms of a column in a spreadsheet for a moment. Cells 30-34 contain lists of information about drives - "C:,D:,E:" in one, and "14981948109,12390419843,13893049" in the next. Thus, your brain can associate the C: with 14981948109 bytes in the next row; D: with 12390419843, and so on. The computer needs to do it a bit differently. The section of your code that looks like $D_Letters = Split($aSysInfo[32], ',') takes the comma-delimited text string from the 32nd array element and creates a new array called D_Letters. Each element in this array has one drive letter. Since we're doing that for each of these lists, we have several arrays. (consider the spreadsheet, where columns M, N, O, and P represent these vars, and rows 1-3 represent the values. So M1 holds "C:", N1 holds the capacity, O1 holds the freespace, and so on..)
I see that you added a new array $D_VolumeName. This - in effect - altered the spreadsheet model by inserting a new column, but your new column is "hidden". 
Right after we split the drive data strings into individual arrays, we assume that $D_Letters contains one element for each drive letter. Using a For/Next loop, we iterate all of the element values of the drive data arrays using the $Index var. Right after the "For $Index" line are statements that format and output the various array values (note that each one is referenced as $arrayname[$INDEX]). Each of these lines pad the array value with spaces, but then trim it to a specific length. What you're missing is a reference to the new array you created. If you use the first line as a model, you should be able to add the labels the same way, although you'll need to adjust the spacing of the header as well. Each column is 15 chars wide.
< Stop reading here if you want to think about the solution yourself >
So - bottom line - you've correctly referenced the VolumeLabels string from the array, and split it into individual items, but you haven't output it. Copy the "Left($D_Letters".. line, paste a new copy below it, and change the var name to $D_VolumeName and you should be good to go.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#184235 - 2007-12-26 05:46 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Glenn....you magnificent bastard!!!
Ok, I challenged myself and fixed it.
|
|
Top
|
|
|
|
#184256 - 2007-12-27 03:45 AM
Re: Disk Capacity/Free Space Script
[Re: Lonkero]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
Um - yes?
The event log part runs on the client, dumping the logs each night - part of an archiving requirement we have. Keeps 30 days of .EVT files on the server. It also exports on the local server to a TXT format. Exporting on the local computer maintains the computer-specific messages.
There's a server component that gathers some basic info, along with the exported event logs from the servers. After gathering the data, another process is triggered to generate the reports and send the emails. It's a snapshot of system health, along with a summary of the past 24 hours of the event logs, with all the crap filtered out. Each line in the event log report lists the event ID, how many times it occurred, and displays one random message (ie - if event 123 occurred 47 times, the process picks one of the 47 error 123 events at random to include in the email. The point is to give the admin a clue of how many times a certain kind of message has appeared, and let them determine if a closer examination is needed.
When I was at the Fed, we gathered info from about 100 key servers in several sites around the country. A few connected by T3, but some by T1. Data collection ran on a Compaq DL-380 G1 w/ a single 800MHz processor, and performed most of the collections in about 15 minutes at 100% CPU load. It pulled data from a few very old systems at poorly connected sites, which took about 20-30 minutes to complete. Depends on how many entries there are in the event logs, and the speed of the links, remote computers, etc.. We currently collect data from about 40 servers in two well-connected sites in about 4-5 minutes at 100% load.
About the 100% load - I wrote the process to multi-thread the collections - as many as 35 at a time running independently. I kick off 25, then wait until only 10 processes remain and kick off 25 more.. The idea was to hammer the collection server to get it done as quickly as possible.
There actually is a client-side component that I developed for use in DMZ servers. The client was executed over SSH, and returned all of the data. It could easily be adapted to a full client/server environment. I chose not to because we had restrictions about installing client software.
I can send you a sample report from my home network if you PM me your email.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#184265 - 2007-12-27 04:52 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Wow!! That is progressive...but as Freakin Sweet!
I wanted to know the possibilities on the reporting output. Is there a way I can get the "Total Capacity" and "total Free Space" MB's for particular volume labels (e.g. data) to be added up and divided by 1024 to produce a GB value?
I may be wishing here.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1188 anonymous users online.
|
|
|