• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

Find all machines which has 2 HDD in the CPU

Hi,

How can i find which all machine names which i have in a txt file have 2 or more HDD's.
I have installed an additional Hardisk on 5 computers and now i dont know the machine names.Is there a way to scan all machines which has 2 drives.

Regards
Sharath
0
bsharath
Asked:
bsharath
  • 7
  • 5
1 Solution
 
SysExpertCommented:
DO you know if they have a certain drive letter that other machines will not have ?

Using a batch file , WMI or other scripts it should be easy enough to figure this out.

I would cross post in the MSDOS TA.

I hope this helps !
0
 
RobSampsonCommented:
Sharath, try this VBS script:
'===============
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const intForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFile = "computers.txt"
Set objInputFile = objFSO.OpenTextFile(strFile, intForReading)
strComputers = objInputFile.ReadAll
objInputFile.Close
Set objInputFile = Nothing
arrComputers = Split(strComputers, VbCrLf)

For Each strComputer In arrComputers
      boolResult = Ping(strComputer)
      If boolResult = True Then
            intDrives = 0
            Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
            Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", _
                                                wbemFlagReturnImmediately + wbemFlagForwardOnly)
            For Each objItem In colItems
                  intDrives = intDrives + 1
            Next
            If intDrives > 1 Then
                     MsgBox strComputer & " has " & intDrives & " hard drives."
            End If
      Else
            MsgBox strComputer & " could not be pinged."
      End If
Next

MsgBox "Done"

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
 
bsharathAuthor Commented:
Any way to run this and the results to a txt file.

0
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.

 
bsharathAuthor Commented:
How does this script find this out.That the machine has 2 HDD?
0
 
bsharathAuthor Commented:
Can you even give error on resume.
If any error found to search the other machine.
0
 
RobSampsonCommented:
>> Any way to run this and the results to a txt file.
Yes, see code below

>> How does this script find this out.That the machine has 2 HDD?
The script goes through each object in the Win32_DiskDrive class with the For Each loop, and increments intDrives by one for each object in that class, hence the amount of physical drives.

>> Can you even give error on resume.
Yes, see code below

'=================
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const intForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")

strFile = "computers.txt"
strOutput = "Results.txt"

Set objInputFile = objFSO.OpenTextFile(strFile, intForReading)
Set objOutputFile = objFSO.CreateTextFile(strOutput, True)
strComputers = objInputFile.ReadAll
objInputFile.Close
Set objInputFile = Nothing
arrComputers = Split(strComputers, VbCrLf)

For Each strComputer In arrComputers
      boolResult = Ping(strComputer)
      If boolResult = True Then
            intDrives = 0
            On Error Resume Next
            Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
            Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", _
                                                wbemFlagReturnImmediately + wbemFlagForwardOnly)
            If Err.Number = 0 Then
                  On Error GoTo 0
                  For Each objItem In colItems
                        intDrives = intDrives + 1
                  Next
                  If intDrives > 1 Then
                           objOutputFile.WriteLine strComputer & " has " & intDrives & " hard drives"
                  End If
            End If
            Set objWMIService = Nothing
      Else
            MsgBox strComputer & " could not be pinged."
      End If
Next

objOutputFile.Close
Set objOutputFile = Nothing
Set objFSO = Nothing

MsgBox "Done"

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
 
bsharathAuthor Commented:
Still get these popups

---------------------------

---------------------------
Dev-chen-pc031 could not be pinged.
---------------------------
OK  
---------------------------
0
 
RobSampsonCommented:
Oh whoops!  Did you want that output to the file as well? If not, just place an apostrophe at the start of this line:
MsgBox strComputer & " could not be pinged."

or, to log it to the file, change it to
objOutputFile.WriteLine strComputer & " could not be pinged."

Also, if you want to log that do NOT have 2 or more drives, change this bit:
                  If intDrives > 1 Then
                           objOutputFile.WriteLine strComputer & " has " & intDrives & " hard drives"
                  End If

to this
                  If intDrives > 1 Then
                           objOutputFile.WriteLine strComputer & " has " & intDrives & " hard drives"
                  Else
                           objOutputFile.WriteLine strComputer & " has " & intDrives & " hard drives"
                  End If

Regards,

Rob.
0
 
bsharathAuthor Commented:
I get this.

---------------------------
Windows Script Host
---------------------------
Script:      C:\2 HDD.vbs
Line:      27
Char:      19
Error:      0x80041013
Code:      80041013
Source:       (null)

---------------------------
OK  
---------------------------

Can i have the changed code please
0
 
RobSampsonCommented:
Sorry Sharath, try this:
'============
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const intForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")

strFile = "computers.txt"
strOutput = "Results.txt"

Set objInputFile = objFSO.OpenTextFile(strFile, intForReading)
Set objOutputFile = objFSO.CreateTextFile(strOutput, True)
strComputers = objInputFile.ReadAll
objInputFile.Close
Set objInputFile = Nothing
arrComputers = Split(strComputers, VbCrLf)

For Each strComputer In arrComputers
      boolResult = Ping(strComputer)
      If boolResult = True Then
            intDrives = 0
            On Error Resume Next
            Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
            Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", _
                                                wbemFlagReturnImmediately + wbemFlagForwardOnly)
            If Err.Number = 0 Then
                  For Each objItem In colItems
                        If Err.Number = 0 Then
                              On Error GoTo 0
                              intDrives = intDrives + 1
                        Else
                              Err.Clear
                              On Error GoTo 0
                              intDrives = "UNKNOWN"
                        End If
                  Next
                  If intDrives > 1 Then
                        objOutputFile.WriteLine strComputer & " has " & intDrives & " hard drives"
                  Else
                        objOutputFile.WriteLine strComputer & " has " & intDrives & " hard drive"
                  End If
            Else
                  Err.Clear
                  On Error GoTo 0
            End If
            Set objWMIService = Nothing
      Else
            MsgBox strComputer & " could not be pinged."
      End If
Next

objOutputFile.Close
Set objOutputFile = Nothing
Set objFSO = Nothing

MsgBox "Done"

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
 
bsharathAuthor Commented:
Rob.

I get this when a machine does not ping

---------------------------

---------------------------
Dev-chen-pc049 could not be pinged.
---------------------------
OK  
---------------------------


Can this results also be put in the file instaed of poping up
0
 
RobSampsonCommented:
Oh yeah sorry, I overlooked that one (again).
Please change this line:
MsgBox strComputer & " could not be pinged."

to this:
objOutputFile.WriteLine strComputer & " could not be pinged."

Regards,

Rob.
0
 
bsharathAuthor Commented:
Thanks a lot Rob...
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now