I'm currently trying to make a script to make an excel spreadsheet that will show the current amount of drive space used in MB on a server. I've adapted a script I found on the net to do this, but I'm having trouble. Here's the script:
$cred = Get-Credential ""
$erroractionpreference = "SilentlyContinue"
$a = New-Object -comobject Excel.Application
$a.visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
$c.Cells.Item(1,1) = "Machine Name"
$c.Cells.Item(1,2) = "Drive"
$c.Cells.Item(1,3) = "Data size (MB)"
$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$d.EntireColumn.AutoFit($True)
$intRow = 2
$colComputers = get-content C:\pstools\mailservers.txt
foreach ($strComputer in $colComputers)
{
$colDisks = get-wmiobject Win32_LogicalDisk -Credential $cred -computername $strComputer -Filter "DriveType = 3"
foreach ($objdisk in $colDisks)
{
$c.Cells.Item($intRow, 1) = $strComputer.ToUpper()
$c.Cells.Item($intRow, 2) = $objDisk.DeviceID
$c.Cells.Item($intRow, 3) = "{0:P0}" -f ($objDisk.Size/1MB-$objDisk.FreeSpace/1MB)
$intRow = $intRow + 1
}
}
The problem is the returns are weird large percentages that don't make any sense.
Any idea what I'm doing wrong?