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

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Olaf Soyk Olaf Soyk 7 months, 2 weeks ago.

  • Author
    Posts
  • #59760
    Profile photo of Errol
    Errol
    Participant

    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
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    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
    Profile photo of Errol
    Errol
    Participant

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

  • #59791
    Profile photo of Bryan Hoffower
    Bryan Hoffower
    Participant

    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
    Profile photo of Errol
    Errol
    Participant

    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
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    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. 😉

You must be logged in to reply to this topic.