【发布时间】:2017-01-31 10:13:20
【问题描述】:
以下powershell获取计算机系统信息的对象:
> $o = Get-WmiObject -Class Win32_ComputerSystem -ComputerName .
> $o
# output
# Domain : somedomain.com
# Manufacturer : VMware, Inc.
# Model : VMware Virtual Platform
# Name : MYSERVER
# PrimaryOwnerName : Windows User
# TotalPhysicalMemory : 17179332608
我给对象$o添加了一个新成员TotalPhysicalMemoryGB,如下:
> $o = Add-Member -Input $o @{TotalPhysicalMemoryGB=([math]::round($t.TotalPhysicalMemory / 1GB))} -PassThru
这似乎可行,因为我可以访问该成员:
> $o.TotalPhysicalMemoryGB
# output
# 16
但是,当我再次打印整个对象时,成员TotalPhysicalMemoryGB 并没有出现在成员列表中:
> $o
# output
# Domain : somedomain.com
# Manufacturer : VMware, Inc.
# Model : VMware Virtual Platform
# Name : MYSERVER
# PrimaryOwnerName : Windows User
# TotalPhysicalMemory : 17179332608
我做错了什么?打印$o时如何获取新成员?
【问题讨论】:
标签: powershell wmi windows-server-2012 powershell-5.0 get-wmiobject