【问题标题】:Get disk informations without using WMI不使用 WMI 获取磁盘信息
【发布时间】:2019-02-18 15:57:47
【问题描述】:

我使用 check_mk 作为监控解决方案,并且我禁用了 WMI 服务,导致它在 check_mk 查询信息时创建超时。

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

你知道有什么解决方法吗?

【问题讨论】:

  • PInvoke win32 API?编写您自己的 c#/c++ 应用程序,生成可消耗的输出,如 json、xml、csv 等。
  • 重新启用 WMI 服务并修复导致超时的任何问题。

标签: powershell wmi


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-08
    • 2012-08-28
    • 1970-01-01
    • 2015-01-19
    • 2012-10-27
    • 2019-08-06
    相关资源
    最近更新 更多