Anybody done any programming using WMI??
#1
Scooby Regular
Thread Starter
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like
on
1 Post
Hi,
Has anybody done any programming using vbs and wmi???
I can query the local machine but if I try and do a remote machine it goes pear shaped... both machines are w2k. I think it may just be something simple that I have missed....
I am trying to connect to a remote machine and then depending on the disk type (fixed) return the size and space that is free..
would submit my code, but I am at home now and cant be bothered dialing in to work.
David.
Has anybody done any programming using vbs and wmi???
I can query the local machine but if I try and do a remote machine it goes pear shaped... both machines are w2k. I think it may just be something simple that I have missed....
I am trying to connect to a remote machine and then depending on the disk type (fixed) return the size and space that is free..
would submit my code, but I am at home now and cant be bothered dialing in to work.
David.
#3
Scooby Regular
Thread Starter
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like
on
1 Post
doh... was me being thick... forward slash instead of backslash etc..
following code now works (VBS)...
NetBiosName="David01"
Set FixedDiskS = GetObject("winmgmts:{impersonationLevel=impersonat e}!//" & NetBiosName).ExecQuery ("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3")
For Each Disk in FixedDisks
WScript.Echo "Drive " & Disk.Name & " Has " & KB(Disk.Freespace) & " Free."
Next
Function KB(Bytes)
KB = FormatNumber(Bytes/1024, 0) & " KB"
end function
In case anybody is interested it is part of a script that will query our sms (SQL) database and return a list of windows NT 4 Servers on our network, It then connects to them using WMI and works out Total Disk Size, Available Space and Used DiskSpace and then will output this to an excel spreadsheet....
David
[Edited by David_Wallis - 11/26/2001 8:14:25 PM]
as Tabs dont show up...
[Edited by David_Wallis - 11/26/2001 8:15:23 PM]
following code now works (VBS)...
NetBiosName="David01"
Set FixedDiskS = GetObject("winmgmts:{impersonationLevel=impersonat e}!//" & NetBiosName).ExecQuery ("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3")
For Each Disk in FixedDisks
WScript.Echo "Drive " & Disk.Name & " Has " & KB(Disk.Freespace) & " Free."
Next
Function KB(Bytes)
KB = FormatNumber(Bytes/1024, 0) & " KB"
end function
In case anybody is interested it is part of a script that will query our sms (SQL) database and return a list of windows NT 4 Servers on our network, It then connects to them using WMI and works out Total Disk Size, Available Space and Used DiskSpace and then will output this to an excel spreadsheet....
David
[Edited by David_Wallis - 11/26/2001 8:14:25 PM]
as Tabs dont show up...
[Edited by David_Wallis - 11/26/2001 8:15:23 PM]
#4
Scooby Regular
Thread Starter
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like
on
1 Post
Right.. Now working...
Here is code to connect to SMS site Server and Query the All windows nt servers collection and then use wmi to query the fixed disks as to what size they are and how much space is used, free etc.. do what you like with the output if you wish to use it..
David
' Script for Returning Free Disk Space on Servers.
' David Wallis 28/11/2001
' Uses WBEM / WMI / SMS
Dim WBEMLocator, ServerConnect, FindColl, FindColls, Server, Servers, SMSServer, Sitecode
' Change following two lines to match your SMS ServerName and SiteCode
' You will neeed to install wmi if not on w2k.
SMSServer="ServerName"
SiteCode="LS1"
Server="All Windows NT Server Systems"
Set WBEMLocator = CreateObject("Wbemscripting.SWbemLocator")
Set ServerConnect = WBEMLocator.ConnectServer(SMSServer, "root\sms\site_"& SiteCode)
' Convert the collection names visible in the SMS console, to the internal SMS/WMI name (SMS_CM_RES_....)
Set FindColls = ServerConnect.ExecQuery("Select Name, MemberClassName FROM SMS_Collection Where Name='" & Server & "'")
For Each FindColl in FindColls
If FindColl.Name = Server Then
ServerColl = FindColl.MemberClassName
End If
Next
Set Servers = ServerConnect.ExecQuery("Select System.ResourceID, System.NetbiosName FROM SMS_R_System AS System INNER JOIN " & ServerColl & " AS Coll ON Coll.ResourceID = System.Resourceid")
For Each Server in Servers
On Error Resume Next
' Put in a Ping Routine to check to see if the machine is on.
Set FixedDisks = GetObject("winmgmts:{impersonationLevel=impersonat e}!//" & Server.NetBiosName).ExecQuery ("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3")
For Each Disk in FixedDisks
Used = Disk.Size - Disk.FreeSpace
WScript.Echo Server.NetBiosName & " " & Disk.Name & " Size: " & KB(Disk.Size) & " Free Space: " & KB(Disk.Freespace) & " Used: " & KB(Used)
Next
Set FixedDisks = Nothing
Next
Function KB(Bytes)
KB = FormatNumber(Bytes/1024, 0) & " KB"
End Function
apollogies if the tabs dont format correctly..
Here is code to connect to SMS site Server and Query the All windows nt servers collection and then use wmi to query the fixed disks as to what size they are and how much space is used, free etc.. do what you like with the output if you wish to use it..
David
' Script for Returning Free Disk Space on Servers.
' David Wallis 28/11/2001
' Uses WBEM / WMI / SMS
Dim WBEMLocator, ServerConnect, FindColl, FindColls, Server, Servers, SMSServer, Sitecode
' Change following two lines to match your SMS ServerName and SiteCode
' You will neeed to install wmi if not on w2k.
SMSServer="ServerName"
SiteCode="LS1"
Server="All Windows NT Server Systems"
Set WBEMLocator = CreateObject("Wbemscripting.SWbemLocator")
Set ServerConnect = WBEMLocator.ConnectServer(SMSServer, "root\sms\site_"& SiteCode)
' Convert the collection names visible in the SMS console, to the internal SMS/WMI name (SMS_CM_RES_....)
Set FindColls = ServerConnect.ExecQuery("Select Name, MemberClassName FROM SMS_Collection Where Name='" & Server & "'")
For Each FindColl in FindColls
If FindColl.Name = Server Then
ServerColl = FindColl.MemberClassName
End If
Next
Set Servers = ServerConnect.ExecQuery("Select System.ResourceID, System.NetbiosName FROM SMS_R_System AS System INNER JOIN " & ServerColl & " AS Coll ON Coll.ResourceID = System.Resourceid")
For Each Server in Servers
On Error Resume Next
' Put in a Ping Routine to check to see if the machine is on.
Set FixedDisks = GetObject("winmgmts:{impersonationLevel=impersonat e}!//" & Server.NetBiosName).ExecQuery ("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3")
For Each Disk in FixedDisks
Used = Disk.Size - Disk.FreeSpace
WScript.Echo Server.NetBiosName & " " & Disk.Name & " Size: " & KB(Disk.Size) & " Free Space: " & KB(Disk.Freespace) & " Used: " & KB(Used)
Next
Set FixedDisks = Nothing
Next
Function KB(Bytes)
KB = FormatNumber(Bytes/1024, 0) & " KB"
End Function
apollogies if the tabs dont format correctly..
Thread
Thread Starter
Forum
Replies
Last Post
Steve Breen
ScoobyNet General
87
05 August 2001 05:29 PM
johnfelstead
ScoobyNet General
27
26 February 2001 05:48 PM