Author Posts

December 8, 2016 at 11:08 am

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

December 8, 2016 at 11:25 am

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.

December 8, 2016 at 11:41 am

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

December 8, 2016 at 4:05 pm

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.

December 9, 2016 at 8:03 am

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

December 9, 2016 at 1:39 pm

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