#178424 - 2007-07-25 09:18 PM
Todays' Hey, Scripting Guy! article...
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
Today's article on the Scripting Guy is titled... "How Can I Create a New WMI Namespace Under the Root Namespace?"
Here is the link: http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul07/hey0725.mspx
Interestingly, in the article they say at least two times "we know what you’re thinking," but to be honest I don't think they do. What I'm thinking is, what can you do with this. What's the point?
Anyone?
|
Top
|
|
|
|
#178568 - 2007-07-31 02:52 PM
Re: Todays' Hey, Scripting Guy! article...
[Re: Allen]
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Yep.
This script runs on the Exchange servers every day to keep the WhiteSpace class information up-to-date and is also collected daily via hardware inventory.
On Error Resume Next
fnCreateClass()
MaxTime = fnGetMaxTime()
Set objLocator = CreateObject("wbemscripting.swbemlocator")
Set objServices = objLocator.ConnectServer(,"root\cimv2")
objServices.Security_.Privileges.AddAsString "SeSecurityPrivilege"
Set objWhiteSpace = GetObject("Winmgmts:root\CIMV2:WhiteSpace").SpawnInstance_
Set colLoggedEvents = objServices.ExecQuery ("Select * from Win32_NTLogEvent where Logfile = 'Application' and " & _
"EventCode = '1221' and ComputerName is not null and TimeWritten > '" & MaxTime &"'")
For Each objEvent in colLoggedEvents
wscript.echo objEvent.Message
Database = Split(objEvent.Message,"""")(1)
Server = Split(Split(Database,"(")(1),")")(0)
SG = "SG" & Split(Split(Database,"Storage Group ")(1),"\")(0)
Store = Split(Split(Database,"Mailbox Store ")(1)," ")(0)
Label = Server & " " & SG & " Store" & Store
FreeSpace = Split(Split(objEvent.Message,"has ")(1)," megabytes")(0)
objWhiteSpace.ComputerName = objEvent.ComputerName
objWhiteSpace.Message = objEvent.Message
objWhiteSpace.TimeWritten = objEvent.TimeWritten
objWhiteSpace.Database = Database
objWhiteSpace.Label = Label
objWhiteSpace.FreeSpace = FreeSpace
Set objInstancePath = objWhiteSpace.Put_
Next
Set objLocator = Nothing
Set objServices = Nothing
Set objWhiteSpace = Nothing
Set colLoggedEvents = Nothing
Set objInstancePath = Nothing
Function fnCreateClass()
wbemCimtypeSint16 = 2 'Signed 16-bit integer
wbemCimtypeSint32 = 3 'Signed 32-bit integer
wbemCimtypeReal32 = 4 '32-bit real number
wbemCimtypeReal64 = 5 '64-bit real number
wbemCimtypeString = 8 'String
wbemCimtypeBoolean = 11 'Boolean value
wbemCimtypeObject = 13 'CIM object
wbemCimtypeSint8 = 16 'Signed 8-bit integer
wbemCimtypeUint8 = 17 'Unsigned 8-bit integer
wbemCimtypeUint16 = 18 'Unsigned 16-bit integer
wbemCimtypeUint32 = 19 'Unsigned 32-bit integer
wbemCimtypeSint64 = 20 'Signed 64-bit integer
wbemCimtypeUint64 = 21 'Unsigned 64-bit integer
wbemCimtypeDatetime = 101 'Date/time value
wbemCimtypeReference = 102 'Reference to a CIM object
wbemCimtypeChar16 = 103 '16-bit character
Set objSWbemService = GetObject("Winmgmts:root\CIMV2")
Set objClass = objSWbemService.Get()
objClass.Path_.Class = "WhiteSpace"
If objClass.Properties_.Count <> 6 Then
objClass.Properties_.Add "ComputerName", wbemCimtypeString
objClass.Properties_.Add "Message", wbemCimtypeString
objClass.Properties_.Add "TimeWritten", wbemCimtypeDatetime
objClass.Properties_.Add "Database", wbemCimtypeString
objClass.Properties_.Add "Label", wbemCimtypeString
objClass.Properties_.Add "Freespace", wbemCimtypeSint32
objClass.Properties_("Database").Qualifiers_.Add "key", True
End If
' Write the new class to the root\CIMV2 namespace in the repository
Set objClassPath = objClass.Put_
' wscript.echo objClassPath.Path
' Release SwbemServices object
Set objSWbemService = Nothing
End Function
Function fnDeleteClass()
Set objSWbemService = GetObject("Winmgmts:root\CIMV2")
' Remove the new class and instance from the repository
objSWbemService.Delete("WhiteSpace")
If Err <> 0 Then
WScript.Echo Err.Number & " " & Err.Description
Else
WScript.Echo "Delete succeeded"
End If
' Release SwbemServices object
Set objSWbemService = Nothing
End Function
Function fnGetMaxTime()
On Error Resume Next
Set objLocator = CreateObject("wbemscripting.swbemlocator")
Set objServices = objLocator.ConnectServer(,"root\CIMV2")
Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
dateTime.SetVarDate (CDate(DateAdd("d",-1,Date)))
MaxTimeWritten = dateTime
Set existing = objServices.ExecQuery("Select TimeWritten from WhiteSpace")
For Each inst In Existing
If MaxTimeWritten < inst.TimeWritten Then
MaxTimeWritten = inst.TimeWritten
End If
Next
fnGetMaxTime = MaxTimeWritten
End Function
Please forgive the vbscript.
|
Top
|
|
|
|
#178569 - 2007-07-31 02:57 PM
Re: Todays' Hey, Scripting Guy! article...
[Re: Chris S.]
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Here is the MOF to add to the sms_def.mof for the WIN32_Volume (needed to collect FreeSpace) and for the newly created WhiteSpace class:
//=============================================================================================================
// WIN32_Volume Information Class Created: 12/14/2006
//=============================================================================================================
[ SMS_Report (TRUE),
SMS_Group_Name ("Volume"),
SMS_Class_ID ("MICROSOFT|Volume|1.0")]
class WIN32_Volume : SMS_Class_Template
{
[SMS_Report (TRUE), SMS_Units("KiloBytes")]
uint64 Capacity;
[SMS_Report (TRUE) ]
string Caption;
[SMS_Report (TRUE) ]
boolean Compressed;
[SMS_Report (TRUE) ]
string Description;
[SMS_Report (TRUE),KEY ]
string DeviceID;
[SMS_Report (TRUE) ]
string DriveLetter;
[SMS_Report (TRUE) ]
uint32 DriveType;
[SMS_Report (TRUE) ]
string FileSystem;
[SMS_Report (TRUE), SMS_Units("KiloBytes")]
uint64 FreeSpace;
[SMS_Report (TRUE) ]
boolean IndexingEnabled;
[SMS_Report (TRUE) ]
string Label;
[SMS_Report (TRUE) ]
string Name;
[SMS_Report (TRUE) ]
string PNPDeviceID;
[SMS_Report (TRUE) ]
string SystemName;
};
// <:[-<>>>>>>>>>>>>>>>>>>>>>>>>>>>>END>>-WIN32_Volume-<<END<<<<<<<<<<<<<<<<<<<<<<<<<<>-]:>
//=============================================================================================================
// WhiteSpace Information Class Created: 01/08/2007
//=============================================================================================================
//SMS Reporting class only. WMI is created with a VB Script ()
//`'`*._.*`'`*-
// Instance of WhiteSpace
//`'`*._.*`'`*-
#pragma namespace("\\\\.\\root\\cimv2\\sms")
[ SMS_Report (TRUE),
SMS_Group_Name ("White Space"),
SMS_Class_ID ("MICROSOFT|WhiteSpace|1.0")]
class WhiteSpace : SMS_Class_Template
{
[SMS_Report (TRUE) ]
string ComputerName;
[SMS_Report (TRUE),KEY ]
string Database;
[SMS_Report (TRUE) ]
sint32 Freespace;
[SMS_Report (TRUE) ]
string Label;
[SMS_Report (TRUE) ]
string Message;
[SMS_Report (TRUE) ]
datetime TimeWritten;
};
// <:[-<>>>>>>>>>>>>>>>>>>>>>>>>>>>>END>>-WhiteSpace-<<END<<<<<<<<<<<<<<<<<<<<<<<<<<>-]:>
|
Top
|
|
|
|
#178570 - 2007-07-31 03:00 PM
Re: Todays' Hey, Scripting Guy! article...
[Re: Chris S.]
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Here is a sample report:
Free Space - Offline Defrag Candidates
Freespace is less than 12% and WhiteSpace is greater than 8GB.
Select Distinct vol.SystemName0, vol.Label0 [Volume Label],
Cast(vol.Capacity0 as money) / 1024 / 1024 [Capacity (GB)],
Cast(vol.FreeSpace0 as money) / 1024 / 1024 [FreeSpace (GB)],
Cast(wht.FreeSpace0 as money) / 1024 [WhiteSpace (GB)],
Convert(money,100.0 * vol.FreeSpace0 / vol.Capacity0) [% FreeSpace]
From v_GS_Volume vol
Left Join v_GS_WhiteSpace wht on wht.Label0 = vol.Label0
Where SystemName0 like '%ML%'
and (vol.Label0 is not null or vol.DriveLetter0 = 'C:')
and (Convert(float,100.0 * vol.FreeSpace0 / vol.Capacity0)) < 12
and wht.FreeSpace0 /1024 > 8
Order by vol.SystemName0, vol.Label0
|
Top
|
|
|
|
#178572 - 2007-07-31 03:13 PM
Re: Todays' Hey, Scripting Guy! article...
[Re: Chris S.]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
Wow... much to digest... questions coming later.
Thanks Chris...
BTW... WTF is up with the VBScript?
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 248 anonymous users online.
|
|
|