简体   繁体   中英

Powershell Disk Space Check

Trying to export details from a list of servers to excel, including the disk space and free space i would also like to add a the % (Percentfree) left but i am very new to powershell and having trouble getting the syntax correct..

$ServerList = "######"


$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add()

$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1) = “Computer”
$Sheet.Cells.Item(1,2) = “Drive Letter”
$Sheet.Cells.Item(1,3) = “Description”
$Sheet.Cells.Item(1,4) = “File System”
$Sheet.Cells.Item(1,5) = “Size in GB”
$Sheet.Cells.Item(1,6) = “Free Space in GB”
$Sheet.Cells.Item(1,7) = “Percent Free GB”

$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 8
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True

$intRow = 2
$colItems = Get-wmiObject Win32_LogicalDisk -computername $ServerList

foreach ($objItem in $colItems) {
$Sheet.Cells.Item($intRow,1) = $objItem.SystemName
$Sheet.Cells.Item($intRow,2) = $objItem.DeviceID
$Sheet.Cells.Item($intRow,3) = $ojbItem.Description
$Sheet.Cells.Item($intRow,4) = $objItem.FileSystem
$Sheet.Cells.Item($intRow,5) = $objItem.Size / 1GB
$Sheet.Cells.Item($intRow,6) = $objItem.FreeSpace / 1GB  


$intRow = $intRow + 1

}
 $WorkBook.EntireColumn.AutoFit()
 Clear

If I understand you correctly, you're trying to build the expression that calculates the percentage free.

Try this:

$Sheet.Cells.Item($intRow,7) = [MATH]::Round(($objItem.FreeSpace / 1gb) / ($objItem.Size / 1gb),4) * 100

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM