无法在 WMI 类“DateTime”属性中插入数据

问题描述

我在 WMI 类中声明属性“InstallDate”,如下所示:

$newClass.Properties.Add("InstallDate",[System.Management.CimType]::DateTime,$false)
$newClass.Properties["InstallDate"].Qualifiers.Add("Key",$true)

然后我使用以下 cmdlet 从注册获取 InstallDate:

$Win10Upgrade = Get-ChildItem -Path HKLM:\System\Setup\Source* | ForEach-Object {Get-ItemProperty -Path Registry::$_} | Select @{n="InstallDate"; e={([DateTime]'1/1/1970').AddSeconds($_.InstallDate)}}

然后我试图将它插入 WMI 类 CM_Win10UpgradeHistory 到声明的“InstallDate”属性中。

Set-WmiInstance -Class CM_Win10UpgradeHistory -Namespace ROOT\CustomSCCMInventory -Arguments @{InstallDate=$Win10Upgrade.InstallDate} -ErrorAction SilentlyContinue | Out-Null

注册表中 InstallDate 的原始值为“1573146514” powershell中的DateTime操作将其更改为“11/7/2019 5:08:34 PM”

但是我收到了“Set-WmiInstance:类型不匹配”的错误。 我也尝试插入原始值,但它也给出了同样的错误。如果我将 WMI 类属性值解密为“String”而不是“DateTime”,我可以插入它

对此的任何帮助表示赞赏。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)