Author Posts

May 12, 2017 at 5:39 pm

How can I add a member to an object returned from get-wmiobject?

I expected this to work

$results.add("BIOS",$((Get-WmiObject win32_BIOS | Add-Member -MemberType NoteProperty -Name "myDate" -Value (get-date))))

but $results.bios is completly empty.

May 12, 2017 at 7:50 pm

Add-Member doesn't return anything, so the pipeline ends. Add-Member updates\modifies the object. You can see that myDate does exist in this resultset:

$bios = Get-WmiObject win32_BIOS;
$bios | Add-Member -MemberType NoteProperty -Name "myDate" -Value (get-date);
$bios | Select *

Adding the date could be accomplished with a calculated property:

Get-WmiObject -Class Win32_BIOS | Select *, @{Name="myDate";Expression={Get-Date}}

If you only need the SerialNumber and not all properties, you can also speed up and clean up your query like so:

Get-WmiObject -Class Win32_BIOS -Property SerialNumber | Select SerialNumber, @{Name="myDate";Expression={Get-Date}}