powershell - PowerShell返回类型

标签 powershell casting wmi

我正在创建一个测试应用程序以获取系统信息。

当我运行此命令

[int] $cdCodeIntTest = Get-WmiObject win32_cdromdrive | select ConfigManagerErrorCode

根据powershell程序:
它返回一个“Selected.System.Management.ManagementObject”,但是在线文档说该类型是[uint32](32位无符号整数)。

如何将错误代码转换为整数或十六进制值,以便以后可以打开该值?

最佳答案

您需要扩展属性以获取值,否则您将获得一个具有一个属性的对象(ConfigManagerErrorCode):

Get-WmiObject win32_cdromdrive | select -expand ConfigManagerErrorCode

关于powershell - PowerShell返回类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17283588/

相关文章:

windows-7 - 从 Windows 7 凭据管理器获取 PowerShell 中的缓存凭据

c++ - 使用返回值传递给构造函数不起作用

c++ - ConvertToReferencePoint 方法不起作用,作业参数为 NULL (HyperV 2016)

c++ - 使用 WMI 更改亮度

c++ - 如何在 Windows 设备管理器中获取带有黄色感叹号的设备列表 - C++

mysql - 通过PowerShell远程连接连接到MySQL

iis - 使用Powershell更改IIS6站点主目录

c++ - c++ 中的手动或自动类型转换

c# - 在 C# 中创建远程 PowerShell session ?

java - 为什么这个赋值不需要显式转换?