#154181 - 2005-12-28 05:23 PM
Help with Output from For Each Loop
|
jwmac
Fresh Scripter
Registered: 2005-12-22
Posts: 5
|
First quick question, Is there a way to prevent the script code results from being displayed in output whether it be on screen or in a file? My srcript below dumps output to files just fine but the output in the file is always followed by a "0" at the end. Is there a way to prevent this?
Now to my main question. I have written a simple inventory script and as of right now everything is working great but I have overlooked an issue with the Harddrive query through WMI. As you can see in the script below I have a FOR EACH loop grabbing hard drive info but the way I have my output set up the last drive is the only one being sent to output.
With an early version of this script, I was printing output within the FOR EACH loop after each varible which worked fine. Now Im guessing I will need a counter which would create a new variable each time through the loop(ie. $Var+1,Var+2,...) but I'm not quite sure how to do so.
Any help is appreciated and FYI, I am experimenting and searching with ways to do this, and not just coming here for a cheap, quick, lazy answer although my first question was kind of lazy. Thanks
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..."
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") If @error <> 0 Goto Error Else Endif
? @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") If @error <> 0 Goto Error Else Endif ? "**********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! Thank You!" sleep 2 :end exit
:Error cls ? "Share currently unavailable." Sleep 2 exit
|
Top
|
|
|
|
#154182 - 2005-12-28 05:26 PM
Re: Help with Output from For Each Loop
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
$nul =WRITEVALUE(...) will supress the 0's
There is a FAQ on this
|
Top
|
|
|
|
#154187 - 2006-01-01 07:30 PM
Re: Help with Output from For Each Loop
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Instead of re-inventing the wheel with WMI, why not use WMIQuery()?
Kent
|
Top
|
|
|
|
#154188 - 2006-01-04 04:43 PM
Re: Help with Output from For Each Loop
|
jwmac
Fresh Scripter
Registered: 2005-12-22
Posts: 5
|
thanks to all for helping my newbie self. much apprieciated!
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1169 anonymous users online.
|
|
|