Author Posts

May 3, 2016 at 11:09 am

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!

May 3, 2016 at 11:25 am

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

May 3, 2016 at 11:52 am

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: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

May 3, 2016 at 12:02 pm

$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

May 3, 2016 at 12:27 pm

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.

May 3, 2016 at 12:46 pm

Try my comment again.

May 4, 2016 at 5:42 am

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: (:) [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: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

May 4, 2016 at 6:00 am

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

May 4, 2016 at 6:28 am

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

Get-WmiObject -Class win32_computersystem -ComputerName

on individual computers?

May 4, 2016 at 6:44 am

try this using the function here

https://github.com/gangstanthony/PowerShell/blob/master/Enable-PSRemoting.ps1
you may need this to get that function to work.
https://psremoteregistry.codeplex.com/

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

May 4, 2016 at 6:52 am

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!