Find all Cdd and DVD with the detail if there is a cd inside the drive.

LVL 11
bsharathAsked:
Who is Participating?
 
zoofanConnect With a Mentor Commented:
This will return as follows,

PCname,DiscIn,DriveModel
name,True/False,Modelname


If more then one drive is installed the order from left to right for disc in and model
disc,disc,disc   model,model,model
1st ,2nd ,3rd   1st    ,2nd     ,3rd

they pair together in order left to right.

'===Start copy: getcdroms.vbs===
' ---------------------------------------------------------------'
' getcdroms.vbs
' 'Sample VBScript to query remote computers
' 'and return cdrom model information into csv file.
' ''Author Riley C. aka ZooFan
' '''Version 1.9 - August 2007
' ''''www.experts-exchange.com question ID: 22746064
' ---------------------------------------------------------------'
'
Option explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 3 'FileObject Access Type
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 'FileObject Format Type
Dim strPcList
Dim arrPcnames()
Dim strResultsFile
Dim dte
Dim tme
Dim objFso
Dim objWshShell
Dim objPCnames
Dim objReadFile
Dim intLneCount
Dim objOutputFile
Dim strCurPath
Dim intPCLoop
Dim strReturn      
Dim strTestcon
      Set objFso = CreateObject("Scripting.FileSystemObject")
      Set objWshShell = WScript.CreateObject("WScript.Shell")
      strCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
      strPcList = InputBox("Please enter the full path and file" & VbCrLf & "name of the file with the computer names.","Get cdrom drives.")
            'Test to make sure file exists if not exit script
            If Not objFso.FileExists(strPcList) Then
                  MsgBox "You must enter a valid full path and file name!",vbOKOnly,"Get cdrom drives."
                WScript.Quit(0)
            Elseif strPcList = "" Then
                  MsgBox "You must enter a filename!",vbOKOnly,"Get cdrom drives."
                WScript.Quit(0)               
            Else 'File exists continue
                                    dte = Replace(FormatDateTime(date(),vbshortdate),"/","-")
                                    tme = Replace(Replace(FormatDateTime(now(),vbLongtime),":","-")," ","")
                                          strResultsFile = strCurPath & "\" & tme & "_" & dte & ".csv"
                                                If objFSO.FileExists(strResultsFile) Then
                                                      ObjFSO.deleteFile(strResultsFile)
                                                Else
                                                      Set objOutputFile = objFso.CreateTextFile(strResultsFile)
                                                      objOutputFile.Close      
                                                End If
                                                MsgBox strResultsFile
                                    Set objPCnames = objFso.GetFile(strPcList)
                                    Set objReadFile = objPCnames.OpenAsTextStream(ForReading, TristateUseDefault)
                                          Do Until objReadFile.AtEndOfStream
                                                ReDim Preserve arrPCnames(intLneCount)
                                                arrPCnames(intLneCount) = objReadFile.ReadLine
                                                intLneCount = intLneCount + 1
                                          Loop
                                    objReadFile.Close
                                          Set objOutputFile = objFso.OpenTextFile(strResultsFile,ForWriting,TristateUseDefault)
                                          objOutputFile.WriteLine("Computer,DiscIn,Drives")
                                                For intPCLoop = LBound(arrPCnames) To UBound(arrPCnames)
                                                      strTestcon = IsServerOn(arrPCnames(intPCLoop))
                                                      If strTestcon = "0" then                                                
                                                      strReturn = getcdrom(arrPCnames(intPCLoop))
                                                      objOutputFile.WriteLine(arrPCnames(intPCLoop) & "," & strReturn)
                                                      Else
                                                      objOutputFile.WriteLine(arrPCnames(intPCLoop) & "," & strTestcon)
                                                      End If
                                                Next
                                           objOutputFile.Close
                                           MsgBox("Script has completed")
                                    WScript.Quit
                        End If
Function IsServerOn(strserver)                        
      Dim Testme
      Dim intErr
      Dim strRegValue
      Dim strFileServer
      On Error Resume Next
            Set Testme = GetObject("winmgmts://" & strserver & "/root/cimv2")
                  Set strRegValue = GetObject("winmgmts://" & strserver & "/root/default:StdRegProv")
                        intErr = Err.Number
                        If intErr <> 0 Then
                              IsServerOn = Err.Description
                        Else
                              IsServerOn = "0"
                        End If
      On Error GoTo 0
End Function
Function getcdrom(strcomputer)
Dim GetWMIServices
Dim colItems
Dim getcd
Dim obj
Dim discin

                        Set GetWMIServices = GetObject("winmgmts:" _
                            & "{impersonationLevel=impersonate}!//" & strcomputer & "/root/cimv2")
                        Set colItems = GetWMIServices.ExecQuery("Select * from Win32_CDROMDrive")
                        For Each obj In colItems
                        getCD = obj.name
                        discin = discin & "," & obj.MediaLoaded
                        getcdrom = getcdrom & "," & getcd
                        Next
                        getcdrom = discin & "," & getcdrom
                        If getcdrom = ",," Then
                         getcdrom = "Error reading drive information"
                         End if
      Set GetWMIServices = Nothing
      Set colItems = Nothing
End Function

Function readtextfile(strTxtFile, arrname())
On Error Resume Next
      Dim intErr, intLines
      Dim objTxtLines, objReadFile,objFso      
            Set objFso = CreateObject("Scripting.FileSystemObject")
            Set objTxtLines = objFso.GetFile(strTxtFile)
            Set objReadFile = objTxtLines.OpenAsTextStream(ForReading, TristateUseDefault)
                  Do Until objReadFile.AtEndOfStream
                        ReDim Preserve arrname(intLines)
                        arrname(intLines) = objReadFile.ReadLine
                        intLines = intLines + 1
                  Loop
            objReadFile.Close
            Set objFso = nothing
            Set objTxtLines = Nothing
            Set objReadFile = Nothing
                  intErr = Hex(Err.Number)
                        If intErr <> 0 Then
                              readtextfile = Err.Description
                        Else
                              readtextfile = "0"
                        End If
On Error GoTo 0                        
End Function



any problems let me know.


zf
0
 
bsharathAuthor Commented:
Thanks....
0
 
zoofanCommented:
How about a free bonus??  lol

Realize this will get messy if you run accross alot of pc's with multi drives, but in single drive machines you may like this better, returns to the file as before, added drive letter assigned and volume label if disc is in.
Output:

PCNAME,DriveLetter,VolumeLabel,DiscIn,DriveModel


'===Start copy: getcdroms.vbs===
' ---------------------------------------------------------------'
' getcdroms.vbs
' 'Sample VBScript to query remote computers
' 'and return cdrom model information into csv file.
' ''Author Riley C. aka ZooFan
' '''Version 1.7 - August 2007
' ''''www.experts-exchange.com question ID: 22746064
' ---------------------------------------------------------------'
'
Option explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 3 'FileObject Access Type
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 'FileObject Format Type
Dim strPcList
Dim arrPcnames()
Dim strResultsFile
Dim dte
Dim tme
Dim objFso
Dim objWshShell
Dim objPCnames
Dim objReadFile
Dim intLneCount
Dim objOutputFile
Dim strCurPath
Dim intPCLoop
Dim strReturn      
Dim strTestcon
      Set objFso = CreateObject("Scripting.FileSystemObject")
      Set objWshShell = WScript.CreateObject("WScript.Shell")
      strCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
      strPcList = InputBox("Please enter the full path and file" & VbCrLf & "name of the file with the computer names.","Get cdrom drives.")
            'Test to make sure file exists if not exit script
            If Not objFso.FileExists(strPcList) Then
                  MsgBox "You must enter a valid full path and file name!",vbOKOnly,"Get cdrom drives."
                WScript.Quit(0)
            Elseif strPcList = "" Then
                  MsgBox "You must enter a filename!",vbOKOnly,"Get cdrom drives."
                WScript.Quit(0)               
            Else 'File exists continue
                                    dte = Replace(FormatDateTime(date(),vbshortdate),"/","-")
                                    tme = Replace(Replace(FormatDateTime(now(),vbLongtime),":","-")," ","")
                                          strResultsFile = strCurPath & "\" & tme & "_" & dte & ".csv"
                                                If objFSO.FileExists(strResultsFile) Then
                                                      ObjFSO.deleteFile(strResultsFile)
                                                Else
                                                      Set objOutputFile = objFso.CreateTextFile(strResultsFile)
                                                      objOutputFile.Close      
                                                End If
                                                MsgBox strResultsFile
                                    Set objPCnames = objFso.GetFile(strPcList)
                                    Set objReadFile = objPCnames.OpenAsTextStream(ForReading, TristateUseDefault)
                                          Do Until objReadFile.AtEndOfStream
                                                ReDim Preserve arrPCnames(intLneCount)
                                                arrPCnames(intLneCount) = objReadFile.ReadLine
                                                intLneCount = intLneCount + 1
                                          Loop
                                    objReadFile.Close
                                          Set objOutputFile = objFso.OpenTextFile(strResultsFile,ForWriting,TristateUseDefault)
                                          objOutputFile.WriteLine("Computer,DriveLtr,Label,DiscIn,Drives")
                                                For intPCLoop = LBound(arrPCnames) To UBound(arrPCnames)
                                                      strTestcon = IsServerOn(arrPCnames(intPCLoop))
                                                      If strTestcon = "0" then                                                
                                                      strReturn = getcdrom(arrPCnames(intPCLoop))
                                                      objOutputFile.WriteLine(arrPCnames(intPCLoop) & "," & strReturn)
                                                      Else
                                                      objOutputFile.WriteLine(arrPCnames(intPCLoop) & "," & strTestcon)
                                                      End If
                                                Next
                                           objOutputFile.Close
                                           MsgBox("Script has completed")
                                    WScript.Quit
                        End If
Function IsServerOn(strserver)                        
      Dim Testme
      Dim intErr
      Dim strRegValue
      Dim strFileServer
      On Error Resume Next
            Set Testme = GetObject("winmgmts://" & strserver & "/root/cimv2")
                  Set strRegValue = GetObject("winmgmts://" & strserver & "/root/default:StdRegProv")
                        intErr = Err.Number
                        If intErr <> 0 Then
                              IsServerOn = Err.Description
                        Else
                              IsServerOn = "0"
                        End If
      On Error GoTo 0
End Function
Function getcdrom(strcomputer)
Dim GetWMIServices
Dim colItems
Dim getcd
Dim obj
Dim discin
Dim strVolume
Dim strDrvLetter

                        Set GetWMIServices = GetObject("winmgmts:" _
                            & "{impersonationLevel=impersonate}!//" & strcomputer & "/root/cimv2")
                        Set colItems = GetWMIServices.ExecQuery("Select * from Win32_CDROMDrive")
                        For Each obj In colItems
                        getCD = obj.name
                        strDrvLetter = strDrvLetter & obj.Drive
                        strVolume = strVolume & "," & obj.VolumeName
                        discin = discin & "," & obj.MediaLoaded
                        getcdrom = getcdrom & "," & getcd
                        Next
                        getcdrom = strDrvLetter & "," & strVolume & "," & discin & "," & getcdrom
                        If getcdrom = ",,," Then
                         getcdrom = "Error reading drive information"
                         End if
      Set GetWMIServices = Nothing
      Set colItems = Nothing
End Function

Function readtextfile(strTxtFile, arrname())
On Error Resume Next
      Dim intErr, intLines
      Dim objTxtLines, objReadFile,objFso      
            Set objFso = CreateObject("Scripting.FileSystemObject")
            Set objTxtLines = objFso.GetFile(strTxtFile)
            Set objReadFile = objTxtLines.OpenAsTextStream(ForReading, TristateUseDefault)
                  Do Until objReadFile.AtEndOfStream
                        ReDim Preserve arrname(intLines)
                        arrname(intLines) = objReadFile.ReadLine
                        intLines = intLines + 1
                  Loop
            objReadFile.Close
            Set objFso = nothing
            Set objTxtLines = Nothing
            Set objReadFile = Nothing
                  intErr = Hex(Err.Number)
                        If intErr <> 0 Then
                              readtextfile = Err.Description
                        Else
                              readtextfile = "0"
                        End If
On Error GoTo 0                        
End Function



:-)

zf
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
zoofanCommented:
If you dont need it just use the other, thought you may like a touch more for good measure.

enjoy!

zf
0
 
zoofanCommented:
If you have any other hardware queries let me know those i enjoy doing!! :-)

zf
0
 
bsharathAuthor Commented:
Wow this is a nice one zoofan.An additional benifit for me....:)
0
 
zoofanCommented:
Thought you might enjoy the suprise, glad you like.


cheers

zf
0
 
bsharathAuthor Commented:
I have a Q from a long time.I think you can help...

Is it possible to find all the HDD in a rack server.In what raid are they configured,How many slots they have and how many are free.
esults like.

machinename     No of HDD    HDD size    Raide type     Free slots    

If you can help i can raise a Q....
THX
Sharath
0
 
zoofanCommented:
hmmm.....

I think I can get you some of it.  Num of drives yes, size of drive yes, raid type not very confident, and free slots I assume you mean on the controller and that as well not very confident.

These last two in a hardware raid configuration windows would'nt have access to the information as all it see's is one single drive(the array, Which btw would list in No of HDD and size as a single drive) it would know the controller type and thats it as far I know the other information would have to be queried directly from the controller and would be card specific as well as manufacturer specific dont think thats happening or atleast not with my ability.  

I can do Num drives, and drive size with no problem,  which wil include the raid drive(as windows see's it)


zf

0
 
zoofanCommented:
For example when you go into disk managment you should see the hardware raid as a single Drive entity within windows,  aside from low-level machine programming specific to the card model and manufacturer thats all your going to get from it I belive.  

My suggestion to start you in a better direction is who makes your raid controller? and what model is it? I will help you look and see if they have any windows based managment/montoring tools.

zf
0
 
bsharathAuthor Commented:
Ok Zoofan

I only have HP and dell machines...
0
 
bsharathAuthor Commented:
Zoofan.

This is a relevent Q for the previous post printer status page.The same way but to connect through Mstsc.

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Q_22749002.html
0
All Courses

From novice to tech pro — start learning today.