Getting Computer name, serial number and model of list of machines

Welcome Forums General PowerShell Q&A Getting Computer name, serial number and model of list of machines

  • This topic has 5 replies, 3 voices, and was last updated 3 years ago by
    Participant
    .
Viewing 5 reply threads
  • Author
    Posts
    • #59760
      Participant
      Topics: 1
      Replies: 2
      Points: 0
      Rank: Member

      How can I get this script to show serial number as well as name and model in the output? Also I would like to output to Excel.
      Also, is using a txt file list the best way to input the list of PCs?

      I am just getting my feet wet in PS Scripting so would love some assistance.

      $computers = Get-Content c:\pstest\computerlist.txt
      
      Get-WmiObject Win32_ComputerSystem -ComputerName $computers | select name,model
      Get-WmiObject Win32_BIOS -ComputerName $computers | select serialnumber
      
    • #59772
      Participant
      Topics: 1
      Replies: 1635
      Points: 3,089
      Helping Hand
      Rank: Community Hero

      You will have to create an object and concatenate the output of your 2 commands. Then you can pipe that output to whatever you like / need. In my example here it's piped to a csv file what's almost perfect to open it in Excel. 😉

      $computer = Get-Content c:\pstest\computerlist.txt
      $Output = Foreach($C in $computer){
          $System = Get-WmiObject Win32_ComputerSystem -ComputerName $C | Select-Object -Property Name,Model
          $BIOS = Get-WmiObject Win32_BIOS -ComputerName $C | Select-Object -Property SerialNumber
      	[PSCustomObject]@{
              ComputerName = $C
      		Name = $System.Name
      		Model = $System.Model
              SerialNumber = $BIOS.SerialNumber
      	}
      }
      $Output
      
      $Output |Export-Csv -Path c:\pstest\Result.csv -NoTypeInformation
      

      If you just have a simple list of items, a text file with a single item on each line is just fine.

    • #59773
      Participant
      Topics: 1
      Replies: 2
      Points: 0
      Rank: Member

      That's brilliant, thanks, is there any way to get primary user for the list of devices generated in this script?

    • #59791
      Participant
      Topics: 0
      Replies: 1
      Points: 1
      Rank: Member

      You could add on a line on 5 like:

       $DomainUsers = Get-WmiObject Win32_NetworkLoginProfile -ComputerName $C | Select-Object -Property Name 

      and then bring it in on 9/10 with:

       Users = $DomainUsers.Name 

      If not exactly what your looking for, Win32_NetworkLoginProfile seems to be close to what your seeking and should have an answer at least.

    • #59869
      Participant
      Topics: 1
      Replies: 2
      Points: 0
      Rank: Member

      I settled on this using Configuration Manager. Though now I run into RPC server unavailable errors for some of the machines. Though that's a separate issue.
      Thanks for your help and suggestions. Powershell is a powerful tool that I am keen to learn.

      if (-not (Get-Module ConfigurationManager)) 
       { 
       Write-Host “Loading Configuration Manager" 
      import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1') 
       $PSD = Get-PSDrive -PSProvider CMSite 
       $SiteCode = $PSD.Name 
       CD “$($PSD):” 
      } 
      ELSE {Write-Host “Configuration Manager Already Loaded”}
      
      $computer = Get-Content c:\pstest\computerlist.txt
      $Output = Foreach($C in $computer){
          $System = Get-WmiObject Win32_ComputerSystem -ComputerName $C | Select-Object -Property Name,Model
          $BIOS = Get-WmiObject Win32_BIOS -ComputerName $C | Select-Object -Property SerialNumber
      	$User = Get-CMUserDeviceAffinity -DeviceName $c | Select-Object -Property UniqueUserName
              [PSCustomObject]@{
                      ComputerName = $C
      		Name = $System.Name
      		Model = $System.Model
              SerialNumber = $BIOS.SerialNumber
              User = $User.UniqueUserName
      	}
      }
      $Output
      
      $Output |Export-Csv -Path c:\pstest\Result.csv -NoTypeInformation
      
    • #59886
      Participant
      Topics: 1
      Replies: 1635
      Points: 3,089
      Helping Hand
      Rank: Community Hero

      If you like to learn a little more about Powershell and spend some time you could take a look at this:
      MVA Advanced Tools and Scripting with Powershell 3.0 Jump Start
      When they come to the lession for error handling that fits almost prefectly to your RPC unavailable errors you mentioned. 😉

Viewing 5 reply threads
  • The topic ‘Getting Computer name, serial number and model of list of machines’ is closed to new replies.