#183944 - 2007-12-19 05:16 PM
Disk Capacity/Free Space Script
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Hello all, I am rather new to this and was hoping someone could lend a hand on how to go about a task I have. I need to query all the disk space available on multiple servers across our network. After logging into the first 15 machines to check the details, I remembered how I used KiXtart a while back to assist me with multiple printer creations and wondered if I could get lucking again. My problem is that I am not much of a scriptor.
I have about 60 machines I need to know what their current Free space and capacity is and was wondering if anyone could point me in a direction to automate this process?
Thank you so much. Richard
|
Top
|
|
|
|
#183950 - 2007-12-19 06:24 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Glenn, thank you so much. I will check this out. I really appreciate your assistance.
|
Top
|
|
|
|
#183951 - 2007-12-19 06:53 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Wow...I may be in over my head here. I just tried to sort some of this out and my eyes went crossed.
My apologies, I am usually the Citrix Administrator. But have some downtime to lend a hand.
|
Top
|
|
|
|
#183957 - 2007-12-19 07:58 PM
Re: Disk Capacity/Free Space Script
[Re: rcurrao]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
It's not as scary as it looks... Consider the UDF as a "black box" like any other function - you ask a question and get an answer. Try this:
Download the UDF & save it as "WMISysInfo.UDF" in the root of C: (for now). If you have a preferred place for your UDFs, put it there and modify the path in the CALL statement.
Next, try the following example:
Break On
; Load the UDF
Call "C:\temp\WMISysInfo.UDF" ; or specify your alternate location
; print the header
'Drv Capacity Free <!>' ?
; Define the name of your test computer
; (later, enumerate a list of computers in a loop)
$Computer = 'lghbsappp04'
; load the array from the computer
$aSysInfo = WMISysInfo($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) ; 150 spaces between quotes
Right(' ' + $D_Capacities[$Index], 15)
Right(' ' + $D_FreeSpace[$Index], 15)
If Val($D_FreeSpace[$Index]) < 500
' <Low!>'
EndIf
?
Next
This should display a simple report for all drives on that system. If you wrap this logic into a loop, enumerating a list of computers, you can get a report for each computer.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#183960 - 2007-12-19 08:11 PM
Re: Disk Capacity/Free Space Script
[Re: rcurrao]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
Well here is something to get you started. It's old code and could use some updating but should work. Then you might want to read a file of server names to feed it in a loop. You could also use WMI to find the drives to feed it as well.
If Not @LogonMode
Break On
EndIf
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
$SO=SetOption('WrapAtEOL','On')
Dim $Dsize
$Dsize = GetDiskFreeSpace('your SERVER name here','D')
'Bytes Total Disk Size is: ' + $Dsize[0] ?
'Percent Used is: ' + $Dsize[1] + '%' ?
'Percent Unused is: ' + $Dsize[2] +'%' ?
'Bytes Left Unused is: ' + $Dsize[3] ?
Function GetDiskFreeSpace($sComputer,$Drive)
Dim $objWMIService, $colDisks, $objDisk
Dim $FreeSpace, $TotalSize, $pctFreeSpace, $pctUsed
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $sComputer + "\root\cimv2")
If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
$colDisks = $objWMIService.ExecQuery('Select * from Win32_LogicalDisk Where DeviceID = '+"'"+$Drive+":'")
If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
For Each $objDisk in $colDisks
If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
$FreeSpace = CDBL($objDisk.FreeSpace)
$TotalSize = CDBL($objDisk.Size)
$pctFreeSpace = FormatNumber(($FreeSpace / $TotalSize * 100),2)
$FreeSpace = FormatNumber($FreeSpace,-1,,-2)
$pctUsed = CDBL(100) - $pctFreeSpace
$pctUsed = FormatNumber($pctUsed,-1,,-2)
$TotalSize = FormatNumber($TotalSize,-1,,-2)
Next
;Bytes Total Disk Size = $TotalSize
;Percent Used = $pctUsed
;Percent Unused = $pctFreeSpace
;Bytes Left Unused = $FreeSpace
$GetDiskFreeSpace = $TotalSize, $pctUsed, $pctFreeSpace, $FreeSpace
Exit Val('&' + Right(DecToHex(@ERROR), 4))
EndFunction
Here is a script that will read a file from the same directory the script is ran from and then will attempt to locate the shares like C$ D$ E$ etc.. ignoring the IPC$ and ADMIN$ shares. It too could use some updating to the code as it is quite old and was designed for some other stuff as well at the time.
Break On
Dim $SO,$Server,$Servers,$ValidSystem,$Share,$Item,$HS,$x,$File,$Report,$sComputer,$Send,$Results,$Results1,$Results2
Dim $Results3,$NB,$Arp,$Status
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$Servers=ReadFile(@ScriptDir+'\servers.txt')
$File = @ScriptDir+'\ServerDiskSpace.txt'
If Exist($File)
Del $File
EndIf
$Report = RedirectOutput($File,1)
For Each $sComputer In $Servers
If $sComputer
$Send=0
$Results=Join(wshpipe('ping '+$sComputer+' -n 1',1),@CRLF)
If UBound(Split($sComputer,'.'))=3 ;IP was supplied from list
$NB='IP'
$Arp=0
$Results1=Trim(Split(Split(Split($Results,":")[4],"Received = ")[1],", Lost")[0])
Else ; NetBIOS name was supplied from list
$NB='NetBIOS'
$Arp=1
$Results1=Trim(Split(Split(Split($Results,":")[4],"Received = ")[1],", Lost")[0])
$Results2=Trim(Split(Split($Results,"[")[1],"]")[0])
$Results3=Trim(Split(Split($Results,"could")[1],"find")[0])
EndIf
If $Arp ; NetBIOS name was supplied from list
Select
Case $Results3
$Status=$sComputer+' using '+$NB+' is not in WINS-DNS'
? $Status
$Send=0
Case $Results2
If
$Results1 >0 $Status=$sComputer+' using '+$NB+' '+$Results2+' is responding to ping'
$Send=1
Else
$Status=$sComputer+' using '+$NB+' has WINS-DNS entry but is not responding.'
? $Status
$Send=0
EndIf
Case 1
$Status=$sComputer+' generated an unknown error '+ 'ERR: '+@ERROR
? $Status
$Send=0
EndSelect
Else ;IP was supplied from list
If $Results1 >0
$Status=$sComputer+' using '+$NB+' is responding to ping'
$Send=1
Else
$Status=$sComputer+' using '+$NB+' is NOT responding to ping'
? $Status
$Send=0
EndIf
EndIf
If $Send
If ConfirmWMI($sComputer)
$HS=ListHiddenShares($sComputer)
$HS=QS(Split(Join(Split($HS,CHR(42)),CHR(32)),CHR(47))) ;Sort the list using QS UDF
For $x=0 To UBound($HS)
If $x
? $sComputer + CHR(32) + $HS[$x]
EndIf
Next
EndIf
EndIf
EndIf
Next
$Report = RedirectOutput("")
Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If Not VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
If Not $NoEcho $Output Endif
$WshPipe=Split(Join(Split($Output,CHR(13)),CHR(32)),CHR(10))
Exit($oExec.ExitCode)
EndFunction
Function ListHiddenShares($sComputer)
Dim $objWMIService,$colShares,$objShare,$HiddenShare
If Not $sComputer $sComputer = @WKSTA EndIf
$sComputer = '\\' + $sComputer + '\'
$objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!" + $sComputer + "root\cimv2")
$colShares = $objWMIService.ExecQuery("Select * from Win32_Share")
For each $objShare In $colShares
If $objShare.Type = '-2147483648' And Not InStr($objShare.Name,'ADMIN$')
$HiddenShare = $HiddenShare + $objShare.Name + CHR(42) + Diskspace($sComputer+ $objShare.Name) + CHR(47)
EndIf
Next
$ListHiddenShares = $HiddenShare
EndFunction
Function Diskspace(optional $drive, optional $format)
Dim $objWMIService, $sWQL, $colDrives, $objDrive
If Not $drive
$drive='%WINDIR%'
EndIf
$format=Val($format)
If $format<5
$format=IIf($format=1,1024,IIf($format=2,1024.0*1024,IIf($format=3,1024.0*1024*1024,IIf($format=4,1024.0*1024*1024*1024,1))))
$diskspace=CDBL(GetDiskSpace($drive))/$format
Else
$objWMIService=GetObject('winmgmts:{impersonationLevel=impersonate}!\\'+@WKSTA+'\root\cimv2')
$sWQL = "SELECT Size, FreeSpace FROM Win32_LogicalDisk WHERE Name='"+Left($drive,2)+"'"
$colDrives=$objWMIService.ExecQuery($sWQL)
For Each $objDrive in $colDrives
$diskspace=CDBL($objDrive.FreeSpace)/CDBL($objDrive.Size)*100
Next
EndIf
Exit @ERROR
EndFunction
Function ConfirmWMI(Optional $sComputer)
Dim $Computer,$Namespace,$WinDir,$Target,$WMIVer,$objWMIService,$WinDrive
If Not $sComputer $sComputer = @WKSTA EndIf
$sComputer = '\\' + $sComputer + '\'
$WinDir = $sComputer+Join(Split(ReadValue($sComputer+ 'HKLM\Software\Microsoft\Windows NT\CurrentVersion', 'SystemRoot'),':'),Chr(36))
If @ERROR
Exit @ERROR
EndIf
$Target = $WinDir + '\system32\wbem\wbemdisp.dll'
If Exist($Target)
$WMIVer = Trim(GetFileVersion($Target,'BinFileVersion'))
If @ERROR
Exit @ERROR
EndIf
Else
Exit 2
EndIf
$ConfirmWMI=$WMIVer
$Namespace = "root\cimv2"
If $WMIVer
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!" + $sComputer + $Namespace)
If @ERROR
Exit Val("&"+Right(DecToHex(@ERROR),4))
Else
Exit 0
EndIf
EndIf
Exit 2
EndFunction
Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=Chr(10)
$f=FreeFileHandle
$_=Open($f,$file)
If @ERROR Exit @ERROR EndIf
Do $t=$t+$lf+ReadLine($f) Until @ERROR
$_=Close($f)
$ReadFile=Split(SubStr($t,2),$lf)
EndFunction
Function QS($a)
DIM $b[32],$c[32],$d,$e,$f,$g,$h,$i,$j,$k,$l
$b[0]=0
$c[0]=Ubound($a)
$d=0
While $d >=0
$e=$b[$d]
$f=$c[$d]
While $e < $f
$h=$e+($f-$e)/2
$k=$a[$e]
$A[$e]=$A[$h]
$A[$h]=$k
$i=$e+1
$j=$f
$l=0
Do
While ($i<$j) And $A[$e] > $A[$i]
$i=$i+1
Loop
While ($j>=$i) And $A[$j] > $A[$e]
$j=$j-1
Loop
IF $i>=$j
$l=1
Else
$k=$A[$i]
$A[$i]=$A[$j]
$A[$j]=$k
$j=$j-1
$i=$i+1
EndIf
Until $l=1
$k=$a[$e]
$a[$e]=$a[$j]
$a[$j]=$k
$g=$j
If $g-$e <= $f - $g
If $g+1 < $f
$b[$d]=$g+1
$c[$d]=$f
$d=$d+1
EndIf
$f=$g-1
Else
If $g-1 > $e
$b[$d]=$e
$c[$d]=$g-1
$d=$d+1
EndIf
$e=$g+1
EndIf
Loop
$d=$d-1
Loop
$qs=$a
EndFunction
|
Top
|
|
|
|
#183961 - 2007-12-19 08:15 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
I may have to try this one from Glenn out later on
|
Top
|
|
|
|
#183966 - 2007-12-19 08:31 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Thanks again.
I assume the kix32.exe is what "kicks" the UDF off?
So I would run it from a command prompt calling up UDF?
Thank you for tolerating my silly questions.
|
Top
|
|
|
|
#183968 - 2007-12-19 08:47 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
My goodness.....I am entering a world here that both scares and entices at the same time. The possibilities seem endless.
|
Top
|
|
|
|
#183972 - 2007-12-19 09:11 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Glenn, I am getting:
ERROR : FUNCTION without ENDFUNCTION! LINE : 174
I think I am making the mistake of treating this like a script. I used to have the kix32.exe call up a .kix file for my printers. That was the only other time I every used KiXtart.
God, you guys must hate people like me!
Edited by rcurrao (2007-12-19 09:55 PM)
|
Top
|
|
|
|
#183975 - 2007-12-19 09:56 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Where will this report turn up? I do not see anything being returned. Is there a location it is dropped in or will it just pop on the screen?
|
Top
|
|
|
|
#183976 - 2007-12-19 10:28 PM
Re: Disk Capacity/Free Space Script
[Re: rcurrao]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
OK - try this.. Here's the script AND the UDF, all in one file. 1. Copy the following script 2. Paste into Notepad 3. Edit the line between the ; ===== headers to define a computer on your network that you have access to 4. Save as "DskInfo.kix" 5. Run as KIX32.EXE DSKINFO.KIX You should get a report of each disk capacity. If you don't, check that the computer name is correct, and that you have access to the remote computer. You can verify by "DIR \\COMPUTER\C$"
The difference between this and the earlier version is that the UDF is included directly in the file, and not loaded from an external file. I prefer this method, as it assures me the script will always work without reliance on external files. My KGen tool (Part of my KixDev product) assembles finished scripts in this manner, but automatically identifies which UDFs are required. I added a simple error check - if the call to the UDF doesn't return data, I display a message and exit.
Note that this example is very basic in terms of coding - vars are not declared, and vars/macros are permitted in strings. My emphasis was on providing a usable code SAMPLE, which demonstrates the capability. It's up to you to A) apply good coding process to your finished script, and B) wrap this logic in a loop to process many computers instead of just one.
That should provide you with a decent shove in the right direction, and enough stuff to do on your own to make it a worthwhile learning experience.
Regards,
Glenn
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'
;=====================================================
; 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(' ' + $D_Capacities[$Index], 15)
Right(' ' + $D_FreeSpace[$Index], 15)
If CDbl($D_FreeSpace[$Index]) < 500000
' <Low!>'
EndIf
?
Next
; ==========================================================
; 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
|
|
|
|
#183978 - 2007-12-19 11:22 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
The very fist script I posted should work as is. Just provide it a server name. Perhaps not as fancy as Glenns
The second example includes all UDF code as well. Just create a list of servers you want to check in a file called servers.txt. It writes it all out to a ServerDiskSpace.txt file in the same folder the script is ran from.
From a DOS Console with KIX32.EXE in the folder or path.
KIX32.EXE DISKSPACE.KIX
Then open ServerDiskSpace.txt with notepad.
|
Top
|
|
|
|
#183981 - 2007-12-20 12:02 AM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Glenn thanks again. I don't think I am dropping the computer name in the proper place or maybe not using the proper syntax.
EUREKA..I got it. But I have to get it to MB's at least.
Edited by rcurrao (2007-12-20 12:13 AM)
|
Top
|
|
|
|
#183982 - 2007-12-20 12:06 AM
Re: Disk Capacity/Free Space Script
[Re: NTDOC]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
Thanks, Doc. I am trying them both. I need to establish some comfort level here.
|
Top
|
|
|
|
#183983 - 2007-12-20 01:22 AM
Re: Disk Capacity/Free Space Script
[Re: rcurrao]
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
Loc: CA
|
No problem. Either one should work for you.
Glenn has some nice code and documents it better than most of us
|
Top
|
|
|
|
#183988 - 2007-12-20 02:27 AM
Re: Disk Capacity/Free Space Script
[Re: rcurrao]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Change the RED part to a valid computer name on your network!
;===================================================== ; Define the name of your test computer ; (later, enumerate a list of computers in a loop) $Computer = ' COMPUTER' ;=====================================================
Once it works, and you configure the results the way you like, you can put the code below the $Computer= line, and up to the beginning of the UDF definition into a loop to process multiple computers. Obviously, delete or comment out the $Computer= part when you get to this point.
Try something like this to read a list of computer names from NAMES.TXT:
If Open(3, "NAMES.TXT") = 1
$Computer = ReadLine(3)
While Not @ERROR
; reporting code goes here...
$Computer = ReadLine(3)
Loop
$ = Close(3)
EndIf
Again, this is example code, not polished, prim, and proper. This example writes the data to the screen, but you can simply add a RedirectOutput('DiskReport.txt') to the beginning of the script. Don't forget to close the redirect with RedirectOutput(''), and capture the return values with $RC = in front of each RedirectOutput call. You'll probably want to delete or rename the output file first, since it will simply append the output to any existing file.
You need MBytes - the disk values are in bytes, and are STRINGS!! You need to divide by 1024 to get KBytes, or 1048576.0 to get MBytes. You're dealing with large values - above 32768, so should convert to doubles first - like this: Right(' ' + CDbl($D_Capacities[$Index]) / 1048576.0, 15)
This converts the value to a double, divides it by 1 meg (as a double), converts the whole mess back to a string by prepending it with spaces, then trims the rightmost 15 characters. Phew! Might be easier to do this one step at a time till you get the hang of it.
Glenn
PS
Post your code if you get in a jam - I'd rather keep nudging you in the right direction till you understand it than hand you finished code. It's the teacher in me...
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#184027 - 2007-12-20 03:55 PM
Re: Disk Capacity/Free Space Script
[Re: Glenn Barnas]
|
rcurrao
Fresh Scripter
Registered: 2005-09-13
Posts: 21
|
I was able to enumerate the computers, and have results returned to me!!
Regarding the conversion of bytes into Mbytes, can that conversion code be placed into this? And where?
HOLY SCHNEYEKEYS!! I got it!
Edited by rcurrao (2007-12-20 04:56 PM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|