Add Member to ManagementObject

Welcome Forums General PowerShell Q&A Add Member to ManagementObject

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 9 months ago.

  • Author
  • #70579

    Points: 38
    Rank: Member

    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

    Points: 492
    Helping Hand
    Rank: Contributor

    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

      Points: 38
      Rank: Member

      Thank you!

The topic ‘Add Member to ManagementObject’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort