powershell - Get Pc & Monitor Info remotely with one script -


code 1 gets pc info remotely , code 2 gets monitor info remotely. how incorporate code 2 code 1? output pc info followed monitor info. tried incorporate got lot of errors.

code 1 logs information computers queried , un-queried.

    code 1:  courtesy of alexander obersht       $arrcomputers = gc .\computernames.txt     $outputlog = ".\output.log"      $notrespondinglog = ".\notresponding.log"      $erroractionpreference = "stop"       clear-host       foreach ($computer in $arrcomputers)      { try {     $computersystem = get-wmiobject win32_computersystem -computer $computer     $computerbios = get-wmiobject win32_bios -computer $computer     $version = get-wmiobject -namespace "root\cimv2" `         -query "select * win32_computersystemproduct" `         -computer $computer | select -expandproperty version } catch {     $computer | out-file -filepath $notrespondinglog -append -encoding utf8     continue }  $header = "system information for: {0}" -f $computersystem.name  write-host $header -backgroundcolor darkcyan $header | out-file -filepath $outputlog -append -encoding utf8  $output = (@" -------------------------------------------------------     model: {0}    serial number: {1}    version: {2}      -------------------------------------------------------    "@) -f $computersystem.model, $computerbios.serialnumber, $version   write-host $output $output | out-file -filepath $outputlog -append -encoding utf8    }      code 2:       $users = gc .\computernames1.txt     gwmi wmimonitorid -namespace root\wmi -computername $users |    select pscomputername,      @{n="model";e={[system.text.encoding]::ascii.getstring($_.userfriendlyname -ne 00)}},      @{n="serial number";e={[system.text.encoding]::ascii.getstring($_.serialnumberid -ne 00)}} |      format-list | out-file '.\report.csv' 

updated solution previous question:

$arrcomputers = gc .\computernames.txt $outputlog = ".\output.log" # main log $notrespondinglog = ".\notresponding.log" # logging "unqueried" hosts  $erroractionpreference = "stop" # or add '-ea stop' get-wmiobject queries clear-host  foreach ($computer in $arrcomputers)  {     try     {         $computersystem = get-wmiobject win32_computersystem -computer $computer         $computerbios = get-wmiobject win32_bios -computer $computer         $version = get-wmiobject -namespace "root\cimv2" `             -query "select * win32_computersystemproduct" `             -computer $computer | select -expandproperty version         $monitorinfo = gwmi wmimonitorid -namespace root\wmi `             -computername $computer `             | select pscomputername, `                 @{n="model";e={[system.text.encoding]::ascii.getstring(`                     $_.userfriendlyname -ne 00)}},                 @{n="serial number";e={[system.text.encoding]::ascii.getstring(`                     $_.serialnumberid -ne 00)}}          }     catch     {         $computer | out-file -filepath $notrespondinglog -append -encoding utf8         continue     }      $header = "system information for: {0}" -f $computersystem.name      # outputting , logging header.     write-host $header -backgroundcolor darkcyan     $header | out-file -filepath $outputlog -append -encoding utf8      $output = (@" -------------------------------------------------------  model          : {0}  serial number  : {1}  version        : {2}  monitor model  : {3} monitor serial : {4}  -------------------------------------------------------  "@) -f $computersystem.model, $computerbios.serialnumber, $version, `        $monitorinfo.model, $monitorinfo."serial number"      # ouputting , logging wmi data     write-host $output     $output | out-file -filepath $outputlog -append -encoding utf8 } 

Comments