Computer info

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

April 21st, 2015 10:32am

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.

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 10:44am

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



April 21st, 2015 10:53am

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

Free Windows Admin Tool Kit Click here and download it now
April 21st, 2015 11:00am


jrv,

Thank you! And yes i am still a newb when it comes to PowerShell... i knew i didnt 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

April 21st, 2015 12:01pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics