Doing work on a list .csv list of computernames

I’m trying to get the Manufacturer,Model,Serial Number and hostname from a list of computers in my domain. I was thinking to do this:

Get-ADComputer -Filter * -Properties Name | Select-Object Name | Export-Csv c:\working\computers.csv

That gets my working list of computers.
Then I would use:

Get-WmiObject -ComputerName (My .csv list of computers) -Class Win32_ComputerSystem -Properties (etc…)

My problem is doing the get-WmiObject process on each of the computers in my list.

I’m still Powershell novice so no complex scripting if possible. I’ll get to that eventually but for now, I want it as simple as possible.

Thank you!

try this

$computers = Get-ADComputer -Filter *

$computers | Export-Csv c:\working\computers.csv -NoTypeInformation

$results = foreach ($computer in $computers) {
    $model = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$computer).OpenSubKey('HARDWARE\DESCRIPTION\System\BIOS').GetValue('SystemProductName')
    $serial = (Get-WMIObject WIN32_SystemEnclosure -ComputerName $computer).SerialNumber

    [pscustomobject]@{
        ComputerName = $computer
        Model = $model
        Serial = $serial
    }
}

$results | Export-Csv c:\working\computersinfo.csv -NoTypeInformation

Lots of red:

Exception calling “OpenRemoteBaseKey” with “2” argument(s): "The network path was not found.
"
At line:6 char:5

  • $model = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$co ...
    
  •   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : IOException
    
    

Get-WMIObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:7 char:16

  • $serial = (Get-WMIObject WIN32_SystemEnclosure -ComputerName $computer).Seri ...
    
  •            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:slight_smile: [Get-WmiObject], COMException
    • FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
$computers = ((Get-ADComputer -Filter *).Name -split "`n")

$sysinfo = foreach ($computer in $computers){
    $sysobj1 = Get-WmiObject -Class win32_computersystem -ComputerName $computer
    $sysobj2 = Get-WmiObject -Class Win32_systemenclosure -ComputerName $computer
    [PSCustomObject]@{
        Manufacturer = $sysobj1.manufacturer
        Model = $sysobj1.model
        SerialNumber = $sysobj2.serialnumber
        HostName = $sysobj1.Name}
        }

$sysinfo | export-csv .\sysinfo.csv -NoTypeInformation

I have a .csv file with 1137 lines of :

LENOVO 20BWS4FH00 PC07X2V9 'MYCOMPUTERNAME"

Which is my local computer

I need that for all the other computers too.

Try my comment again.

Sorry, that didn’t work either. I have run

gwmi -class win32_computersystem -computername ‘computername’

on several random hosts in our network and i get the info. It seems to have something to do with getting the list of names into the ComputerName property.

Here is the error I get:

Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:4 char:16

  • $sysobj1 = Get-WmiObject -Class win32_computersystem -ComputerName $computer
    
  •            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:slight_smile: [Get-WmiObject], COMException
    • FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:5 char:16

  • $sysobj2 = Get-WmiObject -Class Win32_systemenclosure -ComputerName $compute ...
    
  •            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:slight_smile: [Get-WmiObject], COMException
    • FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

you may need to use enable-psremoting on those computers then retry

If I needed to enable psremoting would I be able to run

Get-WmiObject -Class win32_computersystem -ComputerName

on individual computers?

try this using the function here

you may need this to get that function to work.
https://psremoteregistry.codeplex.com/

$computer = 'Workstation1'
enable-psremoting $computer
gwmi win32_computersystem -comp $computer

My apologies Anthony. Your script does work. Apparently a large number of the computers in my list are not one line.

Thank you very much for your assistance!