简体   繁体   English

如何知道哪个分区未分配空间可用? (Powershell或Command)

[英]How to know, After which Partition unallocated space is available ? (Powershell or Command)

I am trying to use Command or PowerShell to know where on a disk unallocated space is available. 我试图使用Command或PowerShell来了解磁盘上未分配空间的可用位置。

For example below the unallocated space is present after G: drive (or Partition 1). 例如,下面的G:驱动器(或分区1)之后存在未分配的空间。

Using the command echo list disk | diskpart 使用命令echo list disk | diskpart echo list disk | diskpart I can only know the Unallocated space. echo list disk | diskpart我只能知道未分配的空间。

在此处输入图片说明

Is there any way to know this information? 有什么办法知道这些信息吗?

Solution for Windows 8/2012 Server or newer: Windows 8/2012 Server或更高版本的解决方案:

I think you could do this (needs to be run with Administrator rights) to return an object with each volume that can be extended (from which you can then deduce there is free space after the volume): 我认为您可以执行此操作(需要以管理员权限运行)以返回具有每个可扩展卷的对象(然后可以从中推断出该卷之后有可用空间):

Get-Volume | Where DriveLetter -ne $null | ForEach-Object {
    $Size = Get-PartitionSupportedSize -DriveLetter $_.DriveLetter
    If ($Size.SizeMax -gt $_.Size) { $_ }
}
  • Get-Volume | Where DriveLetter -ne $null Get-Volume | Where DriveLetter -ne $null gets all drives that have a letter Get-Volume | Where DriveLetter -ne $null获取所有带有字母的驱动器
  • $Size = Get-PartitionSupportedSize -DriveLetter $_.DriveLetter gets the sizemin and sizemax of each drive $Size = Get-PartitionSupportedSize -DriveLetter $_.DriveLetter _。DriveLetter获取每个驱动器的sizemin和sizemax
  • If ($Size.SizeMax -gt $_.Size) { $_ } returns the volumes which can be extended (their size max is bigger than the current volume size). If ($Size.SizeMax -gt $_.Size) { $_ }返回可以扩展的卷(其大小max大于当前卷的大小)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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