当我在 powershell 中运行此命令时,我没有得到任何响应。我必须终止 powershell,因为查询一旦完成就无法取消。
Get-WMIObject -query 'SELECT * from Win32_UserAccount'
可以采取哪些步骤来了解发生这种情况的原因?
谢谢!
最佳答案
对于大多数命令,我建议添加 -Verbose
,但我认为 Get-WMIObject
不会在该流上输出很多有用的信息。
至于它挂起的原因,请记住该命令将枚举您域中的每个 用户帐户(而不仅仅是本地计算机)。如果您在大型网络上运行它,则需要一些时间。即使是我的约 800 个用户对象的小型网络也需要 15 秒才能运行。
如果你在一个大网络上......让它运行,它可能需要一段时间。
guidance from Microsoft关于这个类是:
Note Because both the Name and Domain are key properties, enumerating Win32_UserAccount on a large network can negatively affect performance. Calling GetObject or querying for a specific instance has less impact.
它仍然需要很长时间才能运行,但 CIM 版本的速度稍快(12.5 秒而不是我的 15 秒):
Get-CimInstance -ClassName Win32_UserAccount
或者,如果您想坚持使用查询格式:
Get-CimInstance -Query 'SELECT * from Win32_UserAccount'
关于windows - WMI 查询正在停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46656748/