Solved

Is there any way to find unpartitioned drives in all machines in a file.

Posted on 2009-06-30
59
545 Views
Last Modified: 2012-05-07
Hi,

Is there any way to find unpartitioned drives in all machines in a file.
I have so many machines without the partitions created. In unpartitioned format. Some without a drive letter or some without even formating. Can i find just machine names that may have such cases.

I have the machine names in a txt file which i need to scan. Can i find just the machine names that needs attention on these.

Regards
Sharath
0
Comment
Question by:bsharath
  • 29
  • 20
  • 8
59 Comments
 
LVL 3

Expert Comment

by:astroviper
ID: 24751144
This may help: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/disk/drives/

You could get the physical hard drive size then subtract the active partitions from it.

0
 
LVL 11

Author Comment

by:bsharath
ID: 24762550
Can you mention which code i can use and on all systems in the txt file
0
 
LVL 11

Author Comment

by:bsharath
ID: 24762551
Can you mention which code i can use and on all systems in the txt file
0
 
LVL 3

Expert Comment

by:astroviper
ID: 24762757
I'll work on it. Do you have a machine that you can test it on though? Save me setting up a virtual machine with unpartitioned space...
0
 
LVL 11

Author Comment

by:bsharath
ID: 24763118
Yes i do have
0
 
LVL 3

Expert Comment

by:astroviper
ID: 24763591
Okay to run this you wanna have your input.txt file in the same directory as the script and enter "cscript script.vbs > out.txt"  in a command window. Note that it may not be entirely accurate but I'm sure your only using this as a guide to find the computers that need attention anyway.

' Note there may be rounding errors in the CDbl bit

inputfile = "input.txt"

separator = VbCrLf
 

set filesys = CreateObject("Scripting.FileSystemObject")

set readfile = filesys.OpenTextFile(inputfile, 1, false)

arrComputers = Split(readfile.ReadAll, separator)

readfile.close
 

For i = 0 To UBound(arrComputers) 

    WScript.Echo "Computer name:           " & arrComputers(i)

    WScript.Echo "Physical Drive Space:    " & filesize(PhysicalDriveSpace(arrComputers(i)) )

    WScript.echo "Partitioned Drive Space: " & filesize(PartitionedSpace(arrComputers(i)))

    WScript.Echo "Difference:              " & _

        filesize(PhysicalDriveSpace(arrComputers(i)) - PartitionedSpace(arrComputers(i))) & VbCrLf

Next

Function PartitionedSpace(strComputer)

    Set objWMIService = GetObject("winmgmts:" _

        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colDiskPartitions = objWMIService.ExecQuery _

        ("Select * from Win32_DiskPartition")

    For each objPartition in colDiskPartitions

        PartitionedSpace = PartitionedSpace + CDbl(objPartition.Size)

    Next

End Function
 

Function PhysicalDriveSpace(strComputer)

    Set objWMIService = GetObject("winmgmts:" _    

        & "{impersonationLevel=impersonate}!\\" & strComputer _

            & "\root\cimv2")

    Set colDiskDrives = objWMIService.ExecQuery _    

        ("Select * from Win32_DiskDrive")

    For each objDiskDrive in colDiskDrives

        PhysicalDriveSpace = PhysicalDriveSpace + CDbl(objDiskDrive.Size)

    Next

End Function
 

Function filesize(bytes)

'http://www.osix.net/modules/article/?id=139

    Filesize = bytes / 1024

    Filesize = Round(Filesize, 2)
 

        If FileSize < 0.5 Then
 

            Filesize = Filesize * 1024

            Filesize = Int(FileSize)

            Filesize = Filesize & " Bytes"
 

        ElseIf Filesize > 1024 Then
 

            FileSize = Filesize / 1024

            FileSize = Round(FileSize, 2)

            FileSize = Filesize & " Meg"
 

        Else
 

            filesize = filesize & " K"

    

        END IF
 

End Function 

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 24763785
I get this
E:\>cscript Partition.vbs > e:\Out.txt
E:\Partition.vbs(28, 5) Microsoft VBScript runtime error: The remote server machine does not exist or is unavailable: 'GetObject'

Can i get a way to skip the machines if Off or with permission errors
0
 
LVL 3

Expert Comment

by:astroviper
ID: 24763958
The only way I know how to tell if you have permission to do something is to try it, so I just added in On Error Resume Next in the bits that may require permissions.
Just checking too, is your file one computer name per line, or comma separated? If comma separated change separator = VbCrLf to separator = ","

' Note there may be rounding errors in the CDbl bit

inputfile = "input.txt"

separator = VbCrLf

 

set filesys = CreateObject("Scripting.FileSystemObject")

set readfile = filesys.OpenTextFile(inputfile, 1, false)

arrComputers = Split(readfile.ReadAll, separator)

readfile.close

 

For i = 0 To UBound(arrComputers) 

    WScript.Echo "Computer name:           " & arrComputers(i)

    WScript.Echo "Physical Drive Space:    " & filesize(PhysicalDriveSpace(arrComputers(i)) )

    WScript.echo "Partitioned Drive Space: " & filesize(PartitionedSpace(arrComputers(i)))

    WScript.Echo "Difference:              " & _

        filesize(PhysicalDriveSpace(arrComputers(i)) - PartitionedSpace(arrComputers(i))) & VbCrLf

Next

Function PartitionedSpace(strComputer)

    On Error Resume Next

    Set objWMIService = GetObject("winmgmts:" _

        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colDiskPartitions = objWMIService.ExecQuery _

        ("Select * from Win32_DiskPartition")

    For each objPartition in colDiskPartitions

        PartitionedSpace = PartitionedSpace + CDbl(objPartition.Size)

    Next

    On Error Goto 0

End Function

 

Function PhysicalDriveSpace(strComputer)

    On Error Resume Next

    Set objWMIService = GetObject("winmgmts:" _    

        & "{impersonationLevel=impersonate}!\\" & strComputer _

            & "\root\cimv2")

    Set colDiskDrives = objWMIService.ExecQuery _    

        ("Select * from Win32_DiskDrive")

    For each objDiskDrive in colDiskDrives

        PhysicalDriveSpace = PhysicalDriveSpace + CDbl(objDiskDrive.Size)

    Next

    On Error Goto 0

End Function

 

Function filesize(bytes)

'http://www.osix.net/modules/article/?id=139

    Filesize = bytes / 1024

    Filesize = Round(Filesize, 2)

 

        If FileSize < 0.5 Then

 

            Filesize = Filesize * 1024

            Filesize = Int(FileSize)

            Filesize = Filesize & " Bytes"

 

        ElseIf Filesize > 1024 Then

 

            FileSize = Filesize / 1024

            FileSize = Round(FileSize, 2)

            FileSize = Filesize & " Meg"

 

        Else

 

            filesize = filesize & " K"

    

        END IF

 

End Function 

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 24764337
What should i look for... I ran the script on 100 machines and most are "0' and others as 31 K
0
 
LVL 3

Expert Comment

by:astroviper
ID: 24764421
Have you tried it on just one machine that you know for sure has a significant amount of unpartitioned space? Use that as a benchmark. You want to be looking at the difference line for a large number. Thats the difference between the physical size of all the disks on the machine and the sum of the size of all the partitions on it.
0
 
LVL 11

Author Comment

by:bsharath
ID: 24779427
Hi,

I tested it with a delted partotio
Unallocated partition
Formatted partition
None of these were found by the script
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24792058
See if this works.  It tries to read the amount of partitions using the Win32_DiskDrive class.

Regards,

Rob.
Const wbemFlagReturnImmediately = &h10

Const wbemFlagForwardOnly = &h20

strComputersFile = "Computers.txt"

strLogFile = "NoPartitionsLog.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Const intForReading = 1

Set objFile = objFSO.OpenTextFile(strComputersFile, intForReading, False)

strResults = "Computer without partitions on hard disks" & VbCrLf & "========================================="

While Not objFile.AtEndOfStream

	strComputer = objFile.ReadLine

	On Error Resume Next

	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

	Set colItems = objWMIService.ExecQuery("SELECT DeviceID,Partitions FROM Win32_DiskDrive", "WQL", _

                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

	For Each objItem In colItems

		If Err.Number = 0 Then

			If objItem.Partitions = 0 Then

				strResults = strResults & VbCrLf & strComputer & ": " & objItem.DeviceID & " has no partitions."

			End If

		Else

			strResults = strResults & VbCrLf & strComputer & ": Connection error"

		End If

		Err.Clear

		On Error GoTo 0

	Next

Wend

objFile.Close

Set objLog = objFSO.CreateTextFile(strLogFile, True)

objLog.Write strResults

objLog.Close

MsgBox "Finished. Please see " & strLogFile

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 24792089
Rob i get this

---------------------------
Windows Script Host
---------------------------
Script:      E:\Partition.vbs
Line:      25
Char:      2
Error:      Object not a collection
Code:      800A01C3
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
ID: 24792090
Rob i get this

---------------------------
Windows Script Host
---------------------------
Script:      E:\Partition.vbs
Line:      25
Char:      2
Error:      Object not a collection
Code:      800A01C3
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24792112
Oh, try this.

Regards,

Rob.
Const wbemFlagReturnImmediately = &h10

Const wbemFlagForwardOnly = &h20

strComputersFile = "Computers.txt"

strLogFile = "NoPartitionsLog.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Const intForReading = 1

Set objFile = objFSO.OpenTextFile(strComputersFile, intForReading, False)

strResults = "Computer without partitions on hard disks" & VbCrLf & "========================================="

While Not objFile.AtEndOfStream

	strComputer = objFile.ReadLine

	On Error Resume Next

	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

	Set colItems = objWMIService.ExecQuery("SELECT DeviceID,Partitions FROM Win32_DiskDrive", "WQL", _

                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

	For Each objItem In colItems

		If Err.Number = 0 Then

			If objItem.Partitions = 0 Then

				strResults = strResults & VbCrLf & strComputer & ": " & objItem.DeviceID & " has no partitions."

			End If

		Else

			strResults = strResults & VbCrLf & strComputer & ": Connection error"

		End If

	Next

	Err.Clear

	On Error GoTo 0

Wend

objFile.Close

Set objLog = objFSO.CreateTextFile(strLogFile, True)

objLog.Write strResults

objLog.Close

MsgBox "Finished. Please see " & strLogFile

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 24792166
Rob i tried with few machines but no results

Partition without drive letter
Partition Formatted without a drive letter
Unpartioned space
None of these were detected
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24792194
So you only have the header lines in the log file?  No computer names listed?  I don't have any unpartitioned devices.  If you can wait two weeks I'll be back at work and will able to get something to test with...

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24792205
In the meantime, download ScriptoMatic from Microsoft, then on a machine with such a drive, run it, and select the Win32_DiskDrive class on the right hand side, then click Run.

You should get a DOS box that lists the details of the drives.  Look for anything that might suggest that it's unformatted or has no partitions.

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 24792209
Ok Rob....
0
 
LVL 11

Author Comment

by:bsharath
ID: 24792210
Ok Rob....
0
 
LVL 11

Author Comment

by:bsharath
ID: 24792292
Rob i get this


==========================================
Computer: IN-FS01
==========================================
Availability:
BytesPerSector: 512
Capabilities: 3,4
CapabilityDescriptions:
Caption: ST3500830AS
CompressionMethod:
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_DiskDrive
DefaultBlockSize:
Description: Disk drive
DeviceID: \\.\PHYSICALDRIVE0
ErrorCleared:
ErrorDescription:
ErrorMethodology:
Index: 0

InterfaceType: IDE
LastErrorCode:
Manufacturer: (Standard disk drives)
MaxBlockSize:
MaxMediaSize:
MediaLoaded: True
MediaType: Fixed hard disk media
MinBlockSize:
Model: ST3500830AS
Name: \\.\PHYSICALDRIVE0
NeedsCleaning:
NumberOfMediaSupported:
Partitions: 3
PNPDeviceID: IDE\DISKST3500830AS_____________________________3.CQD___\5&2A9D7AB2
&0&0.0.0
PowerManagementCapabilities:
PowerManagementSupported:
SCSIBus: 0
SCSILogicalUnit: 0
SCSIPort: 1
SCSITargetId: 0
SectorsPerTrack: 63
Signature: -1833332039
Size: 500105249280
Status: OK
StatusInfo:
SystemCreationClassName: Win32_ComputerSystem
SystemName: IN-FS01
TotalCylinders: 60801
TotalHeads: 255
TotalSectors: 976768065
TotalTracks: 15504255
TracksPerCylinder: 255

0
 
LVL 11

Author Comment

by:bsharath
ID: 24792293
Rob i get this


==========================================
Computer: IN-FS01
==========================================
Availability:
BytesPerSector: 512
Capabilities: 3,4
CapabilityDescriptions:
Caption: ST3500830AS
CompressionMethod:
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_DiskDrive
DefaultBlockSize:
Description: Disk drive
DeviceID: \\.\PHYSICALDRIVE0
ErrorCleared:
ErrorDescription:
ErrorMethodology:
Index: 0

InterfaceType: IDE
LastErrorCode:
Manufacturer: (Standard disk drives)
MaxBlockSize:
MaxMediaSize:
MediaLoaded: True
MediaType: Fixed hard disk media
MinBlockSize:
Model: ST3500830AS
Name: \\.\PHYSICALDRIVE0
NeedsCleaning:
NumberOfMediaSupported:
Partitions: 3
PNPDeviceID: IDE\DISKST3500830AS_____________________________3.CQD___\5&2A9D7AB2
&0&0.0.0
PowerManagementCapabilities:
PowerManagementSupported:
SCSIBus: 0
SCSILogicalUnit: 0
SCSIPort: 1
SCSITargetId: 0
SectorsPerTrack: 63
Signature: -1833332039
Size: 500105249280
Status: OK
StatusInfo:
SystemCreationClassName: Win32_ComputerSystem
SystemName: IN-FS01
TotalCylinders: 60801
TotalHeads: 255
TotalSectors: 976768065
TotalTracks: 15504255
TracksPerCylinder: 255

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24799950
Hmmm, well that shows that the drive that you ran that on has three partitions.....Does Disk Management show you those partitions?
0
 
LVL 11

Author Comment

by:bsharath
ID: 24800431
Hi Rob here is the screenshot
Capture.JPG
0
 
LVL 3

Expert Comment

by:astroviper
ID: 24800494
That looks like it's already partitioned, just doesn't have a drive letter assigned.
0
 
LVL 11

Author Comment

by:bsharath
ID: 24800502
I tried with both the ways
0
 
LVL 3

Expert Comment

by:astroviper
ID: 24800555
Could you see if this script picks up the fact that it's partitioned but has no drive letter?
Its from: http://www.experts-exchange.com/Programming/System/Windows__Programming/Q_21262527.html
Run it from the command line: cscript script.vbs > out.txt
Can you post the output in out.txt?

dim obj, objs
 

Set objs = GetObject("winmgmts:").InstancesOf("Win32_LogicalDiskToPartition")

for each obj in objs

      msgbox(obj.Antecedent & vbcrlf & obj.Dependent)

next

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 24800908
I get these

Unpartitioned code results

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

---------------------------
\\IN-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #0"

\\IN-FS01\root\cimv2:Win32_LogicalDisk.DeviceID="C:"
---------------------------
OK  
---------------------------

and

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

---------------------------
\\IN-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #1"

\\IN-FS01\root\cimv2:Win32_LogicalDisk.DeviceID="E:"
---------------------------
OK  
---------------------------



Partitioned drive but no drive letter

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

---------------------------
\\IN-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #0"

\\IN-FS01\root\cimv2:Win32_LogicalDisk.DeviceID="C:"
---------------------------
OK  
---------------------------

and

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

---------------------------
\\IN-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #1"

\\IN-FS01\root\cimv2:Win32_LogicalDisk.DeviceID="E:"
---------------------------
OK  
---------------------------
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 11

Author Comment

by:bsharath
ID: 24800909
I get these

Unpartitioned code results

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

---------------------------
\\IN-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #0"

\\IN-FS01\root\cimv2:Win32_LogicalDisk.DeviceID="C:"
---------------------------
OK  
---------------------------

and

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

---------------------------
\\IN-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #1"

\\IN-FS01\root\cimv2:Win32_LogicalDisk.DeviceID="E:"
---------------------------
OK  
---------------------------



Partitioned drive but no drive letter

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

---------------------------
\\IN-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #0"

\\IN-FS01\root\cimv2:Win32_LogicalDisk.DeviceID="C:"
---------------------------
OK  
---------------------------

and

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

---------------------------
\\IN-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #1"

\\IN-FS01\root\cimv2:Win32_LogicalDisk.DeviceID="E:"
---------------------------
OK  
---------------------------
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24976054
Sharath, the code that gives you the aboe output....can you post the code you used to get that? It looks like that will provide you enough information to know what's partitioned and what is not.

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 24976408
Hi Rob i used this code....
dim obj, objs

 

Set objs = GetObject("winmgmts:").InstancesOf("Win32_LogicalDiskToPartition")

for each obj in objs

      msgbox(obj.Antecedent & vbcrlf & obj.Dependent)

next

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24986369
OK, try running this code against a few systems.  From what I can tell, we will be able to find out whether there is a partition without a drive letter, but I don't have any drives without any partitions, so I can't tell if that will work.

Regards,

Rob.
strComputer = InputBox("Enter remote computer name:", "Computer Name", "D1KYSZ1SRING")

Set objPhysicalDisks = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputer).InstancesOf("Win32_DiskDriveToDiskPartition")

strResults = "Hard Disk Details for " & strComputer & ":"

strResults = strResults & VbCrLf & "Physical Details:"

For Each objDisk In objPhysicalDisks

	strResults = strResults & VbCrLf & objDisk.Antecedent & VbCrLf & objDisk.Dependent

Next

Set objLogicalDisks = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputer).InstancesOf("Win32_LogicalDiskToPartition")

strResults = strResults & VbCrLf & "Logical Details:"

For Each objDisk In objLogicalDisks

	strResults = strResults & VbCrLf & objDisk.Antecedent & VbCrLf & objDisk.Dependent

Next

MsgBox strResults

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24986550
Did you recieve the above email?  EE was having problems when I posted it....
0
 
LVL 11

Author Comment

by:bsharath
ID: 24987080
Hi Rob sorry did not receive it..

Here is the results
---------------------------
 

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

Hard Disk Details for In-fs01:
 

Physical Details:
 

\\In-FS01\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE0"
 

\\In-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #0"
 

\\In-FS01\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE0"
 

\\In-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #1"
 

Logical Details:
 

\\In-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #0"
 

\\In-FS01\root\cimv2:Win32_LogicalDisk.DeviceID="C:"
 

\\In-FS01\root\cimv2:Win32_DiskPartition.DeviceID="Disk #0, Partition #1"
 

\\In-FS01\root\cimv2:Win32_LogicalDisk.DeviceID="E:"

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

OK   

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

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 24997185
OK, so that tells me there is one physical disk, with two partitions, both with drive letters assigned.

Do you have a drive with a partition without a drive letter assigned, and also a drive with no partitions that we can check what we get?

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 24998377
Rob attached is the disk management... Which has 1 partition un created...

Capture.JPG
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 25002341
Oh, so it's unpartitioned space?  Hmmm, I think the only way we can find unpartitioned space is to determine the entire disk size, and subtract the known partition sizes, and see what's left. I'll have to work on that.....hopefully I can knock something up tomorrow.

Regards,

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 25002351
Ok Rob thanks
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 25010233
OK, I think I've finally got it sorted....try this....

Regards,

Rob.
Set objShell = CreateObject("Wscript.Shell")

If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then

    strPath = Wscript.ScriptFullName

    strCommand = "%comspec% /k cscript  """ & strPath & """"

    objShell.Run(strCommand), 1, True

    Wscript.Quit

End If
 

Const adVarChar = 200

Const adBigInt = 20

Const MaxCharacters = 255
 

Set objDrives = CreateObject("ADOR.Recordset")

objDrives.Fields.Append "Drive", adVarChar, MaxCharacters

objDrives.Fields.Append "Size", adBigInt

objDrives.Open

	

Set objPartitions = CreateObject("ADOR.Recordset")

objPartitions.Fields.Append "Drive", adVarChar, MaxCharacters

objPartitions.Fields.Append "Partition", adVarChar, MaxCharacters

objPartitions.Fields.Append "DriveLetter", adVarChar, MaxCharacters

objPartitions.Fields.Append "Size", adBigInt

objPartitions.Open
 

strComputer = InputBox("Enter remote computer name:", "Computer Name", "D1KYSZ1SRING")

If strComputer <> "" Then

	If strComputer = "." Then strComputer = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

	If Ping(strComputer) = True Then

		On Error Resume Next

		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2")

		Set objDisks = objWMIService.ExecQuery("SELECT DeviceID,Size FROM Win32_DiskDrive")

		If Err.Number = 0 Then

			On Error GoTo 0

			strResults = "Hard Disk Details for " & strComputer & ":"

			For Each objDisk In objDisks

				strDrive = "Disk #" & Mid(objDisk.DeviceID, InStr(objDisk.DeviceID, "DRIVE") + 5)

				objDrives.AddNew

				objDrives("Drive") = strDrive

				objDrives("Size") = objDisk.Size

				objDrives.Update

				'WScript.Echo strDrive & ": " & objDisk.Size

			Next
 

			Set objPhysicalDisks = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDriveToDiskPartition")

			For Each objPhysicalDisk In objPhysicalDisks

				strPhysicalDetail = Mid(objPhysicalDisk.Dependent, InStrRev(objPhysicalDisk.Dependent, "=") + 2)

				strPhysicalDetail = Left(strPhysicalDetail, InStr(strPhysicalDetail, """") - 1)

				strPhysicalDrive = Trim(Split(strPhysicalDetail, ",")(0))

				strPhysicalPartition = Trim(Split(strPhysicalDetail, ",")(1))

				objPartitions.AddNew

				objPartitions("Drive") = strPhysicalDrive

				objPartitions("Partition") = strPhysicalPartition

				objPartitions.Update

				'WScript.Echo strPhysicalDrive & VbCrLf & strPhysicalPartition

			Next
 

			Set objLogicalDisks = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDiskToPartition")

			For Each objLogicalDisk In objLogicalDisks

				strLogicalDetail = Mid(objLogicalDisk.Antecedent, InStrRev(objLogicalDisk.Antecedent, "=") + 2)

				strLogicalDetail = Left(strLogicalDetail, InStr(strLogicalDetail, """") - 1)

				strLogicalDrive = Trim(Split(strLogicalDetail, ",")(0))

				strLogicalPartition = Trim(Split(strLogicalDetail, ",")(1))

				strLogicalDriveLetter = Mid(objLogicalDisk.Dependent, InStrRev(objLogicalDisk.Dependent, "=") + 2)

				strLogicalDriveLetter = Left(strLogicalDriveLetter, InStr(strLogicalDriveLetter, """") - 1)

				objPartitions.Filter = "Drive='" & strLogicalDrive & "' AND Partition='" & strLogicalPartition & "'"

				If objPartitions.EOF = False Then

					objPartitions("DriveLetter") = strLogicalDriveLetter

				End If

				'WScript.Echo strLogicalDrive & VbCrLf & strLogicalPartition & VbCrLf & strLogicalDriveLetter

			Next

			

			objPartitions.Filter = ""

			If Not objPartitions.EOF Then objPartitions.MoveFirst

			While Not objPartitions.EOF

				Set objLocalPartitions = objWMIService.ExecQuery("SELECT * FROM Win32_DiskPartition WHERE DeviceID='" & objPartitions("Drive") & ", " & objPartitions("Partition") & "'")

				For Each objLocalPartition In objLocalPartitions

					objPartitions("Size") = objLocalPartition.Size

				Next

				objPartitions.MoveNext

			Wend

			

			objDrives.Filter = ""

			If Not objDrives.EOF Then objDrives.MoveFirst

			WScript.Echo VbCrLf & "Physical Drives:" & VbCrLf

			While Not objDrives.EOF

				WScript.Echo "Drive: " & objDrives("Drive") & VbCrLf & _

					"Size: " & objDrives("Size")

				objPartitions.Filter = "Drive='" & objDrives("Drive") & "'"

				If Not objPartitions.EOF Then objPartitions.MoveFirst

				WScript.Echo VbCrLf & "Logical Drives:" & VbCrLf

				intTotalSize = 0

				While Not objPartitions.EOF

					WScript.Echo "Drive: " & objPartitions("Drive") & VbCrLf & _

						"Partition: " & objPartitions("Partition") & VbCrLf & _

						"DriveLetter: " & objPartitions("DriveLetter") & VbCrLf & _

						"Size: " & objPartitions("Size")

					'WScript.Echo TypeName(CLng(objPartitions("Size"))) & VbCrLf & TypeName(intTotalSize)

					intTotalSize = CDbl(intTotalSize) + CDbl(objPartitions("Size"))

					objPartitions.MoveNext

				Wend

				WScript.Echo "There is " & (CDbl(objDrives("Size")) - CDbl(intTotalSize)) / 1024 / 1024 & " MB of unpartitioned space on " & objDrives("Drive")

				objDrives.MoveNext

			Wend

		Else

			Err.Clear

			On Error GoTo 0

			WScript.Echo "Unable to access " & strComputer

		End If

	Else

		WScript.Echo strComputer & " is offline."

	End If

End If
 

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

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 25010236
Oh, the question was already closed....oh well....
0
 
LVL 3

Expert Comment

by:astroviper
ID: 25010244
Yea I'm pretty sure you deserved the points on this one Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 25010262
LOL! Yeah, doesn't matter.....the code you posted pointed in the right direction for the Win32 classes....I had to include a few more, and cross reference them, and stuff like that.  You can give the code a shot too if you like...

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 25010264
Hi Rob
I get this

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.


Physical Drives:

Drive: Disk #0
Size: 500105249280

Logical Drives:

Drive: Disk #0
Partition: Partition #0
DriveLetter: C:
Size: 20974431744
Drive: Disk #0
Partition: Partition #1
DriveLetter: E:
Size: 479130785280
There is 0.03076171875 MB of unpartitioned space on Disk #0

it was automatically closed i guess... I shall request to reopen... :-)
Can i get the data in GB and the script to query a txt file
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 25010306
Try this.

Regards,

Rob.
Set objShell = CreateObject("Wscript.Shell")

If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then

    strPath = Wscript.ScriptFullName

    strCommand = "%comspec% /k cscript  """ & strPath & """"

    objShell.Run(strCommand), 1, True

    Wscript.Quit

End If
 

strComputers = "computers.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Const intForReading = 1

Set objFile = objFSO.OpenTextFile(strComputers, intForReading, False)
 

Const adVarChar = 200

Const adBigInt = 20

Const MaxCharacters = 255
 

While Not objFile.AtEndOfStream

	Set objDrives = CreateObject("ADOR.Recordset")

	objDrives.Fields.Append "Drive", adVarChar, MaxCharacters

	objDrives.Fields.Append "Size", adBigInt

	objDrives.Open

		

	Set objPartitions = CreateObject("ADOR.Recordset")

	objPartitions.Fields.Append "Drive", adVarChar, MaxCharacters

	objPartitions.Fields.Append "Partition", adVarChar, MaxCharacters

	objPartitions.Fields.Append "DriveLetter", adVarChar, MaxCharacters

	objPartitions.Fields.Append "Size", adBigInt

	objPartitions.Open

	

	'strComputer = InputBox("Enter remote computer name:", "Computer Name", "D1KYSZ1SRING")

	strComputer = objFile.ReadLine

	If strComputer <> "" Then

		If strComputer = "." Then strComputer = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

		WScript.Echo VbCrLf & "================================" & VbCrLf & strComputer & VbCrLf & "================================"

		If Ping(strComputer) = True Then

			On Error Resume Next

			Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2")

			Set objDisks = objWMIService.ExecQuery("SELECT DeviceID,Size FROM Win32_DiskDrive")

			If Err.Number = 0 Then

				On Error GoTo 0

				For Each objDisk In objDisks

					strDrive = "Disk #" & Mid(objDisk.DeviceID, InStr(objDisk.DeviceID, "DRIVE") + 5)

					objDrives.AddNew

					objDrives("Drive") = strDrive

					objDrives("Size") = objDisk.Size

					objDrives.Update

					'WScript.Echo strDrive & ": " & objDisk.Size

				Next

	

				Set objPhysicalDisks = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDriveToDiskPartition")

				For Each objPhysicalDisk In objPhysicalDisks

					strPhysicalDetail = Mid(objPhysicalDisk.Dependent, InStrRev(objPhysicalDisk.Dependent, "=") + 2)

					strPhysicalDetail = Left(strPhysicalDetail, InStr(strPhysicalDetail, """") - 1)

					strPhysicalDrive = Trim(Split(strPhysicalDetail, ",")(0))

					strPhysicalPartition = Trim(Split(strPhysicalDetail, ",")(1))

					objPartitions.AddNew

					objPartitions("Drive") = strPhysicalDrive

					objPartitions("Partition") = strPhysicalPartition

					objPartitions.Update

					'WScript.Echo strPhysicalDrive & VbCrLf & strPhysicalPartition

				Next

	

				Set objLogicalDisks = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDiskToPartition")

				For Each objLogicalDisk In objLogicalDisks

					strLogicalDetail = Mid(objLogicalDisk.Antecedent, InStrRev(objLogicalDisk.Antecedent, "=") + 2)

					strLogicalDetail = Left(strLogicalDetail, InStr(strLogicalDetail, """") - 1)

					strLogicalDrive = Trim(Split(strLogicalDetail, ",")(0))

					strLogicalPartition = Trim(Split(strLogicalDetail, ",")(1))

					strLogicalDriveLetter = Mid(objLogicalDisk.Dependent, InStrRev(objLogicalDisk.Dependent, "=") + 2)

					strLogicalDriveLetter = Left(strLogicalDriveLetter, InStr(strLogicalDriveLetter, """") - 1)

					objPartitions.Filter = "Drive='" & strLogicalDrive & "' AND Partition='" & strLogicalPartition & "'"

					If objPartitions.EOF = False Then

						objPartitions("DriveLetter") = strLogicalDriveLetter

					End If

					'WScript.Echo strLogicalDrive & VbCrLf & strLogicalPartition & VbCrLf & strLogicalDriveLetter

				Next

				

				objPartitions.Filter = ""

				If Not objPartitions.EOF Then objPartitions.MoveFirst

				While Not objPartitions.EOF

					Set objLocalPartitions = objWMIService.ExecQuery("SELECT * FROM Win32_DiskPartition WHERE DeviceID='" & objPartitions("Drive") & ", " & objPartitions("Partition") & "'")

					For Each objLocalPartition In objLocalPartitions

						objPartitions("Size") = objLocalPartition.Size

					Next

					objPartitions.MoveNext

				Wend

				

				objDrives.Filter = ""

				If Not objDrives.EOF Then objDrives.MoveFirst

				WScript.Echo VbCrLf & "Physical Drives:" & VbCrLf

				While Not objDrives.EOF

					WScript.Echo "Drive: " & objDrives("Drive") & VbCrLf & _

						"Size: " & CDbl(objDrives("Size")) / 1024 / 1024 / 1024 & " GB"

					objPartitions.Filter = "Drive='" & objDrives("Drive") & "'"

					If Not objPartitions.EOF Then objPartitions.MoveFirst

					WScript.Echo VbCrLf & "Logical Drives:" & VbCrLf

					intTotalSize = 0

					While Not objPartitions.EOF

						WScript.Echo "Drive: " & objPartitions("Drive") & VbCrLf & _

							"Partition: " & objPartitions("Partition") & VbCrLf & _

							"DriveLetter: " & objPartitions("DriveLetter") & VbCrLf & _

							"Size: " & CDbl(objPartitions("Size")) / 1024 / 1024 / 1024 & " GB"

						'WScript.Echo TypeName(CLng(objPartitions("Size"))) & VbCrLf & TypeName(intTotalSize)

						intTotalSize = CDbl(intTotalSize) + CDbl(objPartitions("Size"))

						objPartitions.MoveNext

					Wend

					WScript.Echo "There is " & (CDbl(objDrives("Size")) - CDbl(intTotalSize)) / 1024 / 1024 / 1024 & " GB of unpartitioned space on " & objDrives("Drive")

					objDrives.MoveNext

				Wend

			Else

				Err.Clear

				On Error GoTo 0

				WScript.Echo "Unable to access " & strComputer

			End If

		Else

			WScript.Echo strComputer & " is offline."

		End If

	End If

Wend
 

WScript.Echo VbCrLf & "Finished."
 

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

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 25010346
Rob i get this... But there are no free partions in either of the machines.
I want the GB as 10 Gb free
and can i get the results to a csv file...
================================

Devn-pc1000

================================
 

Physical Drives:
 

Drive: Disk #0

Size: 149.048187732697 GB
 

Logical Drives:
 

Drive: Disk #0

Partition: Partition #0

DriveLetter: C:

Size: 29.296875 GB

Drive: Disk #0

Partition: Partition #1

DriveLetter: D:

Size: 119.7509765625 GB

There is 3.36170196533203E-04 GB of unpartitioned space on Disk #0
 

================================

Devc1001

================================
 

Physical Drives:
 

Drive: Disk #0

Size: 149.048187732697 GB
 

Logical Drives:
 

Drive: Disk #0

Partition: Partition #0

DriveLetter: C:

Size: 48.8349494934082 GB

Drive: Disk #0

Partition: Partition #1

DriveLetter: D:

Size: 100.213208198547 GB

There is 3.00407409667969E-05 GB of unpartitioned space on Disk #0

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 25010371
When you've got
3.36170196533203E-04 GB

the E-04 on the end means that the decimal point should be four places further left, like
0.000336170196533203

that's the way the scientific notation works.  So for the above, there's 0.000336170196533203 GB of free space, which is about 0.344 if a MB, or about 352 kilobytes, which is not much at all!

I will try to round off the numbers later....I have to go out for a bit now.

Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 25010913
This is now rounded to three decimal places....

The output doesn't really work as a CSV file, because it's got details based on the physical disk as a whole, and the partitions of that disk, so it doesn't really work in columns....

Regards,

Rob.
Set objShell = CreateObject("Wscript.Shell")

If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then

    strPath = Wscript.ScriptFullName

    strCommand = "%comspec% /k cscript  """ & strPath & """"

    objShell.Run(strCommand), 1, True

    Wscript.Quit

End If
 

strComputers = "computers.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Const intForReading = 1

Set objFile = objFSO.OpenTextFile(strComputers, intForReading, False)
 

Const adVarChar = 200

Const adBigInt = 20

Const MaxCharacters = 255
 

While Not objFile.AtEndOfStream

	Set objDrives = CreateObject("ADOR.Recordset")

	objDrives.Fields.Append "Drive", adVarChar, MaxCharacters

	objDrives.Fields.Append "Size", adBigInt

	objDrives.Open

		

	Set objPartitions = CreateObject("ADOR.Recordset")

	objPartitions.Fields.Append "Drive", adVarChar, MaxCharacters

	objPartitions.Fields.Append "Partition", adVarChar, MaxCharacters

	objPartitions.Fields.Append "DriveLetter", adVarChar, MaxCharacters

	objPartitions.Fields.Append "Size", adBigInt

	objPartitions.Open

	

	'strComputer = InputBox("Enter remote computer name:", "Computer Name", "D1KYSZ1SRING")

	strComputer = objFile.ReadLine

	If strComputer <> "" Then

		If strComputer = "." Then strComputer = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

		WScript.Echo VbCrLf & "================================" & VbCrLf & strComputer & VbCrLf & "================================"

		If Ping(strComputer) = True Then

			On Error Resume Next

			Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2")

			Set objDisks = objWMIService.ExecQuery("SELECT DeviceID,Size FROM Win32_DiskDrive")

			If Err.Number = 0 Then

				On Error GoTo 0

				For Each objDisk In objDisks

					strDrive = "Disk #" & Mid(objDisk.DeviceID, InStr(objDisk.DeviceID, "DRIVE") + 5)

					objDrives.AddNew

					objDrives("Drive") = strDrive

					objDrives("Size") = objDisk.Size

					objDrives.Update

					'WScript.Echo strDrive & ": " & objDisk.Size

				Next

	

				Set objPhysicalDisks = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDriveToDiskPartition")

				For Each objPhysicalDisk In objPhysicalDisks

					strPhysicalDetail = Mid(objPhysicalDisk.Dependent, InStrRev(objPhysicalDisk.Dependent, "=") + 2)

					strPhysicalDetail = Left(strPhysicalDetail, InStr(strPhysicalDetail, """") - 1)

					strPhysicalDrive = Trim(Split(strPhysicalDetail, ",")(0))

					strPhysicalPartition = Trim(Split(strPhysicalDetail, ",")(1))

					objPartitions.AddNew

					objPartitions("Drive") = strPhysicalDrive

					objPartitions("Partition") = strPhysicalPartition

					objPartitions.Update

					'WScript.Echo strPhysicalDrive & VbCrLf & strPhysicalPartition

				Next

	

				Set objLogicalDisks = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDiskToPartition")

				For Each objLogicalDisk In objLogicalDisks

					strLogicalDetail = Mid(objLogicalDisk.Antecedent, InStrRev(objLogicalDisk.Antecedent, "=") + 2)

					strLogicalDetail = Left(strLogicalDetail, InStr(strLogicalDetail, """") - 1)

					strLogicalDrive = Trim(Split(strLogicalDetail, ",")(0))

					strLogicalPartition = Trim(Split(strLogicalDetail, ",")(1))

					strLogicalDriveLetter = Mid(objLogicalDisk.Dependent, InStrRev(objLogicalDisk.Dependent, "=") + 2)

					strLogicalDriveLetter = Left(strLogicalDriveLetter, InStr(strLogicalDriveLetter, """") - 1)

					objPartitions.Filter = "Drive='" & strLogicalDrive & "' AND Partition='" & strLogicalPartition & "'"

					If objPartitions.EOF = False Then

						objPartitions("DriveLetter") = strLogicalDriveLetter

					End If

					'WScript.Echo strLogicalDrive & VbCrLf & strLogicalPartition & VbCrLf & strLogicalDriveLetter

				Next

				

				objPartitions.Filter = ""

				If Not objPartitions.EOF Then objPartitions.MoveFirst

				While Not objPartitions.EOF

					Set objLocalPartitions = objWMIService.ExecQuery("SELECT * FROM Win32_DiskPartition WHERE DeviceID='" & objPartitions("Drive") & ", " & objPartitions("Partition") & "'")

					For Each objLocalPartition In objLocalPartitions

						objPartitions("Size") = objLocalPartition.Size

					Next

					objPartitions.MoveNext

				Wend

				

				objDrives.Filter = ""

				If Not objDrives.EOF Then objDrives.MoveFirst

				WScript.Echo VbCrLf & "Physical Drives:" & VbCrLf

				While Not objDrives.EOF

					WScript.Echo "Drive: " & objDrives("Drive") & VbCrLf & _

						"Size: " & Round(CDbl(objDrives("Size")) / 1024 / 1024 / 1024, 3) & " GB"

					objPartitions.Filter = "Drive='" & objDrives("Drive") & "'"

					If Not objPartitions.EOF Then objPartitions.MoveFirst

					WScript.Echo VbCrLf & "Logical Drives:" & VbCrLf

					intTotalSize = 0

					While Not objPartitions.EOF

						WScript.Echo "Drive: " & objPartitions("Drive") & VbCrLf & _

							"Partition: " & objPartitions("Partition") & VbCrLf & _

							"DriveLetter: " & objPartitions("DriveLetter") & VbCrLf & _

							"Size: " & Round(CDbl(objPartitions("Size")) / 1024 / 1024 / 1024, 3) & " GB"

						'WScript.Echo TypeName(CLng(objPartitions("Size"))) & VbCrLf & TypeName(intTotalSize)

						intTotalSize = Round(CDbl(intTotalSize) + CDbl(objPartitions("Size")), 3)

						objPartitions.MoveNext

					Wend

					WScript.Echo "There is " & Round((CDbl(objDrives("Size")) - CDbl(intTotalSize)) / 1024 / 1024 / 1024, 3) & " GB of unpartitioned space on " & objDrives("Drive")

					objDrives.MoveNext

				Wend

			Else

				Err.Clear

				On Error GoTo 0

				WScript.Echo "Unable to access " & strComputer

			End If

		Else

			WScript.Echo strComputer & " is offline."

		End If

	End If

Wend
 

WScript.Echo VbCrLf & "Finished."
 

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

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 25010927
Rob i get this


Physical Drives:

Drive: Disk #0
Size: 465.759 GB

Logical Drives:

Drive: Disk #0
Partition: Partition #0
DriveLetter: C:
Size: 19.534 GB
Drive: Disk #0
Partition: Partition #1
DriveLetter: E:
Size: 446.225 GB
There is 0 GB of unpartitioned space on Disk #0

I have 150 Gb of Unpartitioned space in this machine.
This is the machine where in the above i posted an image...
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 25011006
Hmmm, so it has reported that Drive E: is one partion of 446 GB, whereas Disk Management shows E: as a 300 GB, and an empty 146 GB.  What "type" of partition is the Free Space?  Or is it only "Free Space", which Disk Management now shows as its own square?

Try this....
Set objShell = CreateObject("Wscript.Shell")

If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then

    strPath = Wscript.ScriptFullName

    strCommand = "%comspec% /k cscript  """ & strPath & """"

    objShell.Run(strCommand), 1, True

    Wscript.Quit

End If
 

strComputers = "computers.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Const intForReading = 1

Set objFile = objFSO.OpenTextFile(strComputers, intForReading, False)
 

Const adVarChar = 200

Const adBigInt = 20

Const MaxCharacters = 255
 

While Not objFile.AtEndOfStream

	Set objDrives = CreateObject("ADOR.Recordset")

	objDrives.Fields.Append "Drive", adVarChar, MaxCharacters

	objDrives.Fields.Append "Size", adBigInt

	objDrives.Open

		

	Set objPartitions = CreateObject("ADOR.Recordset")

	objPartitions.Fields.Append "Drive", adVarChar, MaxCharacters

	objPartitions.Fields.Append "Partition", adVarChar, MaxCharacters

	objPartitions.Fields.Append "DriveLetter", adVarChar, MaxCharacters

	objPartitions.Fields.Append "Size", adBigInt

	objPartitions.Fields.Append "FreeSpace", adBigInt

	objPartitions.Open

	

	'strComputer = InputBox("Enter remote computer name:", "Computer Name", "D1KYSZ1SRING")

	strComputer = objFile.ReadLine

	If strComputer <> "" Then

		If strComputer = "." Then strComputer = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

		WScript.Echo VbCrLf & "================================" & VbCrLf & strComputer & VbCrLf & "================================"

		If Ping(strComputer) = True Then

			On Error Resume Next

			Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\CIMV2")

			Set objDisks = objWMIService.ExecQuery("SELECT DeviceID,Size FROM Win32_DiskDrive")

			If Err.Number = 0 Then

				On Error GoTo 0

				For Each objDisk In objDisks

					strDrive = "Disk #" & Mid(objDisk.DeviceID, InStr(objDisk.DeviceID, "DRIVE") + 5)

					objDrives.AddNew

					objDrives("Drive") = strDrive

					objDrives("Size") = objDisk.Size

					objDrives.Update

					'WScript.Echo strDrive & ": " & objDisk.Size

				Next

	

				Set objPhysicalDisks = objWMIService.ExecQuery("SELECT * FROM Win32_DiskDriveToDiskPartition")

				For Each objPhysicalDisk In objPhysicalDisks

					strPhysicalDetail = Mid(objPhysicalDisk.Dependent, InStrRev(objPhysicalDisk.Dependent, "=") + 2)

					strPhysicalDetail = Left(strPhysicalDetail, InStr(strPhysicalDetail, """") - 1)

					strPhysicalDrive = Trim(Split(strPhysicalDetail, ",")(0))

					strPhysicalPartition = Trim(Split(strPhysicalDetail, ",")(1))

					objPartitions.AddNew

					objPartitions("Drive") = strPhysicalDrive

					objPartitions("Partition") = strPhysicalPartition

					objPartitions.Update

					'WScript.Echo strPhysicalDrive & VbCrLf & strPhysicalPartition

				Next

	

				Set objLogicalDisks = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDiskToPartition")

				For Each objLogicalDisk In objLogicalDisks

					strLogicalDetail = Mid(objLogicalDisk.Antecedent, InStrRev(objLogicalDisk.Antecedent, "=") + 2)

					strLogicalDetail = Left(strLogicalDetail, InStr(strLogicalDetail, """") - 1)

					strLogicalDrive = Trim(Split(strLogicalDetail, ",")(0))

					strLogicalPartition = Trim(Split(strLogicalDetail, ",")(1))

					strLogicalDriveLetter = Mid(objLogicalDisk.Dependent, InStrRev(objLogicalDisk.Dependent, "=") + 2)

					strLogicalDriveLetter = Left(strLogicalDriveLetter, InStr(strLogicalDriveLetter, """") - 1)

					objPartitions.Filter = "Drive='" & strLogicalDrive & "' AND Partition='" & strLogicalPartition & "'"

					If objPartitions.EOF = False Then

						objPartitions("DriveLetter") = strLogicalDriveLetter

						Set objFreeSpace = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk Where DriveType = 3 And DeviceID ='" & strLogicalDriveLetter & "'")

						For Each objFreeSpaceDisk In objFreeSpace

							objPartitions("FreeSpace") = objFreeSpaceDisk.FreeSpace

						Next

					End If

					'WScript.Echo strLogicalDrive & VbCrLf & strLogicalPartition & VbCrLf & strLogicalDriveLetter

				Next

				

				objPartitions.Filter = ""

				If Not objPartitions.EOF Then objPartitions.MoveFirst

				While Not objPartitions.EOF

					Set objLocalPartitions = objWMIService.ExecQuery("SELECT * FROM Win32_DiskPartition WHERE DeviceID='" & objPartitions("Drive") & ", " & objPartitions("Partition") & "'")

					For Each objLocalPartition In objLocalPartitions

						objPartitions("Size") = objLocalPartition.Size

					Next

					objPartitions.MoveNext

				Wend

				

				objDrives.Filter = ""

				If Not objDrives.EOF Then objDrives.MoveFirst

				WScript.Echo VbCrLf & "Physical Drives:" & VbCrLf

				While Not objDrives.EOF

					WScript.Echo "Drive: " & objDrives("Drive") & VbCrLf & _

						"Size: " & Round(CDbl(objDrives("Size")) / 1024 / 1024 / 1024, 3) & " GB"

					objPartitions.Filter = "Drive='" & objDrives("Drive") & "'"

					If Not objPartitions.EOF Then objPartitions.MoveFirst

					WScript.Echo VbCrLf & "Logical Drives:" & VbCrLf

					intTotalSize = 0

					While Not objPartitions.EOF

						WScript.Echo "Drive: " & objPartitions("Drive") & VbCrLf & _

							"Partition: " & objPartitions("Partition") & VbCrLf & _

							"DriveLetter: " & objPartitions("DriveLetter") & VbCrLf & _

							"Size: " & Round(CDbl(objPartitions("Size")) / 1024 / 1024 / 1024, 3) & " GB" & VbCrLf & _

							"FreeSpace: " & Round(CDbl(objPartitions("FreeSpace")) / 1024 / 1024 / 1024, 3) & " GB"

						'WScript.Echo TypeName(CLng(objPartitions("Size"))) & VbCrLf & TypeName(intTotalSize)

						intTotalSize = Round(CDbl(intTotalSize) + CDbl(objPartitions("Size")), 3)

						objPartitions.MoveNext

					Wend

					WScript.Echo "There is " & Round((CDbl(objDrives("Size")) - CDbl(intTotalSize)) / 1024 / 1024 / 1024, 3) & " GB of unpartitioned space on " & objDrives("Drive")

					objDrives.MoveNext

				Wend

			Else

				Err.Clear

				On Error GoTo 0

				WScript.Echo "Unable to access " & strComputer

			End If

		Else

			WScript.Echo strComputer & " is offline."

		End If

	End If

Wend
 

WScript.Echo VbCrLf & "Finished."
 

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

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 25011023
I Get this now


Physical Drives:

Drive: Disk #0
Size: 465.759 GB

Logical Drives:

Drive: Disk #0
Partition: Partition #0
DriveLetter: C:
Size: 19.534 GB
FreeSpace: 12.104 GB
Drive: Disk #0
Partition: Partition #1
DriveLetter: E:
Size: 446.225 GB
FreeSpace: 174.172 GB
There is 0 GB of unpartitioned space on Disk #0

Finished.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 25011085
Is the free space shown in Disk Managmenet in your screenshot actually a partition? If so, what "type" of partition is it?
0
 
LVL 11

Author Comment

by:bsharath
ID: 25011113
Now it looks as "Healthy" no drive letter assigned...

2 stages
1. No partition created or no drive letter
2. Partition created and formatted but no drive letter
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 25011163
Wow, that's weird....

1. No partition created or no drive letter
For this I would expect my above code to show
There is 146 GB of unpartitioned space on Disk #0

2. Partition created and formatted but no drive letter
For this I would expect my above code to show
Drive: Disk #0
Partition: Partition #2
DriveLetter:
Size:146 GB

where the DriveLetter is blank.

I'm not sure why it wouldn't work that way.....If you run the code below and enter that computer name, what output do you get?

Rob.
Set objShell = CreateObject("Wscript.Shell")

If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then

    strPath = Wscript.ScriptFullName

    strCommand = "%comspec% /k cscript  """ & strPath & """"

    objShell.Run(strCommand), 1, True

    Wscript.Quit

End If
 

On Error Resume Next
 

Const wbemFlagReturnImmediately = &h10

Const wbemFlagForwardOnly = &h20
 

strComputer = InputBox("Enter computer name:", "Computer Name")

   WScript.Echo

   WScript.Echo "=========================================="

   WScript.Echo "Computer: " & strComputer

   WScript.Echo "=========================================="
 

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DiskPartition", "WQL", _

                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
 

   For Each objItem In colItems

      WScript.Echo "Access: " & objItem.Access

      WScript.Echo "Availability: " & objItem.Availability

      WScript.Echo "BlockSize: " & objItem.BlockSize

      WScript.Echo "Bootable: " & objItem.Bootable

      WScript.Echo "BootPartition: " & objItem.BootPartition

      WScript.Echo "Caption: " & objItem.Caption

      WScript.Echo "ConfigManagerErrorCode: " & objItem.ConfigManagerErrorCode

      WScript.Echo "ConfigManagerUserConfig: " & objItem.ConfigManagerUserConfig

      WScript.Echo "CreationClassName: " & objItem.CreationClassName

      WScript.Echo "Description: " & objItem.Description

      WScript.Echo "DeviceID: " & objItem.DeviceID

      WScript.Echo "DiskIndex: " & objItem.DiskIndex

      WScript.Echo "ErrorCleared: " & objItem.ErrorCleared

      WScript.Echo "ErrorDescription: " & objItem.ErrorDescription

      WScript.Echo "ErrorMethodology: " & objItem.ErrorMethodology

      WScript.Echo "HiddenSectors: " & objItem.HiddenSectors

      WScript.Echo "Index: " & objItem.Index

      WScript.Echo "InstallDate: " & WMIDateStringToDate(objItem.InstallDate)

      WScript.Echo "LastErrorCode: " & objItem.LastErrorCode

      WScript.Echo "Name: " & objItem.Name

      WScript.Echo "NumberOfBlocks: " & objItem.NumberOfBlocks

      WScript.Echo "PNPDeviceID: " & objItem.PNPDeviceID

      strPowerManagementCapabilities = Join(objItem.PowerManagementCapabilities, ",")

         WScript.Echo "PowerManagementCapabilities: " & strPowerManagementCapabilities

      WScript.Echo "PowerManagementSupported: " & objItem.PowerManagementSupported

      WScript.Echo "PrimaryPartition: " & objItem.PrimaryPartition

      WScript.Echo "Purpose: " & objItem.Purpose

      WScript.Echo "RewritePartition: " & objItem.RewritePartition

      WScript.Echo "Size: " & objItem.Size

      WScript.Echo "StartingOffset: " & objItem.StartingOffset

      WScript.Echo "Status: " & objItem.Status

      WScript.Echo "StatusInfo: " & objItem.StatusInfo

      WScript.Echo "SystemCreationClassName: " & objItem.SystemCreationClassName

      WScript.Echo "SystemName: " & objItem.SystemName

      WScript.Echo "Type: " & objItem.Type

      WScript.Echo

   Next
 
 

Function WMIDateStringToDate(dtmDate)

WScript.Echo dtm: 

	WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _

	Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _

	& " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))

End Function

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 25011176
Also, what OS is that machine?  This article says that Win32_DiskPartition does not return the extended partition info if there is an incorrect file on the system.
http://support.microsoft.com/kb/824024

Rob.
0
 
LVL 11

Author Comment

by:bsharath
ID: 25011200
Hi Rob i get this

I have Xp and Win 2003 machines
==========================================

Access:

Availability:

BlockSize: 512

Bootable: True

BootPartition: True

Caption: Disk #0, Partition #0

ConfigManagerErrorCode:

ConfigManagerUserConfig:

CreationClassName: Win32_DiskPartition

Description: Installable File System

DeviceID: Disk #0, Partition #0

DiskIndex: 0

ErrorCleared:

ErrorDescription:

ErrorMethodology:

HiddenSectors:

Index: 0
 

LastErrorCode:

Name: Disk #0, Partition #0

NumberOfBlocks: 40965687

PNPDeviceID:

PowerManagementCapabilities:

PowerManagementSupported:

PrimaryPartition: True

Purpose:

RewritePartition:

Size: 20974431744

StartingOffset: 32256

Status:

StatusInfo:

SystemCreationClassName: Win32_ComputerSystem

SystemName: IN-nil-FS01

Type: Installable File System
 

Access:

Availability:

BlockSize: 512

Bootable:

BootPartition: False

Caption: Disk #0, Partition #1

ConfigManagerErrorCode:

ConfigManagerUserConfig:

CreationClassName: Win32_DiskPartition

Description: Extended w/Extended Int 13

DeviceID: Disk #0, Partition #1

DiskIndex: 0

ErrorCleared:

ErrorDescription:

ErrorMethodology:

HiddenSectors:

Index: 1
 

LastErrorCode:

Name: Disk #0, Partition #1

NumberOfBlocks: 935802315

PNPDeviceID:

PowerManagementCapabilities:

PowerManagementSupported:

PrimaryPartition: False

Purpose:

RewritePartition:

Size: 479130785280

StartingOffset: 20974464000

Status:

StatusInfo:

SystemCreationClassName: Win32_ComputerSystem

SystemName: IN-nil-FS01

Type: Extended w/Extended Int 13

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 25066208
Hi Rob any views....
0
 
LVL 11

Author Comment

by:bsharath
ID: 25189106
Hi Rob any views...
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now