Page 1 of 1 1
Topic Options
#178424 - 2007-07-25 09:18 PM Todays' Hey, Scripting Guy! article...
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4511
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
#178426 - 2007-07-25 10:43 PM Re: Todays' Hey, Scripting Guy! article... [Re: Allen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
hmm...
if it stores the namespace in the computer, one could make an installer for his own namespace and get all the funky stuff he could ever need from there.
sadly, the article didn't dive into that though.
_________________________
!

download KiXnet

Top
#178554 - 2007-07-30 10:36 PM Re: Todays' Hey, Scripting Guy! article... [Re: Allen]
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Well, one could use the new WMI namespace and populate it with data from a script then use SMS 2003 to pull that information into the database and provide management with a report. For example providing the freespace and whitespace information for Exchange server volumes allowing the administrators to perform maintenance as needed to perform an offline defrag on the systems.

Just a theory.

Top
#178555 - 2007-07-30 11:24 PM Re: Todays' Hey, Scripting Guy! article... [Re: Chris S.]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4511
Loc: USA
Do you know how to do this?
Top
#178568 - 2007-07-31 02:52 PM Re: Todays' Hey, Scripting Guy! article... [Re: Allen]
Chris S. Offline
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.

 Code:
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. Offline
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:

 Code:
//=============================================================================================================
//                            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. Offline
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.

 Code:
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
#178571 - 2007-07-31 03:06 PM Re: Todays' Hey, Scripting Guy! article... [Re: Chris S.]
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Also, keep in mind that the Volume Labels of these drives must conform to some type of naming convention to be able to scrape the information from the Event Log.

Example: <SERVERNAME> SG2 Store 4, would be for Server X, storage group 2, mailbox store 4.

Top
#178572 - 2007-07-31 03:13 PM Re: Todays' Hey, Scripting Guy! article... [Re: Chris S.]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4511
Loc: USA
Wow... much to digest... questions coming later.

Thanks Chris...

BTW... WTF is up with the VBScript? ;\)

Top
#178573 - 2007-07-31 03:31 PM Re: Todays' Hey, Scripting Guy! article... [Re: Allen]
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
 Originally Posted By: Allen
BTW... WTF is up with the VBScript? ;\)


What can I say, I work for a large government entity and the paperwork to to do it with KiX would have felled a small forest. ;\)

Top
#178586 - 2007-07-31 08:22 PM Re: Todays' Hey, Scripting Guy! article... [Re: Chris S.]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11606
Loc: CA
Have not looked over the code but also don't forget Allen that there are some things KiX can not do well especially if you're expecting a call back in COM or items that are binary and VBS can handle them.
Top
#178599 - 2007-08-01 02:41 PM Re: Todays' Hey, Scripting Guy! article... [Re: NTDOC]
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
 Quote:
Have not looked over the code but also don't forget Allen that there are some things KiX can not do well especially if you're expecting a call back in COM or items that are binary and VBS can handle them.


Nothing like that, just that KiX isn't approved in the domain where I had to do this.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 139 anonymous users online.
Newest Members
vertage, dimi575, Drecksnacken, Nlill, webtools321
17735 Registered Users

Generated in 0.039 seconds in which 0.013 seconds were spent on a total of 13 queries. Zlib compression enabled.

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