Improved Function: Get-ComputerDetail

Fellow coders, I received some great feedback from our honorary scripting guru’s Mike F. Robbins and Richard Siddaway about my little function (thanks guys! I’ll buy you a drink when we meet! 😉 ).

With their feedback I managed to improve my simple function. And that’s so great about being part of a community; people are always willing to help.

3 thoughts on “Improved Function: Get-ComputerDetail

  1. Steve G

    One more suggested mod. This will process everything in the list, and then print out all the errors at the end of the run.

    Function Get-ComputerDetails{    [cmdletbinding()]    Param([string[]]$Computer)    $msg = ""    foreach ($node in $Computer)    {        try        {            $sys = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $node -ErrorAction Stop            $bios = Get-WmiObject -Class Win32_Bios -ComputerName $node -ErrorAction Stop            [pscustomobject][ordered]@{                Name         = $sys.Name                Manufacturer = $sys.Manufacturer                Model        = $sys.Model                Serial       = $bios.SerialNumber            }        }        catch        {            $msg += "The command failed for computer $node. Message: $_.Exception.Message[crayon-600bdc3ae894c345792267 inline="true" ]rn”
    if (“” -ne $msg) { Write-Error -Message $msg }

Comments are closed.