Remote PCs inventory RRS feed

  • Question

  • Hello guys.

    I'm very new in Powershell and I'm trying to find the script for remote PCs inventory in corporate network. I have desktops host names in txt file. In result I need to get desktops SN; Desktop Model and connected Monitors SN, Models. I found one script but unfortunately it shows only desktop SN and only one monitor SN. The second monitors SN it doesn't show.

    if anyone can help me I will be very grateful.

    $testcomputers = Get-Content -Path 'C:\scripts\computers.txt'
    $exportLocation = 'C:\scripts\pcInventory.csv'
    # Test connection to each computer before getting the inventory info
    foreach ($computer in $testcomputers) {
      if (Test-Connection -ComputerName $computer -Quiet -count 2){
        Add-Content -value $computer -path c:\scripts\livePCs.txt
        Add-Content -value $computer -path c:\scripts\deadPCs.txt
    # Now that we know which PCs are live on the network
    # proceed with the inventory
    $computers = Get-Content -Path 'C:\scripts\livePCs.txt'
    foreach ($computer in $computers) {
        $Bios = Get-WmiObject win32_bios -Computername $Computer
        $Hardware = Get-WmiObject Win32_computerSystem -Computername $Computer
        $Sysbuild = Get-WmiObject Win32_WmiSetting -Computername $Computer
        $OS = Get-WmiObject Win32_OperatingSystem -Computername $Computer
        $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer | Where-Object {$_.IPEnabled}
        $driveSpace = Get-WmiObject win32_volume -computername $Computer -Filter 'drivetype = 3' | 
        Select-Object PScomputerName, driveletter, label, @{LABEL='GBfreespace';EXPRESSION={'{0:N2}' -f($_.freespace/1GB)} } |
        Where-Object { $_.driveletter -match 'C:' }
        $cpu = Get-WmiObject Win32_Processor  -computername $computer
        $username = Get-ChildItem "\\$computer\c$\Users" | Sort-Object LastWriteTime -Descending | Select-Object Name, LastWriteTime -first 1
        $totalMemory = [math]::round($Hardware.TotalPhysicalMemory/1024/1024/1024, 2)
        $lastBoot = $OS.ConvertToDateTime($OS.LastBootUpTime) 
        $IPAddress  = $Networks.IpAddress[0]
        $MACAddress  = $Networks.MACAddress
        $systemBios = $Bios.serialnumber
     # Monitor(s)
        $MonitorInfo = gwmi WmiMonitorID -Namespace root\wmi -computername  $computer |
          Select -last 1 @{n="Model"; e={[System.Text.Encoding]::ASCII.GetString($_.UserFriendlyName -ne 00)}},
            @{n="Serial Number";e={[System.Text.Encoding]::ASCII.GetString($_.SerialNumberID -ne 00)}}  
        $OutputObj  = New-Object -Type PSObject
        $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()
        $OutputObj | Add-Member -MemberType NoteProperty -Name Manufacturer -Value $Hardware.Manufacturer
        $OutputObj | Add-Member -MemberType NoteProperty -Name Model -Value $Hardware.Model
        $OutputObj | Add-Member -MemberType NoteProperty -Name Processor_Type -Value $cpu.Name
        $OutputObj | Add-Member -MemberType NoteProperty -Name System_Type -Value $Hardware.SystemType
        $OutputObj | Add-Member -MemberType NoteProperty -Name Operating_System -Value $OS.Caption
        $OutputObj | Add-Member -MemberType NoteProperty -Name Operating_System_Version -Value $OS.version
        $OutputObj | Add-Member -MemberType NoteProperty -Name Operating_System_BuildVersion -Value $SysBuild.BuildVersion
        $OutputObj | Add-Member -MemberType NoteProperty -Name Serial_Number -Value $systemBios
        $OutputObj | Add-Member -MemberType NoteProperty -Name IP_Address -Value $IPAddress
        $OutputObj | Add-Member -MemberType NoteProperty -Name MAC_Address -Value $MACAddress
        $OutputObj | Add-Member -MemberType NoteProperty -Name Last_User -Value $username.Name
        $OutputObj | Add-Member -MemberType NoteProperty -Name User_Last_Login -Value $username.LastWriteTime
        $OutputObj | Add-Member -MemberType NoteProperty -Name C:_FreeSpace_GB -Value $driveSpace.GBfreespace
        $OutputObj | Add-Member -MemberType NoteProperty -Name Total_Memory_GB -Value $totalMemory
        $OutputObj | Add-Member -MemberType NoteProperty -Name Last_ReBoot -Value $lastboot
        $OutputObj | Add-Member -MemberType NoteProperty -Name "Monitor 1" -Value $MonitorInfo.Model
        $OutputObj | Add-Member -MemberType NoteProperty -Name "Monitor 1 Serial Number" -Value $MonitorInfo."Serial Number"    
        $OutputObj | Export-Csv $exportLocation -Append -NoTypeInformation

    Saturday, December 21, 2019 6:38 PM

All replies

  • In this technical forum we do not rewrite scripts you have found on the Internet. THe forum is for technicians who are writing their own sripts and have questions about a script they are writing.

    YOU are also not asking a question.  You have just copied a script and are asking someone to rewrite it for you.

    Start by taking the time to learn PowerShell and then ask a specific question about a script.

    See the post at the top of this forum for guidance on using this forum: This forum is for scripting questions rather than script requests

    Learning to script properly with PowerShell


    Saturday, December 21, 2019 7:03 PM
  • Thank you for prompt response and provided training materials. I did some small changes in this sript, initially it didnt show monitor sn. But i can't understand how to get second monitor sn only. How to use Foreach ($monitor in $monitors) function in my case, cause monitors sn need to encode also. It's hard for me at the moment. I suppose there are only few rows of code. I tried many variables but without success. Off course I will read provided links. I just created this post because didn't fin dthe correct script. Sorry for inconvenience.
    Saturday, December 21, 2019 7:50 PM
  • There are scripts in the Gallery that get the monitor serial number. It can be different for different OSs.

    Here is the method for most cur5rent systems since Win7:

    $monitor = Get-CimInstance WMIMonitorID -Namespace root\wmi


    Saturday, December 21, 2019 8:29 PM