Help with Inventory PS Code

Welcome Forums General PowerShell Q&A Help with Inventory PS Code

Viewing 2 reply threads
  • Author
    Posts
    • #208167
      Participant
      Topics: 2
      Replies: 4
      Points: 33
      Rank: Member

      Hi,

      I can get the Hostname, Serial and Mac from the following, but wondered if there is a better way to structure the PS?

      Get-ComputerInfo | Select-Object -Property BiosSeralNumber,CSDnsHostName,{Get-NetAdapter -Name Ethernet | Select MacAddress}

      Regards

      Tony

       

    • #208185
      Participant
      Topics: 4
      Replies: 2249
      Points: 5,494
      Helping Hand
      Rank: Community MVP

      Maybe not a better structure but a probably slightly faster way as Get-ComputerInfo used to be very slow: 😉

      [PSCustomObject]@{
          BiosSerialNumber = (Get-CimInstance -ClassName Win32_BIOS).SerialNumber
          CsDNSHostName    = $ENV:COMPUTERNAME
          MacAddress       = Get-NetAdapter -Name Ethernet | Select-Object -ExpandProperty MacAddress
      }

      To learn best practices and styles you could read up The Unofficial PowerShell Best Practices and Style Guide.

      BTW: When you post code please format this as code using the code tag button named “PRE“. Thanks.

    • #208257
      Participant
      Topics: 2
      Replies: 4
      Points: 33
      Rank: Member

      Thanks Olaf, that works nicely and the output is certainly more attractive than my code.

      I will start reading through the guide, cheers for helping out here.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.