在不使用WMI的情况下获取磁盘信息

时间:2019-02-18 15:57:48

标签: powershell wmi

我正在使用check_mk作为监视解决方案,并且我禁用了WMI服务,因为当check_mk查询信息时,WMI服务会导致超时。

Get-WmiObject / Get-Disk / Get-PSDrive使用WMI服务来获取信息,而我想在不使用WMI的情况下获取诸如总空间,已用空间等磁盘信息,因为我不能。

您知道对此有任何解决方法吗?

1 个答案:

答案 0 :(得分:0)

TL; DR-

(echo select disk=0 & echo list partition & (for /l %A in (1,1,10) do @echo select disk=next &@echo list partition)) | diskpart | findstr /i /v /r "^$ > microsoft ^reached ^select ^there ^the\ start"

详细信息-

“ diskpart.exe”命令可以为您提供所需的信息。它需要管理员权限,但是由于您提到了禁用服务,这听起来不像是一个问题。

此示例将与盲目地请求前11个磁盘上的分区列表(并过滤掉不必要的行。),而不是与DISKPART的独特菜单系统进行交互。应该足够了。  :-)

命令:

(echo select disk=0 & echo list partition & (for /l %A in (1,1,10) do @echo select disk=next &@echo list partition)) | diskpart | findstr /i /v /r "^$ > microsoft ^reached ^select ^there ^the\ start"

我的实时系统的输出:

Disk 0 is now the selected disk.
  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    Primary           1863 GB  1024 KB
Disk 1 is now the selected disk.
  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    Primary            350 MB  1024 KB
  Partition 2    Primary            270 GB   351 MB
  Partition 3    Recovery           845 MB   271 GB
  Partition 4    Primary            204 GB   272 GB
Disk 2 is now the selected disk.
  Partition ###  Type              Size     Offset
  -------------  ----------------  -------  -------
  Partition 1    Primary            931 GB  1024 KB