Doing work on a list .csv list of computernames

This topic contains 10 replies, has 3 voices, and was last updated by Profile photo of Chris Ediger Chris Ediger 4 months, 3 weeks ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #38536
    Profile photo of Chris Ediger
    Chris Ediger
    Participant

    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!

    #38537
    Profile photo of Anthony Stringer
    Anthony Stringer
    Participant

    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
    
    #38539
    Profile photo of Chris Ediger
    Chris Ediger
    Participant

    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

    #38540
    Profile photo of random commandline
    random commandline
    Participant
    $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
    
    #38543
    Profile photo of Chris Ediger
    Chris Ediger
    Participant

    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.

    #38544
    Profile photo of random commandline
    random commandline
    Participant

    Try my comment again.

    #38569
    Profile photo of Chris Ediger
    Chris Ediger
    Participant

    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

    #38570
    Profile photo of Anthony Stringer
    Anthony Stringer
    Participant

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

    #38573
    Profile photo of Chris Ediger
    Chris Ediger
    Participant

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

    Get-WmiObject -Class win32_computersystem -ComputerName

    on individual computers?

    #38575
    Profile photo of Anthony Stringer
    Anthony Stringer
    Participant

    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
    
    #38576
    Profile photo of Chris Ediger
    Chris Ediger
    Participant

    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!

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.