#86670 - 2002-07-11 06:14 PM
WMI Function
|
Anonymous
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
|
|
|
|
#86672 - 2002-07-11 10:36 PM
Re: WMI Function
|
Anonymous
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.
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
|
|
|
|
#86675 - 2002-07-12 03:18 PM
Re: WMI Function
|
Anonymous
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.
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.
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
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
|
|
|
|
#86680 - 2002-07-12 06:30 PM
Re: WMI Function
|
Chris S.
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
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
|
|
|
|
#86683 - 2002-07-15 03:19 PM
Re: WMI Function
|
Anonymous
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
   
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.
|
|
Top
|
|
|
|
#86685 - 2002-07-15 07:45 PM
Re: WMI Function
|
Chris S.
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
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
   
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.
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 837 anonymous users online.
|
|
|