Find computer model from a .txt

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 2 years, 2 months ago.

  • Author
  • #37026

    Mario Rico

    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

    Don Jones

    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

You must be logged in to reply to this topic.