Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Get all the machines volume label names to a file

Hi,

I want to get all the volume label names to a file.I have all the machine names in a txt file.Need a script to scan the machines and get all the drives label names.

Machinename   C: Labelname   D:  Labelname and so on.

Regards
Sharath
Avatar of Hitesh Manglani
Hitesh Manglani
Flag of India image

Avatar of Gastone Canali
'
' get-HD-label-all-PCs.vbs
' read the computer computers list from the file c:\computers.txt
' for get output on file run:
'
' cscript //nologo get-HD-label-all-PCs.vbs >result.txt
'
' Gastone Canali
'
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Computers.txt", ForReading)
do while not objFile.AtEndOfStream
    PC = objFile.ReadLine
    Gethdinfo (PC)
loop
objFile.Close
sub Gethdinfo(strComputer)
  getinfo=""
  On Error Resume Next
  Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/CIMV2" )
  Set colInstances = objWMIService.ExecQuery( "SELECT * FROM Win32_LogicalDisk where driveType=3",  "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly )
  If Err.Number = 0 then
    For Each objInstance In colInstances
          getinfo=getinfo & " " & objInstance.deviceID &" " & objInstance.volumename  
    Next
  else
    getinfo="Error computer not found"
    err.clear
  end if
  WScript.echo strComputer & space(10-len(strComputer)) &": " & getinfo
end sub
Avatar of bsharath

ASKER

I tried tha same way as mentioned.TRhe file is creating but no data in the results.txt
try only:
cscript //nologo get-HD-label-all-PCs.vbs
C:\>cscript //nologo get-HD-label-all-PCs.vbs
hydsophos :  C:  D: Data
          : Error computer not found
          : Error computer not found
          : Error computer not found
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial