locked
Inventory Script RRS feed

  • Question

  • Hi,

    I have the blow script but it is not working properly. I use a text file filled with the names of the PC's I want to run the script against, then the info is exported to a csv. This works fine on some PC's but not on others. The ones it doesn't work on I get the following error.

    Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Management.ManagementObject".

    Would anyone be able to fix for me please as I my knowledge is limited and not sure where to go from here?

    Many Thanks

    Paul

    #Test if the text file exisits
    If (Test-Path C:\PC_ServerList.txt)
    {  
         Write-Host "Importing PC/Server hostnames" -ForegroundColor Yellow
    }
    
    Else
    {
        Write-Host "Cannot find PC_ServerList.txt text file. Please check if the file exists." -ForegroundColor Red
        
    Continue
    }
    
    #Gets the list of PC names
    $ComputerList = Get-Content C:\PC_ServerList.txt
    
    
    #Or $Computerlist = Get-ADComputer -Filter  {OperatingSystem -Like '*Windows Server*' }  | Select-Object -ExpandProperty Name
    
    $OutputCSV = "C:\PC_ServerInventory.csv"
     
    $ScriptPath = $MyInvocation.MyCommand.Path
    #$Dir = Split-Path $ScriptPath
    Pushd $Dir
     
    [System.Collections.ArrayList]$SysCollection = New-Object System.Collections.ArrayList($Null)
      
    ForEach ($Computer in $ComputerList)
    {
        "Collecting information from $Computer"
      
        Try
        {
    
            #Starts the necessary services
            Get-Service -Name WinRM -ComputerName $Computer | Set-Service -StartupType Automatic -Status Running
            Get-Service -Name wmiApSrv -ComputerName $Computer | Set-Service -StartupType Automatic -Status Running
            Get-Service -Name RemoteRegistry -ComputerName $Computer | Set-Service -StartupType Automatic -Status Running
            Get-Service -Name COMSysApp -ComputerName $Computer | Set-Service -StartupType Automatic -Status Running
            Get-Service -Name EventSystem -ComputerName $Computer | Set-Service -StartupType Automatic -Status Running
    
    
            [WMI]$SysInfo     = Get-WmiObject Win32_ComputerSystem -Namespace "Root\CIMV2" -ComputerName $Computer
            [WMI]$Monitors    = Get-WmiObject WmiMonitorID -Namespace "Root\WMI" -ComputerName $Computer
            [WMI]$BIOS        = Get-WmiObject Win32_BIOS -Namespace "Root\CIMV2" -ComputerName $Computer
            [WMI]$OS          = Get-WmiObject Win32_OperatingSystem -Namespace "Root\CIMV2" -ComputerName $Computer
            [WMI]$Processor   = Get-WmiObject Win32_Processor -Namespace "Root\CIMV2" -ComputerName $Computer
            [WMI]$AV          = Get-WmiObject AntiVirusProduct -Namespace "Root\SecurityCenter2" -ComputerName $Computer
            [WMI]$LastUser    = Get-WmiObject Win32_Process -Namespace "Root\CIMV2" -ComputerName $Computer | Where-Object Name -Match Explorer
            [WMI]$TimeZone    = Get-WmiObject Win32_TimeZone -Namespace "Root\CIMV2" -ComputerName $Computer
            [Array]$Disks     = Get-WmiObject Win32_LogicalDisk -Namespace "Root\CIMV2" -ComputerName $Computer -Filter DriveType=3
            [Array]$USBDisks  = Get-WmiObject Win32_LogicalDisk -Namespace "Root\CIMV2" -ComputerName $Computer -Filter DriveType=2
            [Array]$NIC       = Get-WmiObject Win32_NetworkAdapterConfiguration -Namespace "Root\CIMV2" -ComputerName $Computer -Filter 'IPEnabled = "True"'
    
            #Selects the Administrator 
            $LocalAdmin       = Invoke-Command -ComputerName $Computer {Get-LocalUser -Name "Administrator"}
    
            #Gets the AV Last updated time/date
            $AVDU             = Invoke-Command -ComputerName $Computer {Get-MpComputerStatus | Select-Object -Property AntivirusSignatureLastUpdated}
    
            #Gets the release ID Number
            $OSVersion        = Invoke-command -ComputerName $Computer {Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"}
    
            #Gets the system uptime
            $LastBoot         = [System.Management.ManagementDateTimeConverter]::ToDateTime("$($OS.LastBootUpTime)")
            $UpTime           = (Get-Date) - $LastBoot
    
            #Switch for the AV Real Time Protection and Definition Status
             Switch ($AV.ProductState){
            "262144" {$DefStatus = "Up to date" ;$RTStatus = "Disabled"} 
            "262160" {$DefStatus = "Out of date" ;$RTStatus = "Disabled"} 
            "266240" {$DefStatus = "Up to date" ;$RTStatus = "Enabled"} 
            "266256" {$DefStatus = "Out of date" ;$RTStatus = "Enabled"} 
            "393216" {$DefStatus = "Up to date" ;$RTStatus = "Disabled"} 
            "393232" {$DefStatus = "Out of date" ;$RTStatus = "Disabled"} 
            "393488" {$DefStatus = "Out of date" ;$RTStatus = "Disabled"} 
            "397312" {$DefStatus = "Up to date" ;$RTStatus = "Enabled"} 
            "397328" {$DefStatus = "Out of date" ;$RTStatus = "Enabled"} 
            "397584" {$DefStatus = "Out of date" ;$RTStatus = "Enabled"}
            "397568" {$DefStatus = "Up to date"; $RTStatus = "Enabled"}
            "393472" {$DefStatus = "Up to date" ;$RTStatus = "Disabled"} 
             Default {$DefStatus = "Unknown" ;$RTStatus = "Unknown"}}
    
             #Switch to list the name of the OS Language
             Switch ($OS.OSLanguage){
            "1078"  {$OSLan = "Afrikaans - South Africa"}
            "1052"  {$OSLan = "Albanian - Albania"}
            "1118"  {$OSLan = "Amharic - Ethiopia"}
            "1025"  {$OSLan = "Arabic - Saudi Arabia"}
            "5121"  {$OSLan = "Arabic - Algeria"}
            "15361" {$OSLan = "Arabic - Bahrain"}
            "3073"  {$OSLan = "Arabic - Egypt"}
            "2049"  {$OSLan = "Arabic - Iraq"}
            "11265" {$OSLan = "Arabic - Jordan"}
            "13313" {$OSLan = "Arabic - Kuwait"}
            "12289" {$OSLan =  "Arabic - Lebanon"}
            "4097"  {$OSLan = "Arabic - Libya"}
            "6145"  {$OSLan = "Arabic - Morocco"}
            "8193"  {$OSLan = "Arabic - Oman"}
            "16385" {$OSLan = "Arabic - Qatar"}
            "10241" {$OSLan = "Arabic - Syria"}
            "7169"  {$OSLan = "Arabic - Tunisia"}
            "14337" {$OSLan = "Arabic - U.A.E."}
            "9217"  {$OSLan = "Arabic - Yemen"}
            "1067"  {$OSLan = "Armenian - Armenia"}
            "1101"  {$OSLan = "Assamese"}
            "2092"  {$OSLan = "Azeri (Cyrillic)"}
            "1068"  {$OSLan = "Azeri (Latin)"}
            "1069"  {$OSLan = "Basque"}
            "1059"  {$OSLan = "Belarusian"}
            "1093"  {$OSLan = "Bengali (India)"}
            "2117"  {$OSLan = "Bengali (Bangladesh)"}
            "5146"  {$OSLan = "Bosnian (Bosnia/Herzegovina)"}
            "1026"  {$OSLan = "Bulgarian"}
            "1109"  {$OSLan = "Burmese"}
            "1027"  {$OSLan = "Catalan"}
            "1116"  {$OSLan = "Cherokee - United States"}
            "2052"  {$OSLan = "Chinese - People's Republic of China"} 
            "4100"  {$OSLan = "Chinese - Singapore"}
            "1028"  {$OSLan = "Chinese - Taiwan"}
            "3076"  {$OSLan = "Chinese - Hong Kong SAR"}
            "5124"  {$OSLan = "Chinese - Macao SAR"}
            "1050"  {$OSLan = "Croatian"}
            "4122"  {$OSLan = "Croatian (Bosnia/Herzegovina)"}
            "1029"  {$OSLan = "Czech"}
            "1030"  {$OSLan = "Danish"}
            "1125"  {$OSLan = "Divehi"}
            "1043"  {$OSLan = "Dutch - Netherlands"}
            "2067"  {$OSLan = "Dutch - Belgium"}
            "1126"  {$OSLan = "Edo"}
            "1033"  {$OSLan = "English - United States"}
            "2057"  {$OSLan = "English - United Kingdom"}
            "3081"  {$OSLan = "English - Australia"}
            "10249" {$OSLan = "English - Belize"}
            "4105"  {$OSLan = "English - Canada"}
            "9225"  {$OSLan = "English - Caribbean"}
            "15369" {$OSLan = "English - Hong Kong SAR"}
            "16393" {$OSLan = "English - India"}
            "14345" {$OSLan = "English - Indonesia"}
            "6153"  {$OSLan = "English - Ireland"}
            "8201"  {$OSLan = "English - Jamaica"}
            "17417" {$OSLan = "English - Malaysia"}
            "5129"  {$OSLan = "English - New Zealand"}
            "13321" {$OSLan = "English - Philippines"}
            "18441" {$OSLan = "English - Singapore"}
            "7177"  {$OSLan = "English - South Africa"}
            "11273" {$OSLan = "English - Trinidad"}
            "12297" {$OSLan = "English - Zimbabwe"}
            "1061"  {$OSLan = "Estonian"}
            "1080"  {$OSLan = "Faroese"}
            "1065"  {$OSLan = "Farsi"}
            "1124"  {$OSLan = "Filipino"}
            "1035"  {$OSLan = "Finnish"}
            "1036"  {$OSLan = "French - France"}
            "2060"  {$OSLan = "French - Belgium"}
            "11276" {$OSLan = "French - Cameroon"}
            "3084"  {$OSLan = "French - Canada"}
            "9228"  {$OSLan = "French - Democratic Rep. of Congo"}
            "12300" {$OSLan = "French - Cote d'Ivoire"}
            "15372" {$OSLan = "French - Haiti"}
            "5132"  {$OSLan = "French - Luxembourg "}
            "13324" {$OSLan = "French - Mali"}
            "6156"  {$OSLan = "French - Monaco"}
            "14348" {$OSLan = "French - Morocco"}
            "58380" {$OSLan = "French - North Africa"}
            "8204"  {$OSLan = "French - Reunion"}
            "10252" {$OSLan = "French - Senegal"}
            "4108"  {$OSLan = "French - Switzerland"}
            "7180"  {$OSLan = "French - West Indies"}
            "1122"  {$OSLan = "Frisian - Netherlands"}
            "1127"  {$OSLan = "Fulfulde - Nigeria"}
            "1071"  {$OSLan = "FYRO Macedonian"}
            "2108"  {$OSLan = "Gaelic (Ireland)"}
            "1084"  {$OSLan = "Gaelic (Scotland)"}
            "1110"  {$OSLan = "Galician"}
            "1079"  {$OSLan = "Georgian"}
            "1031"  {$OSLan = "German - Germany"}
            "3079"  {$OSLan = "German - Austria"}
            "5127"  {$OSLan = "German - Liechtenstein"}
            "4103"  {$OSLan = "German - Luxembourg"}
            "2055"  {$OSLan = "German - Switzerland"}
            "1032"  {$OSLan = "Greek"}
            "1140"  {$OSLan = "Guarani - Paraguay"}
            "1095"  {$OSLan = "Gujarati"}
            "1128"  {$OSLan = "Hausa - Nigeria"}
            "1141"  {$OSLan = "Hawaiian - United States"}
            "1037"  {$OSLan = "Hebrew"}
            "1081"  {$OSLan = "Hindi"}
            "1038"  {$OSLan =" Hungarian"}
            "1129"  {$OSLan = "Ibibio - Nigeria"}
            "1039"  {$OSLan = "Icelandic"}
            "1136"  {$OSLan = "Igbo - Nigeria"}
            "1057"  {$OSLan = "Indonesian"}
            "1117"  {$OSLan = "Inuktitut"}
            "1040"  {$OSLan = "Italian - Italy"}
            "2064"  {$OSLan = "Italian - Switzerland"}
            "1041"  {$OSLan = "Japanese"}
            "1099"  {$OSLan = "Kannada"}
            "1137"  {$OSLan = "Kanuri - Nigeria"}
            "2144"  {$OSLan = "Kashmiri"}
            "1120"  {$OSLan = "Kashmiri (Arabic)"}
            "1087"  {$OSLan = "Kazakh"}
            "1107"  {$OSLan = "Khmer"}
            "1111"  {$OSLan = "Konkani"}
            "1042"  {$OSLan = "Korean"}
            "1088"  {$OSLan = "Kyrgyz (Cyrillic)"}
            "1108"  {$OSLan = "Lao"}
            "1142"  {$OSLan = "Latin"}
            "1062"  {$OSLan = "Latvian"}
            "1063"  {$OSLan = "Lithuanian"}
            "1086"  {$OSLan = "Malay - Malaysia"}
            "2110"  {$OSLan = "Malay - Brunei Darussalam"}
            "1100"  {$OSLan = "Malayalam"}
            "1082"  {$OSLan = "Maltese"}
            "1112"  {$OSLan = "Manipuri"}
            "1153"  {$OSLan = "Maori - New Zealand"}
            "1102"  {$OSLan = "Marathi"}
            "1104"  {$OSLan = "Mongolian (Cyrillic)"}
            "2128"  {$OSLan = "Mongolian (Mongolian)"}
            "1121"  {$OSLan = "Nepali"}
            "2145"  {$OSLan = "Nepali - India"}
            "1044"  {$OSLan = "Norwegian (Bokmål)"}
            "2068"  {$OSLan = "Norwegian (Nynorsk)"}
            "1096"  {$OSLan = "Oriya"}
            "1138"  {$OSLan = "Oromo"}
            "1145"  {$OSLan = "Papiamentu"}
            "1123"  {$OSLan = "Pashto"}
            "1045"  {$OSLan = "Polish"}
            "1046"  {$OSLan = "Portuguese - Brazil"}
            "2070"  {$OSLan = "Portuguese - Portugal"}
            "1094"  {$OSLan = "Punjabi"}
            "2118"  {$OSLan = "Punjabi (Pakistan)"}
            "1131"  {$OSLan = "Quecha - Bolivia"}
            "2155"  {$OSLan = "Quecha - Ecuador"}
            "3179"  {$OSLan = "Quecha - Peru"}
            "1047"  {$OSLan = "Rhaeto-Romanic"}
            "1048"  {$OSLan = "Romanian"}
            "2072"  {$OSLan = "Romanian - Moldava"}
            "1049"  {$OSLan = "Russian"}
            "2073"  {$OSLan = "Russian - Moldava"}
            "1083"  {$OSLan = "Sami (Lappish)"}
            "1103"  {$OSLan = "Sanskrit"}
            "1132"  {$OSLan = "Sepedi"}
            "3098"  {$OSLan = "Serbian (Cyrillic)"}
            "2074"  {$OSLan = "Serbian (Latin)"}
            "1113"  {$OSLan = "Sindhi - India"}
            "2137"  {$OSLan = "Sindhi - Pakistan"}
            "1115"  {$OSLan = "Sinhalese - Sri Lanka"}
            "1051"  {$OSLan = "Slovak"}
            "1060"  {$OSLan = "Slovenian"}
            "1143"  {$OSLan = "Somali"}
            "1070"  {$OSLan = "Sorbian"}
            "3082"  {$OSLan = "Spanish - Spain (Modern Sort)"}
            "1034"  {$OSLan = "Spanish - Spain (Traditional Sort)"}
            "11274" {$OSLan = "Spanish - Argentina"}
            "16394" {$OSLan = "Spanish - Bolivia"}
            "13322" {$OSLan = "Spanish - Chile"}
            "9226"  {$OSLan = "Spanish - Colombia"}
            "5130"  {$OSLan = "Spanish - Costa Rica"}
            "7178"  {$OSLan = "Spanish - Dominican Republic"}
            "12298" {$OSLan = "Spanish - Ecuador"}
            "17418" {$OSLan = "Spanish - El Salvador"}
            "4106"  {$OSLan = "Spanish - Guatemala"}
            "18442" {$OSLan = "Spanish - Honduras"}
            "22538" {$OSLan = "Spanish - Latin America"}
            "2058"  {$OSLan = "Spanish - Mexico"}
            "19466" {$OSLan = "Spanish - Nicaragua"}
            "6154"  {$OSLan = "Spanish - Panama"}
            "15370" {$OSLan = "Spanish - Paraguay"}
            "10250" {$OSLan = "Spanish - Peru"}
            "20490" {$OSLan = "Spanish - Puerto Rico"}
            "21514" {$OSLan = "Spanish - United States"}
            "14346" {$OSLan = "Spanish - Uruguay"}
            "8202"  {$OSLan = "Spanish - Venezuela"}
            "1072"  {$OSLan = "Sutu"}
            "1089"  {$OSLan = "Swahili"}
            "1053"  {$OSLan = "Swedish"}
            "2077"  {$OSLan = "Swedish - Finland"}
            "1114"  {$OSLan = "Syriac"}
            "1064"  {$OSLan = "Tajik"}
            "1119"  {$OSLan = "Tamazight (Arabic)"}
            "2143"  {$OSLan = "Tamazight (Latin)"}
            "1097"  {$OSLan = "Tamil"}
            "1092"  {$OSLan = "Tatar"}
            "1098"  {$OSLan = "Telugu"}
            "1054"  {$OSLan = "Thai"}
            "2129"  {$OSLan = "Tibetan - Bhutan"}
            "1105"  {$OSLan = "Tibetan - People's Rep. of China"}
            "2163"  {$OSLan = "Tigrigna - Eritrea"}
            "1139"  {$OSLan = "Tigrigna - Ethiopia"}
            "1073"  {$OSLan = "Tsonga"}
            "1074"  {$OSLan = "Tswana"}
            "1055"  {$OSLan = "Turkish"}
            "1090"  {$OSLan = "Turkmen"}
            "1152"  {$OSLan = "Uighur - China"}
            "1058"  {$OSLan = "Ukrainian"}
            "1056"  {$OSLan = "Urdu"}
            "2080"  {$OSLan = "Urdu - India"}
            "2115"  {$OSLan = "Uzbek (Cyrillic)"}
            "1091"  {$OSLan = "Uzbek (Latin)"}
            "1075"  {$OSLan = "Venda"}
            "1066"  {$OSLan = "Vietnamese"}
            "1106"  {$OSLan = "Welsh"}
            "1076"  {$OSLan = "Xhosa"}
            "1144"  {$OSLan = "Yi"}
            "1085"  {$OSLan = "Yiddish"}
            "1130"  {$OSLan = "Yoruba"}
            "1077"  {$OSLan = "Zulu"}
            "1279"  {$OSLan = "HID (Human Interface Device)"}}
            
            #Switch to list the name of the monitor manufacturer
            Switch ($MonManufacturer){
            "AAC"   {$MonFriendlyName =	"AcerView"}
            "ACR"   {$MonFriendlyName = "Acer"}
            "AOC"   {$MonFriendlyName = "AOC"}
            "AIC"   {$MonFriendlyName = "AG Neovo"}
            "APP"   {$MonFriendlyName = "Apple Computer"}
            "AST"   {$MonFriendlyName = "AST Research"}
            "AUO"   {$MonFriendlyName = "Asus"}
            "BNQ"   {$MonFriendlyName = "BenQ"}
            "CMO"   {$MonFriendlyName = "Acer"}
            "CPL"   {$MonFriendlyName = "Compal"}
            "CPQ"   {$MonFriendlyName = "Compaq"}
            "CPT"   {$MonFriendlyName = "Chunghwa Pciture Tubes, Ltd."}
            "CTX"   {$MonFriendlyName = "CTX"}
            "DEC"   {$MonFriendlyName = "DEC"}
            "DEL"   {$MonFriendlyName = "Dell"}
            "DPC"   {$MonFriendlyName = "Delta"}
            "DWE"   {$MonFriendlyName = "Daewoo"}
            "EIZ"   {$MonFriendlyName = "EIZO"}
            "ELS"   {$MonFriendlyName = "ELSA"}
            "ENC"   {$MonFriendlyName = "EIZO"}
            "EPI"   {$MonFriendlyName = "Envision"}
            "FCM"   {$MonFriendlyName = "Funai"}
            "FUJ"   {$MonFriendlyName = "Fujitsu"}
            "FUS"   {$MonFriendlyName = "Fujitsu-Siemens"}
            "GSM"   {$MonFriendlyName = "LG Electronics"}
            "GWY"   {$MonFriendlyName = "Gateway 2000"}
            "HEI"   {$MonFriendlyName = "Hyundai"}
            "HIT"   {$MonFriendlyName = "Hyundai"}
    	    "HSD"   {$MonFriendlyName = "Hanns-G"}
            "HSL"   {$MonFriendlyName = "Hansol"}
            "HTC"   {$MonFriendlyName = "Hitachi/Nissei"}
            "HWP"   {$MonFriendlyName = "HP"}
            "IBM"   {$MonFriendlyName = "IBM"}
            "ICL"   {$MonFriendlyName = "Fujitsu ICL"}
            "IVM"   {$MonFriendlyName = "Iiyama"}
            "KDS"   {$MonFriendlyName = "Korea Data Systems"}
            "LEN"   {$MonFriendlyName = "Lenovo"}
            "LGD"   {$MonFriendlyName = "Asus"}
            "LPL"   {$MonFriendlyName = "Fujitsu"}
            "MAX"   {$MonFriendlyName = "Belinea"}
            "MEI"   {$MonFriendlyName = "Panasonic"}
            "MEL"   {$MonFriendlyName = "Mitsubishi Electronics"}
            "MS_"   {$MonFriendlyName = "Panasonic"}
            "NAN"   {$MonFriendlyName = "Nanao"}
            "NEC"   {$MonFriendlyName = "NEC"}
            "NOK"   {$MonFriendlyName = "Nokia Data"}
            "NVD"   {$MonFriendlyName = "Fujitsu"}
            "OPT"   {$MonFriendlyName = "Optoma"}
            "PHL"   {$MonFriendlyName = "Philips"}
            "REL"   {$MonFriendlyName = "Relisys"}
            "SAN"   {$MonFriendlyName = "Samsung"}
            "SAM"   {$MonFriendlyName = "Samsung"}
            "SBI"   {$MonFriendlyName = "Smarttech"}
            "SGI"   {$MonFriendlyName = "SGI"}
            "SNY"   {$MonFriendlyName = "Sony"}
            "SRC"   {$MonFriendlyName = "Shamrock"}
            "SUN"   {$MonFriendlyName = "Sun Microsystems"}
            "SEC"   {$MonFriendlyName = "Hewlett-Packard"}
            "TAT"   {$MonFriendlyName = "Tatung"}
            "TOS"   {$MonFriendlyName = "Toshiba"}
            "TSB"   {$MonFriendlyName = "Toshiba"}
            "VSC"   {$MonFriendlyName = "ViewSonic"}
            "ZCM"   {$MonFriendlyName = "Zenith"}
            "UNK"   {$MonFriendlyName = "Unknown"}
            "_YV"   {$MonFriendlyName = "Fujitsu"}
            }
    
    #Get the monitor Model, Serial and Product Number
    Function Decode {
        If ($Args[0] -Is [System.Array]) {
            [System.Text.Encoding]::ASCII.GetString($Args[0]).Replace("$([char]0x0000)","") -join ""
        }
        Else {
            Continue
        }
    }
    
    ForEach ($Monitor in $Monitors) {  
        $MonModelNumber = Decode $Monitor.UserFriendlyName -Ne 0
        $MonSerialNumber = Decode $Monitor.SerialNumberID -Ne 0
        $MonManufacturer = Decode $Monitor.ManufacturerName -Ne 0
        $MonProductNumber = Decode $Monitor.ProductCodeID -Ne 0
    
    }
    
    #Gets the installed and missing Windows Updates
    $UpdateSession = [Activator]::CreateInstance([Type]::GetTypeFromProgID("Microsoft.Update.Session",$Computer))
    $UpdateSearcher = $UpdateSession.CreateupdateSearcher()
    $MissingUpdates = @($UpdateSearcher.Search("DeploymentAction=* and IsHidden=0 and Type='Software' and IsInstalled=0").Updates)
    $InstalledUpdates = @($UpdateSearcher.Search("IsHidden=0 and Type='Software' and IsInstalled=1").Updates)
    
            
        $SI = @{
                FQDN                          = [String]$SysInfo.DNSHostName+"."+$SysInfo.Domain
                NetBIOSName                   = [String]$SysInfo.DNSHostName
                Domain                        = [String]$SysInfo.Domain
                Manufacturer                  = [String]$SysInfo.Manufacturer
                Model                         = [String]$SysInfo.Model
                SystemType                    = [String]$SysInfo.SystemType
                TotalMemory                   = "$([String]([System.Math]::Round($SysInfo.TotalPhysicalMemory/1GB,2))) GB"
                BIOSName                      = [String]$BIOS.Name
                BIOSDescription               = [String]$BIOS.Description
                BIOSVersion                   = [String]$BIOS.SMBIOSBIOSVersion+"."+$BIOS.SMBIOSMajorVersion+"."+$BIOS.SMBIOSMinorVersion
                BIOSManufacturer              = [String]$BIOS.Manufacturer
                SerialNo                      = [String]$BIOS.SerialNumber
                OSName                        = [String]$OS.Caption
                OSLanguage                    = [String]$OSLan
                OSServicePack                 = (“SP {0}” -F [String]$OS.ServicePackMajorVersion)
                OSArchitecture                = [String]$OS.OSArchitecture
                OSBuildNo                     = [String]$OS.BuildNumber+"."+$OSVersion.UBR
                OSVersion                     = [String]$OS.Version            
                OSReleaseNo                   = [String]$OSVersion.ReleaseID
                OSInstallDate                 = [String]$OS.ConvertToDateTime($OS.InstallDate) -F "MM/dd/yyyy"
                TimeZone                      = [String]$TimeZone.StandardName
                PhysicalProcessors            = [String]@($Processor).Count
                LogicalProcessors             = [String]$Processor.NumberOfLogicalProcessors
                ProcessorModel                = [String]$Processor.Name
                ProcessorManufacturer         = [String]$Processor.Manufacturer
                Cores                         = [String]$Processor.NumberOfCores
                IPAddress                     = [String]$NIC.IPAddress
                MACAddress                    = [String]$NIC.MACAddress
                AVStatus                      = [String]$DefStatus
                RTProtection                  = [String]$RTStatus
                AVLastUpdate                  = [String]$AVDU.AntivirusSignatureLastUpdated
                AntiVirus                     = [String]$AV.DisplayName
                UpTime                        = [String]$UpTime.Days.ToString()+" Days, "+$UpTime.Hours.ToString()+" Hours, "+$UpTime.Minutes.ToString()+" Minutes, "+$UpTime.Seconds.ToString()+" Seconds"
                AdministratorAccountEnabled   = [String]$LocalAdmin.Enabled
                LastUser                      = [String]$LastUser.GetOwner().User
                InstalledWinUpdates           = [String]$InstalledUpdates.Title
                MissingWinUpdates             = [String]$MissingUpdates.Title
                MonitorManufacturer           = [String]$MonFriendlyName
                MonitorModel                  = [String]$MonModelNumber
                MonitorProductNo              = [String]$MonProductNumber
                MonitorSerialNo               = [String]$MonSerialNumber
                }
             
            $Disks    | ForEach-Object {$SI."DriveSize:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round($_.Size/1GB,2))) GB"} -ErrorAction SilentlyContinue
            $Disks    | ForEach-Object {$SI."FreeDriveSpace:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round($_.FreeSpace/1GB,2))) GB"} -ErrorAction SilentlyContinue
            $Disks    | ForEach-Object {$SI."UsedDriveSpace:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round(($_.Size - $_.FreeSpace)/1GB,2))) GB"} -ErrorAction SilentlyContinue
            $USBDisks | ForEach-Object {$SI."DriveSize:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round($_.Size/1GB,2))) GB"} -ErrorAction SilentlyContinue
            $USBDisks | ForEach-Object {$SI."FreeDriveSpace:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round($_.FreeSpace/1GB,2))) GB"} -ErrorAction SilentlyContinue
            $USBDisks | ForEach-Object {$SI."UsedDriveSpace:$($_.Name -Replace ':', '')"="$([String]([System.Math]::Round(($_.Size - $_.FreeSpace)/1GB,2))) GB"} -ErrorAction SilentlyContinue
           
        }
        Catch [Exception]
        {
            Write-Host "Error communicating with $Computer, skipping to next" -ForegroundColor White -BackgroundColor Red
            $SI = @{
                Server          = [String]$Computer
                ErrorMessage    = [String]$_.Exception.Message
                ErrorItem       = [String]$Computer
        }
        Continue
    }
        Finally
        {
            [Void]$SysCollection.Add((New-Object PSObject -Property $SI))   
        }
    }
      
    $SysCollection `
        | Select-Object FQDN,NetBIOSName,Domain,Manufacturer,Model,SerialNo,SystemType,ProcessorManufacturer,ProcessorModel,PhysicalProcessors,LogicalProcessors,Cores,TotalMemory,IPAddress,MACAddress,MonitorManufacturer,MonitorModel,MonitorProductNo,MonitorSerialNo,BIOSName,BIOSManufacturer,BiosDescription,BiosVersion,OSName,OSVersion,OSBuildNo,OSReleaseNo,OSArchitecture,OSServicePack,OSLanguage,OSInstallDate,InstalledWinUpdates,MissingWinUpdates,TimeZone,AntiVirus,AVStatus,RTProtection,AVLastUpdate,UpTime,LastUser,AdministratorAccountEnabled,DriveSize:A,DriveSize:B,DriveSize:C,DriveSize:D,DriveSize:E,DriveSize:F,DriveSize:G,DriveSize:H,DriveSize:I,DriveSize:J,DriveSize:K,DriveSize:L,DriveSize:M,DriveSize:N,DriveSize:O,DriveSize:P,DriveSize:Q,DriveSize:R,DriveSize:S,DriveSize:T,DriveSize:U,DriveSize:V,DriveSize:W,DriveSize:X,DriveSize:Y,DriveSize:Z,UsedDriveSpace:A,UsedDriveSpace:B,UsedDriveSpace:C,UsedDriveSpace:D,UsedDriveSpace:E,UsedDriveSpace:F,UsedDriveSpace:G,UsedDriveSpace:H,UsedDriveSpace:I,UsedDriveSpace:J,UsedDriveSpace:K,UsedDriveSpace:L,UsedDriveSpace:M,UsedDriveSpace:N,UsedDriveSpace:O,UsedDriveSpace:P,UsedDriveSpace:Q,UsedDriveSpace:R,UsedDriveSpace:S,UsedDriveSpace:T,UsedDriveSpace:U,UsedDriveSpace:V,UsedDriveSpace:W,UsedDriveSpace:X,UsedDriveSpace:Y,UsedDriveSpace:Z,FreeDriveSpace:A,FreeDriveSpace:B,FreeDriveSpace:C,FreeDriveSpace:D,FreeDriveSpace:E,FreeDriveSpace:F,FreeDriveSpace:G,FreeDriveSpace:H,FreeDriveSpace:I,FreeDriveSpace:J,FreeDriveSpace:K,FreeDriveSpace:L,FreeDriveSpace:M,FreeDriveSpace:N,FreeDriveSpace:O,FreeDriveSpace:P,FreeDriveSpace:Q,FreeDriveSpace:R,FreeDriveSpace:S,FreeDriveSpace:T,FreeDriveSpace:U,FreeDriveSpace:V,FreeDriveSpace:W,FreeDriveSpace:X,FreeDriveSpace:Y,FreeDriveSpace:Z,ErrorMessage,ErrorItem `
        | Export-CSV -Path $OutputCSV -NoTypeInformation
          Write-Host "Inventory completed. Check $OutputCSV" -ForegroundColor Green

    Tuesday, March 3, 2020 9:21 AM

All replies

  • We do not fix scripts on request.  We cannot answer questions about scripts you have found on the Internet.  YOu will have to ask teh author to fix it for you.

    Please read all of the following links carefully.

    Please carefully review the following links to set your expectation for posting in technical forums.


    \_(ツ)_/

    Tuesday, March 3, 2020 10:02 AM
  • Hi,

    I put this together from bits I found on the internet so there is not one single author so I can't really do that.

    Please can you tell me if there is a place on here that I can get someone to look at it and resolve the issues I have.

    Regards,

    Paul

    Tuesday, March 3, 2020 10:30 AM
  • We Aare not going to take a few hundred lines of script that has been glued together and try to guess at why it doesn't work.

    The error is clear.  You just have to read it an follow the instructions.

    Please read the links I posted.  You need to read the following one carefully:

    How to ask questions in a technical forum


    \_(ツ)_/

    Tuesday, March 3, 2020 10:48 AM
  • To begin with all of these constructs aer wrong:

     [WMI]$Monitors

    Remove al of the [WMI] decorations.  Apparently you copied bad code.


    \_(ツ)_/

    Tuesday, March 3, 2020 10:51 AM
  • Sorry but I don't understand the error that's why I came here. I'm pretty new to powershell and just wanted a bit of guidance.

    Sorry for bothering you.

    Tuesday, March 3, 2020 10:58 AM
  • Here is a short article that explains PowerShell errors. 

    https://mcpmag.com/articles/2017/01/26/exploring-errors-in-powershell.aspx

    You need to start by reading this.  YOU should also get a book and learn basic Powershell.  YOu are trying to use an advanced technology with no basic understanding of the technology.  You need to learn this from the ground up.

    If you read the complete error message it will tell you exactly what is wrong.  We cannot help you because you are not following the instructions in teh link I posted.  Without a correct question there is no way to help you.

    The error text you printed says exactly what it means and it is basic English.

    "Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Management.ManagementObject"."

    Read it.  Read it out loud. If you still can't understand it then ask a coworker to read it for you.  Look up any words you don't understand on the Internet.

    Here is a free eBook that will teach you basic PowerShell including how to read the help and how to read error message:


    \_(ツ)_/

    Tuesday, March 3, 2020 12:55 PM