This is a basic script for retrieving hard disk information of multiple systems. Input for this script would be a Text file which will then retrieve Hard disk information of the computer. Output will be saved to a text file in C drive c:\Output.txt
VBSCRIPT:
on error resume next
Const FOR_READING = 1
DIM strComputers, objwmiservice, objfile, objFSO, arrComputers
DIM colItems, fsoObject, open_file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\input.txt", FOR_READING)
strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)
For Each strComputers In arrComputers
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputers & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType=3" )
Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")
Set open_file = fsoObject.OpenTextFile("c:\output.txt", 8 , "True")
For Each objItem In colItems
open_file.WriteLine ("SystemName: " & vbtab & objItem.systemName)
open_file.WriteLine ("System Drive: " & vbtab & objItem.Name)
open_file.WriteLine ("FileSystem: " & vbtab & objItem.FileSystem)
open_file.WriteLine ("FileSize: " & vbtab & (objItem.Size)/1073741824) & " GB"
open_file.WriteLine ("FreeSpace: " & vbtab & (objItem.FreeSpace)/1073741824) & " GB"
open_file.WriteLine ("FreeSpace % : " & vbtab & INT((objItem.FreeSpace / objItem.Size) * 1000)/10 )
open_file.WriteLine ("***********************************")
open_file.WriteLine (" ")
Next
open_file.Close()
Next
OUTPUT: This is your Output saved to your Text file
VBSCRIPT:
on error resume next
Const FOR_READING = 1
DIM strComputers, objwmiservice, objfile, objFSO, arrComputers
DIM colItems, fsoObject, open_file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\input.txt", FOR_READING)
strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)
For Each strComputers In arrComputers
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputers & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE DriveType=3" )
Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")
Set open_file = fsoObject.OpenTextFile("c:\output.txt", 8 , "True")
For Each objItem In colItems
open_file.WriteLine ("SystemName: " & vbtab & objItem.systemName)
open_file.WriteLine ("System Drive: " & vbtab & objItem.Name)
open_file.WriteLine ("FileSystem: " & vbtab & objItem.FileSystem)
open_file.WriteLine ("FileSize: " & vbtab & (objItem.Size)/1073741824) & " GB"
open_file.WriteLine ("FreeSpace: " & vbtab & (objItem.FreeSpace)/1073741824) & " GB"
open_file.WriteLine ("FreeSpace % : " & vbtab & INT((objItem.FreeSpace / objItem.Size) * 1000)/10 )
open_file.WriteLine ("***********************************")
open_file.WriteLine (" ")
Next
open_file.Close()
Next
OUTPUT: This is your Output saved to your Text file
No comments:
Post a Comment