Page 1 of 1 1
Topic Options
#153927 - 2005-12-22 06:58 PM Help with arithmatic operations using variables
jwmac Offline
Fresh Scripter

Registered: 2005-12-22
Posts: 5
I have an inventory script I have put together which pulls the hard drive freespace and total space from WMI. The retrieved sizes are represented in bytes but I want them to be displayed as Gigs in my log files.

I have tried dividing the variable for these sizes but always get an error in expression.

For example:
$DiskSet = GetObject($WMI).ExecQuery("SELECT * FROM WIN32_LOGICALDISK WHERE DriveType=3")

For Each $Disk in $DiskSet
$FreeSpace = $Disk.FreeSpace
$TotalSpace = $Disk.Size
Next

$sizeingigs =$totalspace / 1,073,741,824
? $sizeingigs

This doesnt work and Im sure theres a simple explanation. Also if this would work or once I get something to work, what would be the easiest way to round the product from xx.xxxxxx to xx.x?
I'm relatively new to scripting so be kind.
thanks

Top
#153928 - 2005-12-22 07:11 PM Re: Help with arithmatic operations using variables
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Hopefully this gets you a little closer to what your looking for:

Code:

break on

$WMI = GetObject("winmgmts:\\"+@WKSTA+"\root\cimv2")

$DiskSet = $WMI.ExecQuery("SELECT * FROM WIN32_LOGICALDISK WHERE DriveType=3")

$TotalSpace = 0.0
$FreeSpace = 0.0

For Each $Disk in $DiskSet
$FreeSpace = $FreeSpace + $Disk.FreeSpace
$TotalSpace = $TotalSpace + $Disk.Size
Next

$sizeingigs = $totalspace / 1073741824

? $sizeingigs


Top
#153929 - 2005-12-22 07:50 PM Re: Help with arithmatic operations using variables
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Hello jwmac and welcome to the board.

If you take a look around in our UDF forum or on one of the mirror sites you should be able to find plenty examples of methods of detecting sizes and getting the values you want.

Please take a look here.
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=126821

Top
#153930 - 2005-12-22 07:50 PM Re: Help with arithmatic operations using variables
jwmac Offline
Fresh Scripter

Registered: 2005-12-22
Posts: 5
Thats Perfect! Brilliant! I new there would be a simple solution. Thank you.
I also have the round command down now so I'm good to go til next week. I have several more questions.

thanks again

My script so far(cramped because of cut and paste):
Quote:

break on

$InvCheck = READVALUE ("HKEY_LOCAL_MACHINE\HARDWARE\IT Inventory", "Stamp")
If $InvCheck = 1
Goto End
Else
cls

? "Performing an inventory of this computer... please wait..."
? " Thank you!"
sleep 2

$WMI = "WINMGMTS:{IMPERSONATIONLEVEL=IMPERSONATE}!//@WKSTA"
$ComputerModel = GetObject($WMI).ExecQuery("Select * FROM Win32_ComputerSystem")
$FindBIOSInfo = GetObject($WMI).ExecQuery("Select * FROM Win32_BIOS")
$DiskSet = GetObject($WMI).ExecQuery("SELECT * FROM WIN32_LOGICALDISK WHERE DriveType=3")
$mem = memorysize(0)
$netinfoip = ENUMIPINFO (0, 0, 1)
$netinfonic = ENUMIPINFO (0, 2, 1)

For Each $model in $ComputerModel
$CompModel = $model.model
Next

For Each $tag in $FindBIOSInfo
$servicetag = $tag.SerialNumber
Next

$TotalSpace = 0.0
$FreeSpace = 0.0

For Each $Disk in $DiskSet
$DriveName = $Disk.Name
$FreeSpace = $FreeSpace + $Disk.FreeSpace
$TotalSpace = $TotalSpace + $Disk.Size
$Format = $Disk.FileSystem
Next


$TotalSpaceGigs = $totalspace / 1073741824
$FreeSpaceGigs = $FreeSpace / 1073741824

REDIRECTOUTPUT ("@LServer\inventory$\inventory.csv")

? @Date", "@Time", "@Site", "@LServer", "@WKsta", "$Servicetag", "@WUserID", "@Producttype", "@CSD", "@CPU", "@MHz", "$mem", "$DriveName", "Round ($FreeSpaceGigs,1)", "Round ($TotalSpaceGigs,1)", "$Format", "$netinfoip", "@Address", "$netinfonic

REDIRECTOUTPUT ("@LServer\inventory$\inventory.log")
? "**********Computer: "+@WKsta"**Site: "+@Site"*************"
? @Date
? @Time
? @Site
? @LServer ;logon server
? @WKsta
? $CompModel
? $Servicetag
? @WUserID ;username
? @Producttype" w/ "@CSD
? @CPU
? @MHz"MHz"
? $mem"MB"
? $DriveName
? Round ($FreeSpaceGigs,1)
? Round ($TotalSpaceGigs,1)
? $Format
? $netinfoip
? @Address
? $netinfonic
?
$WMI = 0

WRITEVALUE ("HKEY_LOCAL_MACHINE\HARDWARE\IT Inventory", "Stamp", "1", "REG_SZ")
WRITEVALUE ("HKEY_LOCAL_MACHINE\HARDWARE\IT Inventory", "Date", "@Date", "REG_SZ")

Redirectoutput ("")
cls
? "Inventory Complete!"
sleep 2
:end
exit



Top
#153931 - 2005-12-22 07:53 PM Re: Help with arithmatic operations using variables
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
jwmac

Just an FYI - using the CODE TAGS instead of QUOTE will preserve your formatting better.

Top
#153932 - 2005-12-22 08:11 PM Re: Help with arithmatic operations using variables
jwmac Offline
Fresh Scripter

Registered: 2005-12-22
Posts: 5
Quote:

jwmac

Just an FYI - using the CODE TAGS instead of QUOTE will preserve your formatting better.




thanks for the tip
Code:
 break on

$InvCheck = READVALUE ("HKEY_LOCAL_MACHINE\HARDWARE\IT Inventory", "Stamp")
If $InvCheck = 1
Goto End
Else
cls

? "Performing an inventory of this computer... please wait..."
? " Thank you!"
sleep 2

$WMI = "WINMGMTS:{IMPERSONATIONLEVEL=IMPERSONATE}!//@WKSTA"
$ComputerModel = GetObject($WMI).ExecQuery("Select * FROM Win32_ComputerSystem")
$FindBIOSInfo = GetObject($WMI).ExecQuery("Select * FROM Win32_BIOS")
$DiskSet = GetObject($WMI).ExecQuery("SELECT * FROM WIN32_LOGICALDISK WHERE DriveType=3")
$mem = memorysize(0)
$netinfoip = ENUMIPINFO (0, 0, 1)
$netinfonic = ENUMIPINFO (0, 2, 1)

For Each $model in $ComputerModel
$CompModel = $model.model
Next

For Each $tag in $FindBIOSInfo
$servicetag = $tag.SerialNumber
Next

$TotalSpace = 0.0
$FreeSpace = 0.0

For Each $Disk in $DiskSet
$DriveName = $Disk.Name
$FreeSpace = $FreeSpace + $Disk.FreeSpace
$TotalSpace = $TotalSpace + $Disk.Size
$Format = $Disk.FileSystem
Next


$TotalSpaceGigs = $totalspace / 1073741824
$FreeSpaceGigs = $FreeSpace / 1073741824

REDIRECTOUTPUT ("@LServer\inventory$\inventory.csv")


? @Date", "@Time", "@Site", "@LServer", "@WKsta", "$Servicetag", "@WUserID"
, "@Producttype", "@CSD", "@CPU", "@MHz", "$mem", "$DriveName",
"Round ($FreeSpaceGigs,1)", "Round ($TotalSpaceGigs,1)", "$Format",
"$netinfoip", "@Address", "$netinfonic

REDIRECTOUTPUT ("@LServer\inventory$\inventory.log")
? "**********Computer: "+@WKsta"**Site: "+@Site"*************"
? @Date
? @Time
? @Site
? @LServer ;logon server
? @WKsta
? $CompModel
? $Servicetag
? @WUserID ;username
? @Producttype" w/ "@CSD
? @CPU
? @MHz"MHz"
? $mem"MB"
? $DriveName
? Round ($FreeSpaceGigs,1)
? Round ($TotalSpaceGigs,1)
? $Format
? $netinfoip
? @Address
? $netinfonic
?
$WMI = 0

WRITEVALUE ("HKEY_LOCAL_MACHINE\HARDWARE\IT Inventory", "Stamp", "1", "REG_SZ")
WRITEVALUE ("HKEY_LOCAL_MACHINE\HARDWARE\IT Inventory", "Date", "@Date", "REG_SZ")

Redirectoutput ("")
cls
? "Inventory Complete!"
sleep 2
:end
exit



Edited by jwmac (2005-12-22 09:12 PM)

Top
#153933 - 2005-12-22 08:27 PM Re: Help with arithmatic operations using variables
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Please edit your post and break the long line here

? @Date", "@Time", "@Site", "@LServer", "@WKsta",

Having long lines like that make it difficult to read and use the board.

Thanks.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 525 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.065 seconds in which 0.033 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org