Find computer model from a .txt

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #37026
    Profile photo of Mario Rico
    Mario Rico
    Participant

    Hi guys,

    im running the script bellow to find out the model for a group of computer and it runs fine for a couple of pc then it freeze and will not continue. so two things i want to do but dont know how

    1. how can i make it out put the results on to a txt file
    2. how can i tell it if no reply skip and let me know that is skip it

    $computers = Get-Content C:\Users\1983865\Desktop\computers.txt
    Get-wmiobject Win32_ComputerSystem -ComputerName $computers |
    Select-Object Model

    #37032
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Something vaguely like this – at least to give you an idea of the logic. This might not be exactly what you need. I suggest getting "Learn PowerShell Toolmaking in a Month of Lunches" as it's designed to help you for exactly this kind of task. Note that this won't stop a "freeze and won't continue" situation – with WMI, there's no way to break the connection if the remote computer is holding it. It's a known weakness in WMI.

    $computers = Get-Content C:\Users\1983865\Desktop\computers.txt
    foreach ($computer in $computers) {
      Try {
        Get-wmiobject Win32_ComputerSystem -ComputerName $computer -EA Stop |
        Select-Object PSComputerName,Model |
        Out-File output.txt -append
      } catch {
        "$computer,UNKNOWN" | Out-File output.txt -append
      }
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.