P
Pal
Hi,
I wrote a simple script to populate a word document with the free space
of my servers and wanted to make it stand out (large font & red) if the
value is less 15%. The code works but everything (just in column 4)
becomes large & red after the first instance of the space being less
than 15%. What is the error? - Thanks
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objRange = objDoc.Range()
objDoc.Tables.Add objRange,1,4
Set objTable = objDoc.Tables(1)
x=1
objTable.Cell(x,1).Range.Font.Bold = True
objTable.Cell(x, 1).Range.Text = "Server Name:"
objTable.Cell(x, 2).Range.Text = "Drive Name: "
objTable.Cell(x, 3).Range.Text = "Free Space: (MB)"
objTable.Cell(x, 4).Range.Text = "PercentFreeSpace: (%)"
x = x + 1
'ServerName = "."
Dim Servers(8)
Servers(0)="A"
Servers(1)="B"
Servers(2)="C"
Servers(3)="D"
Servers(4)="E"
Servers(5)="F"
Servers(6)="G"
Servers(7)="H"
Servers(8)="I"
For each ServerName in Servers
'wscript.echo ServerName
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & ServerName &
"\root\cimv2")
Set colDiskDrives = objWMIService.ExecQuery _
("Select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk Where "
_
& "Name <> '_Total'")
For Each objDiskDrive in colDiskDrives
If x > 1 Then
objTable.Rows.Add()
End If
objTable.Cell(x, 1).Range.Text = ServerName
objTable.Cell(x, 2).Range.text = objDiskDrive.Name
objTable.Cell(x, 3).Range.text = objDiskDrive.FreeMegabytes
If objDiskDrive.PercentFreeSpace < 20 Then
With objTable.Cell(x, 4)
.Range.Font.Size = 35
.Range.Font.ColorIndex = 6
.Range.text = objDiskDrive.PercentFreeSpace
End With
Else
objTable.Cell(x, 4).Range.text = objDiskDrive.PercentFreeSpace
End If
x = x + 1
Next
Next
I wrote a simple script to populate a word document with the free space
of my servers and wanted to make it stand out (large font & red) if the
value is less 15%. The code works but everything (just in column 4)
becomes large & red after the first instance of the space being less
than 15%. What is the error? - Thanks
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objRange = objDoc.Range()
objDoc.Tables.Add objRange,1,4
Set objTable = objDoc.Tables(1)
x=1
objTable.Cell(x,1).Range.Font.Bold = True
objTable.Cell(x, 1).Range.Text = "Server Name:"
objTable.Cell(x, 2).Range.Text = "Drive Name: "
objTable.Cell(x, 3).Range.Text = "Free Space: (MB)"
objTable.Cell(x, 4).Range.Text = "PercentFreeSpace: (%)"
x = x + 1
'ServerName = "."
Dim Servers(8)
Servers(0)="A"
Servers(1)="B"
Servers(2)="C"
Servers(3)="D"
Servers(4)="E"
Servers(5)="F"
Servers(6)="G"
Servers(7)="H"
Servers(8)="I"
For each ServerName in Servers
'wscript.echo ServerName
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & ServerName &
"\root\cimv2")
Set colDiskDrives = objWMIService.ExecQuery _
("Select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk Where "
_
& "Name <> '_Total'")
For Each objDiskDrive in colDiskDrives
If x > 1 Then
objTable.Rows.Add()
End If
objTable.Cell(x, 1).Range.Text = ServerName
objTable.Cell(x, 2).Range.text = objDiskDrive.Name
objTable.Cell(x, 3).Range.text = objDiskDrive.FreeMegabytes
If objDiskDrive.PercentFreeSpace < 20 Then
With objTable.Cell(x, 4)
.Range.Font.Size = 35
.Range.Font.ColorIndex = 6
.Range.text = objDiskDrive.PercentFreeSpace
End With
Else
objTable.Cell(x, 4).Range.text = objDiskDrive.PercentFreeSpace
End If
x = x + 1
Next
Next