0

im trayng to run this script to send mail with info about the servers but i get this error:

Method invocation failed because [System.Object[]] does not contain a method named 'op_Division'.
At C:\Users\admin-ran\Desktop\Startup-SendMailTEST.ps1:22 char:1
+ $compinfo = New-Object PSObject -property @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Division:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

$compinfo = @()
$computerSystem = get-wmiobject Win32_ComputerSystem 
$computerBIOS = get-wmiobject Win32_BIOS 
$computerOS = get-wmiobject Win32_OperatingSystem 
$computerCPU = get-wmiobject Win32_Processor 
$computerHDD = Get-WmiObject Win32_LogicalDisk -Filter drivetype=3 
$colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IpEnabled = TRUE"
# Build objects
$compinfo = New-Object PSObject -property @{ 
'PCName' = $computerSystem.Name 
'Manufacturer' = $computerSystem.Manufacturer 
'Model' = $computerSystem.Model 
'SerialNumber' = $computerBIOS.SerialNumber 
'RAM' = "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) 
'HDDSize' = "{0:N2}" -f ($computerHDD.Size/1GB) 
'HDDFree' = "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) 
'CPU' = $computerCPU.Name 
'OS' = $computerOS.caption 
'SP' = $computerOS.ServicePackMajorVersion 
'User' = $computerSystem.UserName 
'BootTime' = $computerOS.ConvertToDateTime($computerOS.LastBootUpTime) 
'IP_Address' = [string]$colItems.IpAddress 
'MAC_Address' = [string]$colItems.MacAddress 
'Default_Gateway' = [string]$colItems.DefaultIpGateway 
'DNS_Domain' = $colItems.DNSDomain 
'DHCP_Enabled' = $colItems.DHCPEnabled 
}

$compinfo | select -Property HDDFree ,HDDSize ,Ram ,OS ,CPU ,SP ,IP_Address,Mac_Address ,BootTime ,DHCP_Enabled
Zman
  • 3
  • 1
  • 3

1 Answers1

2

I'm betting you have more than one hard drive, so $computerHDD is an array and so is $computerHDD.size and $computerHDD.FreeSpace, so you would need to do a ForEach($HDD in $computerHDD) and insert a loop in there (or something along those lines).

Here is what I would update your script to:

$compinfo = @()
$computerSystem = get-wmiobject Win32_ComputerSystem 
$computerBIOS = get-wmiobject Win32_BIOS 
$computerOS = get-wmiobject Win32_OperatingSystem 
$computerCPU = get-wmiobject Win32_Processor 
$computerHDD = Get-WmiObject Win32_LogicalDisk -Filter drivetype=3 
$colItems = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IpEnabled = TRUE"
# Build objects
ForEach($HDD in $computerHDD){
    $compinfo += New-Object PSObject -property @{ 
        PCName = $computerSystem.Name 
        Manufacturer = $computerSystem.Manufacturer 
        Model = $computerSystem.Model 
        SerialNumber = $computerBIOS.SerialNumber 
        RAM = "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) 
        HDDSize = "{0:N2}" -f ($HDD.Size/1GB) 
        HDDFree = "{0:P2}" -f ($HDD.FreeSpace/$HDD.Size) 
        CPU = $computerCPU.Name 
        OS = $computerOS.caption 
        SP = $computerOS.ServicePackMajorVersion 
        User = $computerSystem.UserName 
        BootTime = $computerOS.ConvertToDateTime($computerOS.LastBootUpTime) 
        IP_Address = [string]$colItems.IpAddress 
        MAC_Address = [string]$colItems.MacAddress 
        Default_Gateway = [string]$colItems.DefaultIpGateway 
        DNS_Domain = $colItems.DNSDomain 
        DHCP_Enabled = $colItems.DHCPEnabled 
    }
}
$compinfo | select -Property HDDFree ,HDDSize ,Ram ,OS ,CPU ,SP ,IP_Address,Mac_Address ,BootTime ,DHCP_Enabled

I ran that on my machine and it ran without errors.

TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56