none
Computer info RRS feed

  • Question

  • I have a basic script that is used to pull information from either a list, single IP, or local computer.

    it works on most of the computers on the network, but on some i get this error:

    The Error:

    Method invocation failed because [System.Object[]] does not contain a method named 'op_Division'.
    At C:\scripts\Get-systeminfo.ps1:26 char:9
    +         "HDD Capacity: "  + "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (op_Division:String) [], RuntimeException
        + FullyQualifiedErrorId : MethodNotFound
     
    Method invocation failed because [System.Object[]] does not contain a method named 'op_Division'.
    At C:\scripts\Get-systeminfo.ps1:27 char:9
    +         "HDD Space: " + "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) + ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (op_Division:String) [], RuntimeException
        + FullyQualifiedErrorId : MethodNotFound

    the script:

    # Remote System Information
    # Shows hardware and OS details from a list of PCs
    #$ArrComputers = Get-Content -Path "C:\ScriptLists\centws.txt"
    $ArrComputers = "10.123.32.8"
    # "." for local

    foreach ($Computer in $ArrComputers)
    {
        $computerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer
        $computerBIOS = get-wmiobject Win32_BIOS -Computer $Computer
        $computerOS = get-wmiobject Win32_OperatingSystem -Computer $Computer
        $computerCPU = get-wmiobject Win32_Processor -Computer $Computer
        $computerIP = Get-WmiObject Win32_NetworkAdapterConfiguration  -Computer $Computer | where  {$_.IPEnabled}
        $computerHDD = Get-WmiObject Win32_LogicalDisk -ComputerName $Computer -Filter drivetype=3
            write-host "System Information for: " $computerSystem.Name -BackgroundColor DarkCyan
            "-------------------------------------------------------"
            "Manufacturer: " + $computerSystem.Manufacturer
            "Model: " + $computerSystem.Model
            "IP:  " + $computerIP.IpAddress[0]
            "Operating System: " + $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
            "Serial Number: " + $computerBIOS.SerialNumber
            "CPU: " + $computerCPU.Name
            "HDD Capacity: "  + "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
            "HDD Space: " + "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) + " Free (" + "{0:N2}" -f ($computerHDD.FreeSpace/1GB) + "GB)"
            "RAM: " + "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
            "User logged In: " + $computerSystem.UserName
            "Last Reboot: " + $computerOS.ConvertToDateTime($computerOS.LastBootUpTime)
            ""
            "-------------------------------------------------------"
    }

    Any ideas?

    Thanks,

    Brian

    Tuesday, April 21, 2015 2:30 PM

Answers

  • Here is an example of how too build a formatter block:

    $listprops=@(
        'SerialNumber',
        'LastReboot',
        'Manufacturer',
        'IP',
        @{L='RAM';E={'{0:N2} Gb' -f ($_.TotalPhysicalMemory/1Gb)}}
    )
    $ArrComputers |
        ForEach-Object{
            $computer=$_
            $computerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer
            $computerBIOS = get-wmiobject Win32_BIOS -Computer $Computer
            $computerOS = get-wmiobject Win32_OperatingSystem -Computer $Computer
            $computerCPU = get-wmiobject Win32_Processor -Computer $Computer
            $computerIP = Get-WmiObject Win32_NetworkAdapterConfiguration  -Computer $Computer | where  {$_.IPEnabled}
            $computerHDD = Get-WmiObject Win32_LogicalDisk -ComputerName $Computer -Filter drivetype=3
            $props=@{
                Manufacturer=$computerSystem.Manufacturer 
                Model=$computerSystem.Model
                IP=$computerIP.IpAddress[0]
                OperatingSystem=$computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
                SerialNumber=$computerBIOS.SerialNumber
                CPU=$computerCPU.Name
                DiskSize=$computerHDD.Size
                FreeSpace=$computerHDD.FreeSpace
                TotalPhysicalMemory=$computerSystem.TotalPhysicalMemory
                UserName=$computerSystem.UserName
                LastReboot=$computerOS.ConvertToDateTime($computerOS.LastBootUpTime)
            }
            New-Object PsObject -Property $props
        } |
        Format-List $listprops  # here you can specify custom formatting
    
    


    \_(ツ)_/


    • Edited by jrv Tuesday, April 21, 2015 2:59 PM
    • Marked as answer by oletech Tuesday, April 21, 2015 5:42 PM
    Tuesday, April 21, 2015 2:59 PM

All replies

  • Bad syntax.

    Get all data then format.  Don't format inline.

    This is impossible:

    "HDD Capacity: "  + "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"

    Should be:

    'HDD Capacity:{0:N2}GB' -f ($computerHDD.Size/1GB)

    You seem to miss the whole point of using the string formatter.  If "prints" values into strings.


    \_(ツ)_/

    Tuesday, April 21, 2015 2:43 PM
  • This is how to gather the data and pass to a formatter.  You can customize the formatter,.

    $ArrComputers |
        ForEach-Object{
            $computer=$_
            $computerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer
            $computerBIOS = get-wmiobject Win32_BIOS -Computer $Computer
            $computerOS = get-wmiobject Win32_OperatingSystem -Computer $Computer
            $computerCPU = get-wmiobject Win32_Processor -Computer $Computer
            $computerIP = Get-WmiObject Win32_NetworkAdapterConfiguration  -Computer $Computer | where  {$_.IPEnabled}
            $computerHDD = Get-WmiObject Win32_LogicalDisk -ComputerName $Computer -Filter drivetype=3
            $props=@{
                Manufacturer=$computerSystem.Manufacturer 
                Model=$computerSystem.Model
                IP=$computerIP.IpAddress[0]
                OperatingSystem=$computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
                SerialNumber=$computerBIOS.SerialNumber
                CPU=$computerCPU.Name
                DiskSize=$computerHDD.Size
                FreeSpace=$computerHDD.FreeSpace
                TotalPhysicalMemory=$computerSystem.TotalPhysicalMemory
                UserName=$computerSystem.UserName
                LastReboot=$computerOS.ConvertToDateTime($computerOS.LastBootUpTime)
            }
            New-Object PsObject -Property $props
        } |
        Format-List  # here you can specify custom formatting
    
    
    


    \_(ツ)_/


    • Edited by jrv Tuesday, April 21, 2015 2:53 PM
    Tuesday, April 21, 2015 2:51 PM
  • Here is an example of how too build a formatter block:

    $listprops=@(
        'SerialNumber',
        'LastReboot',
        'Manufacturer',
        'IP',
        @{L='RAM';E={'{0:N2} Gb' -f ($_.TotalPhysicalMemory/1Gb)}}
    )
    $ArrComputers |
        ForEach-Object{
            $computer=$_
            $computerSystem = get-wmiobject Win32_ComputerSystem -Computer $Computer
            $computerBIOS = get-wmiobject Win32_BIOS -Computer $Computer
            $computerOS = get-wmiobject Win32_OperatingSystem -Computer $Computer
            $computerCPU = get-wmiobject Win32_Processor -Computer $Computer
            $computerIP = Get-WmiObject Win32_NetworkAdapterConfiguration  -Computer $Computer | where  {$_.IPEnabled}
            $computerHDD = Get-WmiObject Win32_LogicalDisk -ComputerName $Computer -Filter drivetype=3
            $props=@{
                Manufacturer=$computerSystem.Manufacturer 
                Model=$computerSystem.Model
                IP=$computerIP.IpAddress[0]
                OperatingSystem=$computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
                SerialNumber=$computerBIOS.SerialNumber
                CPU=$computerCPU.Name
                DiskSize=$computerHDD.Size
                FreeSpace=$computerHDD.FreeSpace
                TotalPhysicalMemory=$computerSystem.TotalPhysicalMemory
                UserName=$computerSystem.UserName
                LastReboot=$computerOS.ConvertToDateTime($computerOS.LastBootUpTime)
            }
            New-Object PsObject -Property $props
        } |
        Format-List $listprops  # here you can specify custom formatting
    
    


    \_(ツ)_/


    • Edited by jrv Tuesday, April 21, 2015 2:59 PM
    • Marked as answer by oletech Tuesday, April 21, 2015 5:42 PM
    Tuesday, April 21, 2015 2:59 PM

  • jrv,

    Thank you! And yes i am still a newb when it comes to PowerShell... i knew i didn’t like the way it looked in the code section, but on SOME computers it did come out to look ok… just ok.

    I will take the newly formatted code and do like you said and format the output… thank you again.

     

    Brian

    Tuesday, April 21, 2015 3:59 PM