如何解决快照 WMI 查询不返回任何内容
-> $VMs = Get-WmiObject -Class "Msvm_ComputerSystem" -Namespace "root\virtualization\v2"
-> $vm = $VMs[1]
-> Get-WmiObject -Namespace "root\virtualization\v2" -Query "Associators Of {$vm} Where AssocClass=Msvm_ElementSettingData ResultClass=Msvm_VirtualSystemSettingData"
我是这样使用的,但它什么都不返回。 VM 有 2 个检查点。但什么都不返回。
我知道以下命令,但需要像上面这样的查询。以下命令运行没有错误。
-> Get-VM | Get-VMSnapshot
解决方法
[注意:下面的命令都需要以管理员身份运行 Powershell。如果不是,您将始终得到零结果,IMX。]
无论我如何编写查询,我要么没有输出,要么出现错误。这似乎是此类和命名空间的一个非常常见的问题。在网上搜索发现很多人都有这个问题。 This looked like the best overall example/workaround。
从那个链接,这确实有效:
library(tidyverse)
test<-data.frame(
x=factor(rep(1:3,each=20)),y=runif(60)
)
p<-ggplot(test,aes(x=x,y=y,fill=x)) +
#Translate left
geom_boxplot(width=0.2,position = position_nudge(-0.1)) +
#Translate right
geom_dotplot(binaxis = "y",width = 0.2,position = position_nudge(x = 0.1))
p
#> `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.
我没有看到 the class documentation 中记录的 $VMs = Get-WmiObject -Namespace root\virtualization\v2 -ClassName Msvm_ComputerSystem
$VM = $VMs[1]
# This returns several results
$VM.GetRelated('Msvm_VirtualSystemSettingData')
# This returns one result
$VM.GetRelated('Msvm_VirtualSystemSettingData','Msvm_SettingsDefineState',$null,$false,$null)
方法,但我相信它是从 the ManagementObject 继承的。
也就是说,我可以使用较新的 CIM cmdlet 获得稍微不同的版本(请参阅 Powershell v5.1 或 7 上的 GetRelated()
),无论如何我都建议使用它们。 Get-Command -Module CimCmdlets
已被 Powershell v3 中的 CIM cmdlet 取代。最大的好处之一是您不再需要处理来自 WQL 的讨厌的 ASSOCIATORS OF 语法。您可以只使用 Get-WmiObject
。
Get-CimAssociatedInstance
以上对我有用。从好的方面来说,此代码也适用于没有 $VMs = Get-CimInstance -Namespace root\virtualization\v2 -ClassName Msvm_ComputerSystem
$VM = $VMs[1]
$VM | Get-CimAssociatedInstance -ResultClassName Msvm_VirtualSystemSettingData
的 Powershell v6 和 v7。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。