Login with Facebook
Showing posts with label WMI. Show all posts
Showing posts with label WMI. Show all posts

Monday, March 28, 2011

OMW: List files on folder that didn’t modified within 30 minutes Part 2

 

nodeName = "."
Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
dateTime.SetVarDate( DateAdd("n",-30,now()))
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & nodeName & "\root\cimv2")
Set colFiles = _
objWMIService.ExecQuery("Select * From CIM_DataFile Where Drive = 'C:' and Path = '\\Scripts\\' ")
'Wscript.Echo colFiles.Count 'echo number of files
For Each objFile in colFiles
IF objFile.LastModified < dateTime.Value Then
strNewFile = objFile.FileName & "." & objFile.Extension & " File last modified : " & objFile.LastModified
Wscript.Echo strNewFile
END IF
next


This script is for displaying files that are last modified date is older than 30 minutes


Here is the script breakdown with explanation


I tried to get the current time using Now() function then I deducted the time by using DateAdd() and used a native value


I called the files using WMI class  CIM_DataFile and I defined the file location through Where clause to filter the files that are located in drive C: and located under folder named \Scripts


objWMIService.ExecQuery("Select * From CIM_DataFile Where Drive = 'C:' and Path = '\\Scripts\\' ")


The problem that the time stored in WMI object is different that the time value used in VB script function like now() like the below


VB Time is 03/28/2011 9:42:03 PM


WMI Time is 20110328214201.225172+240


I have used WbemScripting.SWbemDateTime class to convert the date to WMI date


Set dateTime = CreateObject("WbemScripting.SWbemDateTime")

Then I converted the value received using a function named SetVarDate()


dateTime.SetVarDate( DateAdd("n",-30,now()))


I tried to compare it within the WMI query and failed so I compare it using if statement


If objFile.LastModified < dateTime.Value then
Wscript.Echo strNewFile

Thursday, March 24, 2011

OMW: Modify the Heartbeat settings for Managed Node

Recently I decided to post my replies in HP Support Forum here in my blog to enrich the internet with the direct answer to the question I may also attach some screenshots..

The question was about changing Hearbeat settings for OMW Nodes..

The settings are actually located under system tab in the node properties page

I will use WMI to handle this case

So node information is located in the instances of WMI Class named ov_managednode this class contain all the node related attributes plus more methods to execute different functions

This WMI class is located under WMI namespace “root\HewlettPackard\OpenView\data”

dealing with WMI in VB scripting is quite straightforward, although the scripts may look different

The code below is simple to connect to WMI on the local machine and direct the code to the namespace mentioned above

Set objLocator = CreateObject("WbemScripting.SWbemLocator") 
Set objNode = objLocator.ConnectServer("", "root\HewlettPackard\OpenView\data", "", "")
objNode.Security_.impersonationlevel = 3





 

The next section is to find the node where we want to modify in list of Instance of the ov_managedNode class so as long as we may use the full node name there is attribute contain this data called primarynodename so we will use a WQL to locate node(s) matches our select criteria and we will execute the query by objNode.ExecQuery() function


msgQuery = "Select * from ov_managednode where primarynodename = """ & nodeName & """" 
objNodeList = objNode.ExecQuery(msgQuery)


but in the query about you may notice nodeName which is a variable  where you my add it as argument while executing the script where we defined the nodeName as the 1st argument identified as Item(0)


argsObj = WScript.Arguments 
nodeName = argsObj.Item(0)


 


And finally to change the value of any attribute  you need to locate the attribute name and its possible values and use .put to write your changes.


Tuesday, September 28, 2010

How to use WBEMTEST to get WMI data level 2

I got anonymous reader comment on continuing the series for how to use WBEMTEST to get WMI data

In this article I will add two points to cover in this fabulous tool

1- Connect to remote node

2- Run WQL queries.

 

Connect to remote node

usually we use wbemtest locally to access local classes, but WMI support access to remote computers naturally and for applications like PowerShell version 1 which support local scripting, it uses WMI to expand its functionality and to allow PowerShell access to remote computers.

Anyhow, we can use WBEMTEST utility to achieve this by using the connect button located on the main screen, we usually use root\ to locate our local classes like ROOT\MicrosoftIISv2 to get the status for website hosted on IIS server

but if the IIS is not hosted on my local machine I can query this server by adding \\servername\ROOT\MicrosoftIISv2 so it will look like “unified naming convention” UNC same like the one used for Windows file sharing, also you can use Credentials section to access the remote system with different account.

image

 

Run WQL query to retrieve data from WMI classes.

WMI supports a subset of Structured Query Language that support WMI event and WMI-Specific features which we can use to filter the content of the data (instances) within a class like select certain attributes or limit the number of instance.

My 1st encounter  to WQL was in Windows Server 2003 group policy where you can filter the group policy application to only certain set of computers based on certain attributes like OS version and Service Pack or disk free space.

In our tool we can use Query button to write our query

image

Press Apply to get the result

image

You can try to use

Select * from Win32_LogicalDisk where FreeSpace > 104857600

To list only drives where is have diskspace more than 100 MB

for more statements check http://technet.microsoft.com/en-us/library/cc779036(WS.10).aspx

Friday, February 5, 2010

How to use WBEMTEST to get WMI data level 1

Launch wbemtest from command prompet or RUN

image

Here is the interface

image

to locate WMI classes attributes or instances you have to connect with account with sufficient privilege (note: all users has privilege to WMI but depend of type of action you want to execute which may require administrator priv.)

press on connect then type which namespace you want to connect to: by default Windows (Win32_*)built-in classes almost located under root\cimv2 then click connect.

This will connect you with the current user account, you may specify another account to gain more privilege

image

This is the screen after connection.

image

If you know certain class you can click on Open Class

If you do not know and you want to search manually you may click Enum Classes

To get all the classes you may select Recursive and press OK

image

A full list of classes will be displayed as below

image

Browse to any class and double click

for example User Account on the local machine are under Win32_UserAccount class

 image

Click on Instances to list all the instances

image

Here is the list of User Account

image

 

To be continued.

please remind me to continue it.