0
這是一些較大腳本的修改部分,當F驅動器上沒有足夠的磁盤空間以適應C驅動器中的映像時,該腳本將刪除舊的VHD映像。Windows PowerShell磁盤空間不足腳本
function DiskSpace() {
$Cdisk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace
$Fdisk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='F:'" | Select-Object Size,FreeSpace
$CdiskCapacity = $Cdisk.size/1073741824
$CdiskFree = $Cdisk.freespace/1073741824
$CdiskUSed = $CdiskCapacity-$CDiskFree
$fdisk = $fdisk.freespace/1073741824
return $Fdisk, $cdiskUsed
}
if ($fdisk -gt $cdiskfree) {
write-host "Lot's of space on F: Drive"
}
diskspace
儘管它顯示F驅動器上有超過1.1TB - 它不顯示我的消息。
PS C:\Users\Marek> C:\backup2.ps1
1153,06732559204
221,418087005615
怎麼了?
你做了很多額外的工作,簡化了在那裏你可以像'$ CdiskUsed =($ Cdisk.Size - $ Cdisk。自由空間)/ 1gb' – TheMadTechnician