Page 1 of 1 1
Topic Options
#86670 - 2002-07-11 06:14 PM WMI Function
Anonymous
Unregistered


I am trying to create a PM script for my NT servers and have no clue how to set up functions for what I need. I have located the script on Microsofts site but need a little help. Here is one of the things I am attempting to do.

code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDiskDrives = objWMIService.ExecQuery _
("Select * from win32_perfformatteddata_perfdisk_logicaldisk where Name <> '_Total'")
For each objDiskDrive in colDiskDrives
Wscript.Echo "Drive Name: " & objDiskDrive.Name
Wscript.Echo "Free Space: " & objDiskDrive.FreeMegabytes
Next


This checks for free space on the HD. Thanks for the help.

Jural

Top
#86671 - 2002-07-11 06:28 PM Re: WMI Function
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
The quicky conversion yields:

break on

$strComputer = "."

$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\$strComputer\root\cimv2")

$colDiskDrives = $objWMIService.ExecQuery("Select * from win32_perfformatteddata_perfdisk_logicaldisk where Name <> '_Total'")

For each $objDiskDrive in $colDiskDrives
 ?"Drive Name: " $objDiskDrive.Name
 ?"Free Space: " $objDiskDrive.FreeMegabytes
Next

Exit 1


-Shawn

[ 11 July 2002, 18:29: Message edited by: Shawn ]

Top
#86672 - 2002-07-11 10:36 PM Re: WMI Function
Anonymous
Unregistered


Can you tell me why this code isn't working?
code:
$strComputer = "."
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\$strComputer\root\cimv2")

$colDisks = $objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = " $HARD_DISK $ "")
For Each $objDisk in $colDisks
?"DeviceID: "$vbTab $objDisk.DeviceID
?"Free Disk Space: "$vbTab $objDisk.FreeSpace



Exit 1

Thanks for all of the help on ALL of my problems. This board has definitely been a HUGE help to me.

Jural

Top
#86673 - 2002-07-12 04:46 AM Re: WMI Function
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
My WMI SDK is at work, but this line looks suspious to me...

code:
$colDisks = $objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = " $HARD_DISK $ "")

This seems to work a little better...
code:
$strComputer = "."
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$strComputer+"\root\cimv2")
$DiskSet = $objWMIService.ExecQuery("select * from Win32_LogicalDisk where DriveType=3")

For each $Disk in $DiskSet
? " Disk Name: "+$Disk.Name
? " Disk Space: "+$Disk.Size
? "Disk Freespace: "+$Disk.FreeSpace ?
Next

Also, I'm unsure about the: $ "" business you had at the end of the query. For a query like that, if you are using a variable at the end quotes are unnecessary.

Top
#86674 - 2002-07-12 08:29 AM Re: WMI Function
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
FYI Your code worked fine for me Chris - From web sources....

All information returned in the Win32_LogicalDisk class (note that some systems may not return information in all class properties):

uint16 Access
uint16 Availability
uint64 BlockSize
string Caption
boolean Compressed
uint32 ConfigManagerErrorCode
boolean ConfigManagerUserConfig
string CreationClassName
string Description
string DeviceID
uint32 DriveType
boolean ErrorCleared
string ErrorDescription
string ErrorMethodology
string FileSystem
uint64 FreeSpace
datetime InstallDate
uint32 LastErrorCode
uint32 MaximumComponentLength
uint32 MediaType
string Name
uint64 NumberOfBlocks
string PNPDeviceID
uint16 PowerManagementCapabilities[]
boolean PowerManagementSupported
string ProviderName
string Purpose
boolean QuotasDisabled
boolean QuotasIncomplete
boolean QuotasRebuilding
uint64 Size
string Status
uint16 StatusInfo
boolean SupportsDiskQuotas
boolean SupportsFileBasedCompression
string SystemCreationClassName
string SystemName
boolean VolumeDirty
string VolumeName
string VolumeSerialNumber

Top
#86675 - 2002-07-12 03:18 PM Re: WMI Function
Anonymous
Unregistered


How would I change the code to include all existing drives on the machine?(Physical)
BTW the code worked perfect. When I have completed the PM script I will post for all.

Jural

Top
#86676 - 2002-07-12 03:47 PM Re: WMI Function
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
You could write a query for each .DriveType you want to query. Or, you could query all LogicalDisk(s) and 'filter' your results.

code:
$strComputer = "."
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$strComputer+"\root\cimv2")
$DiskSet = $objWMIService.ExecQuery("select * from Win32_LogicalDisk")

For each $Disk in $DiskSet
? " Disk Name: "+$Disk.Name
? " Disk Space: "+$Disk.Size
? "Disk Freespace: "+$Disk.FreeSpace
Select
Case $Disk.DriveType=0
? " Disk Type: Unknown"
Case $Disk.DriveType=1
? " Disk Type: No Root Directory"
Case $Disk.DriveType=2
? " Disk Type: Removable Disk"
Case $Disk.DriveType=3
? " Disk Type: Local Disk"
Case $Disk.DriveType=4
? " Disk Type: Network Drive"
Case $Disk.DriveType=5
? " Disk Type: Compact Disc"
Case $Disk.DriveType=6
? " Disk Type: RAM Disk"
Case 1 ; Case 1 added as a 'best practice' although its not bloody likely to ever happen as 'Unknown' is already an option.
? " Disk Type: Undeterminable"
Endselect
?
Next



[ 12 July 2002, 15:51: Message edited by: Chris S. ]

Top
#86677 - 2002-07-12 04:01 PM Re: WMI Function
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here is how to format the query to just look for 'physical' disks...

code:
$strComputer = "."
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$strComputer+"\root\cimv2")
$DiskSet = $objWMIService.ExecQuery("select * from Win32_LogicalDisk where DriveType=2 or DriveType=3 or DriveType=5 or DriveType=6")

For each $Disk in $DiskSet
? " Disk Name: "+$Disk.Name
? " Disk Space: "+$Disk.Size
? "Disk Freespace: "+$Disk.FreeSpace
Select
Case $Disk.DriveType=0
? " Disk Type: Unknown"
Case $Disk.DriveType=1
? " Disk Type: No Root Directory"
Case $Disk.DriveType=2
? " Disk Type: Removable Disk"
Case $Disk.DriveType=3
? " Disk Type: Local Disk"
Case $Disk.DriveType=4
? " Disk Type: Network Drive"
Case $Disk.DriveType=5
? " Disk Type: Compact Disc"
Case $Disk.DriveType=6
? " Disk Type: RAM Disk"
Case 1
? " Disk Type: Undeterminable"
Endselect
?
Next


Top
#86678 - 2002-07-12 05:49 PM Re: WMI Function
Anonymous
Unregistered


WORKS GREAT!! Now one more question. I have all of teh info going to the DOS window, which is fine for testing. I want to get the infor into $VAR to send to file.

example
code:
$strComputer = "."
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\$strComputer\root\cimv2")

$colDisks = $objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
For each $objDisk in $colDisks

?"Description: " $vbTab $objDisk.Description
?"DeviceID: " $vbTab $objDisk.DeviceID
?"FileSystem: " $vbTab $objDisk.FileSystem
?"FreeSpace: " $vbTab $objDisk.FreeSpace
?"MediaType: " $vbTab $objDisk.MediaType
?"Name: " $vbTab $objDisk.Name
?"Size: " $vbTab $objDisk.Size

next

How do I get the info in $vbTab $VAR into a $var I can use to put into a file? Probably a simple answer but as you can tell I have never played with this before. Thanks for all of the help.

Jural

Top
#86679 - 2002-07-12 06:04 PM Re: WMI Function
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
$objDisk.Size is a variable. No need to put it into another var. Look up WRITELINE, REDIRECTOUTPUT, WRITEPROFILESTRINMG in the manual.
_________________________
There are two types of vessels, submarines and targets.

Top
#86680 - 2002-07-12 06:30 PM Re: WMI Function
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I'm gonna assume you 'borrowed' your script from a VBScript example. vbTab is not used in KiXtart. You can simply insert a 'tab' inside your quotes to tab over. It can also be used as a delimiter, for import into Excel, for example.

You can always 'assign' a tab to your $vbTab if you want...

code:
$vbTab = "	"

Also, I should warn you to use "+" when joining your output. Example...
code:
? "Size: " + $vbTab + $objDisk.Size

This is considered 'best practice.'

Top
#86681 - 2002-07-12 11:29 PM Re: WMI Function
Anonymous
Unregistered


I see were the problem is. Trouble with QUOTES again also. Fixed now.
I see how to get the processes on the server but is there a way to retrieve only the top five processes. I can't find how to do it with VB either. I can only retriev all of the processes.

Jural

[ 15 July 2002, 15:52: Message edited by: Jural ]

Top
#86682 - 2002-07-13 03:52 AM Re: WMI Function
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
What do you consider the top 5 processes? Are you talking about running time? CPU utilization? Not sure I understand the question.
Top
#86683 - 2002-07-15 03:19 PM Re: WMI Function
Anonymous
Unregistered


CPU utilization. I just need to know which are using the most processor resources at the time the PM was run.

Jural

Top
#86684 - 2002-07-15 07:28 PM Re: WMI Function
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
look up the DriveEnum() and DriveProp() UDFs to get the drive(s) properties.

top 5 processes may not be a reliable method, as Kix32, winmgmt, winlogon, explorer, and cmd will probably grab the top spots during logon.

You may just want to use FindProc() to look for the processess you are searching for.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86685 - 2002-07-15 07:45 PM Re: WMI Function
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Here we go again. This may be the last bit of help from me. Seems I'm writing your script for you. With a solid understanding of KiX and some reading in the WMI SDK, you should be able to do this yourself.

Here are the basics, I think, of what you're trying to get out of the processes list...

code:
$strComputer = "."
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$strComputer+"\root\cimv2")
$Processes = $objWMIService.ExecQuery("select * from win32_process")
for each $Process in $Processes
? " Caption: "+$Process.Caption ;Caption of process
? " Threads: "+$Process.ThreadCount ;Number of active threads
? " PageFileUsage: "+$Process.PageFileUsage ;Page File Space used by process (in KBs)
? "KernelModeTime: "+$Process.KernelModeTime ;Time in kernel mode, in 100 nanosecond units
?
next


Top
#86686 - 2002-07-15 08:49 PM Re: WMI Function
Anonymous
Unregistered


Chris,

Thanks for the LAST BIT OF HELP. Trust me, you didn't write my script for me. I just needed some help. Next time avoid the add reply button if your patience are wearing thin. Sorry to inconvenience you.

Jural

Top
#86687 - 2002-07-15 08:56 PM Re: WMI Function
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
But anyways..... Chris, if you're available now, I have some scripts you can write for me. [Big Grin]
Top
#86688 - 2002-07-15 09:03 PM Re: WMI Function
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
You're right, my patience is wearing thin. Sorry to take a bad day out on you. You asked a question that I wasn't obligated to answer.
Top
Page 1 of 1 1


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

Who's Online
0 registered and 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.077 seconds in which 0.035 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