Add Member to ManagementObject

This topic contains 2 replies, has 2 voices, and was last updated by  kort3x 1 year ago.

  • Author
  • #70579


    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.

  • #70583

    Rob Simmers

    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}}
    • #70585


      Thank you!

You must be logged in to reply to this topic.