[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

Scan all machine to see how many drives they have

Hi,

I have a list of machines.Just need to find how many drives each machine has.
C,D,E etc
Output like this.
Machine name : C D E 3 Drives.
Regards
Sharath
0
bsharath
Asked:
bsharath
  • 4
  • 3
  • 2
1 Solution
 
RobSampsonCommented:
Hi Sharath,

Try this:
'======================
On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile("Computers.txt", 1, False)
strDetails = "Results:"
While Not objInputFile.AtEndOfStream
      strComputer = objInputFile.ReadLine
      strDetails = strDetails & VbCrLf & strComputer & ": "
      Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
      Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
      intCount = 0
      For Each objItem In colItems
            strDetails = strDetails & objItem.Caption & " "
            intCount = intCount + 1
      Next
      strDetails = strDetails & intCount & " drives"
Wend

MsgBox strDetails
'===================

Regards,

Rob.
0
 
bsharathAuthor Commented:
Thanks any way to show if it's a fdd and cdd if any found. And output the data to a file.
0
 
canaliCommented:
this is the output of the script, puclient is switched off the other two are switched on
tusrv01:  Floppy: A 1,  HardDisk: C D E F G 5,   CDrom: M 1
puclient :  Floppy: ,  HardDisk: ,   CDrom:
tusvr02:  Floppy: A 1,  HardDisk: C D E  3,   CDrom: H M 2


::get drive info
@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=#" %%c in ('type c:\computers.txt') do (
    set t=
    call:_GETDRIVE %%c Floppy: 2 2>nul
    set t=!t!,
    call:_GETDRIVE %%c HardDisk: 3  2>nul
    set t=!t!,  
    call:_GETDRIVE %%c CDrom: 5  2>nul
    echo %%c : !t!
)
goto :_END

:_GETdrive
set c=
set d=%2
 for /f "skip=1 delims=:" %%a in ('@WMIC.EXE /Node:%1 path win32_LogicalDisk where drivetype^="%3" get caption') do (
 set /a c=!c!+1
 set d=!d! %%a
)
set t=!t! %d% %c%
goto :_EOF

:_END
:_EOF
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
bsharathAuthor Commented:
Hi Canali.

For the first script i got all the 3 machines output.But for this i get results as such.

C:\>finddrives.bat
indiasophos :  Floppy: A  2,  HardDisk: C D  3,   CDrom: E  2
dev-chen-mrd100 :  Floppy: ,  HardDisk: ,   CDrom:
dev-chen-nas01 :  Floppy: ,  HardDisk: ,   CDrom:

In indiasophos (What does 2,3,2 mean.)
0
 
canaliCommented:
What does 2,3,2 mean. I removed it

::get drive info
::finddrives.cmd
@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=#" %%c in ('type c:\computers.txt') do (
    set t=
    call:_GETDRIVE %%c Floppy: 2 2>nul
    set t=!t!,
    call:_GETDRIVE %%c HardDisk: 3  2>nul
    set t=!t!,  
    call:_GETDRIVE %%c CDrom: 5  2>nul
    echo %%c : !t!
)
goto :_END

:_GETdrive
set c=
set d=%2
 for /f "skip=1 delims=:" %%a in ('@WMIC.EXE /Node:%1 path win32_LogicalDisk where drivetype^="%3" get caption') do (
 set /a c=!c!+1
 set d=!d! %%a
)
set t=!t! %d%
goto :_EOF

:_END
:_EOF

0
 
bsharathAuthor Commented:
I get this

C:\>finddrives.bat
indiasophos :  Floppy: A ,  HardDisk: C D ,   CDrom: E
dev-chen-mrd100 :  Floppy:,  HardDisk:,   CDrom:
dev-chen-nas01 :  Floppy:,  HardDisk:,   CDrom:But your 1st script is even displaying for dev-chen-mrd100 and dev-chen-nas01 machines.
0
 
canaliCommented:
Yes if machines are switched off the script display the following line:
 Floppy:,  HardDisk:,   CDrom:

0
 
bsharathAuthor Commented:
canali
The machines are on even then it shows this

How does this script work.
Even when the drive C,D,E $ share is removed will it show the output.Or will it take info from Device manager
0
 
RobSampsonCommented:
Hi Sharath,

Try this script.  It will output the drives as before, and the drive types to a file.

'=====================
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInputFile = objFSO.OpenTextFile("Computers.txt", 1, False)
strDetails = "Results:"
While Not objInputFile.AtEndOfStream
      strComputer = objInputFile.ReadLine
      boolPinged = Ping(strComputer)
      If boolPinged = True Then
            strDetails = strDetails & VbCrLf & strComputer & ": "
            Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
            Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", _
                                                wbemFlagReturnImmediately + wbemFlagForwardOnly)
            intCount = 0
            For Each objItem In colItems
                  Select Case objItem.DriveType
                        Case 1 strDriveType = "Drive could not be determined."
                        Case 2 strDriveType = "Removable Drive"
                        Case 3 strDriveType = "Local hard disk."
                        Case 4 strDriveType = "Network disk."
                        Case 5 strDriveType = "Compact disk (CD)"
                        Case 6 strDriveType = "RAM disk."
                        Case Else strDriveType = "Drive type Problem."
                  End Select
                  strDetails = strDetails & objItem.Caption & " " & strDriveType & ";"
                  intCount = intCount + 1
            Next
            strDetails = strDetails & intCount & " drives"
      End If
Wend

strOutputFile = "C:\Temp\Drives.txt"
Set objOutputFile = objFSO.CreateTextFile(strOutputFile)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing

Set objShell = CreateObject("WScript.Shell")
objShell.Run "notepad " & objFSO.GetFile(strOutputFile).ShortPath, 1, False

Set objFSO = Nothing
Set objShell = Nothing

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function
'================

Regards,

Rob.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now