• PowerShell PC Information Utility

    Home » Forums » Developers, developers, developers » DevOps Lounge » PowerShell PC Information Utility

    Author
    Topic
    #478259

    Hello again All,

    Continuing my quest to learn PowerShell I’ve heavily modified the PC Info Script by Trenton Ivey. The original is designed to work over a network and provide information topic by topic. My modification gets all the information at once and where I’ve really expended time and learning is in the formatting of that data. The above link will let you look at the original and compare it with my humble contribution.

    To use the script, copy the code below and paste it into Notepad.
    Save the file as “CMsPCInfo.ps1” {Note: include the quotes so Notepad doesn’t add the .txt extension.}

    To run the program start PowerShell {Included in Win-7 others can download from MS} as Administrator.
    Type d:pathCMsPCInfo.ps1 ‘your computer name’
    Ex: G:DocsScriptCMsPCInfo ‘Joes-PC’ {enter}
    If you forget to add the PC name you will be prompted for it.

    If you want the results in a file simply redirect ex:
    G:DocsScriptCMsPCInfo ‘Joes-PC’ > G:DocsMyPCInfo.txt {enter}

    Code:
    # +——————————————————+
    # | Computer Mentors System Information V3.0             |
    # | Code adapted from:                                   |
    # |          Powershell PC Info Script V1.0b             | 
    # |             Coded By:Trenton Ivey(kno)               | 
    # |                    hackyeah.com                      | 
    # +——————————————————+
     
    function Pause ($Message=”Press any key to continue…”){ 
        “” 
        Write-Host $Message 
        $null = $Host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”) 
    } 
     
     
    function GetCompName{ 
        $compname = Read-Host “Please enter a computer name or IP” 
        CheckHost 
    } 
     
    function CheckHost{ 
        $ping = gwmi Win32_PingStatus -filter “Address=’$compname'” 
        if($ping.StatusCode -ne 0){Pause “Host $compname down…Press any key to continue”; GetCompName} 
    } 
         
    Function ShowInfo { 
    
          “General Computer Information:`n”
          # Create Table
           $CITable = New-Object system.Data.DataTable “Computer Information”
    #Create Columns for table 
           $CITcol1 = New-Object system.Data.DataColumn Item,([string])       
           $CITcol2 = New-Object system.Data.DataColumn Value,([string])
    #Add Columns to table
           $CITable.columns.add($CITcol1)
           $CITable.columns.add($CITcol2)
          $I = gwmi -computer $compname Win32_ComputerSystem    
    #Create Row Variable 
          $CITRow = $CITable.NewRow()
    #Assign items to row variable
          $CITRow.Item = ‘Computer Name’ 
          $CITRow.Value = $I.Name
    #Add Row to Table using Row Variable
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘Domain Name’
          $CITRow.Value = $I.Domain
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘Manufacturer’
          $CITRow.Value = $I.Manufacturer
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘Model’
          $CITRow.Value = $I.Model
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘System Type’
          $CITRow.Value = $I.SystemType
          $CITable.Rows.Add($CITRow)
          
          $I = gwmi -computer $compname Win32_BIOS
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘Serial Number’
          $CITRow.Value = $I.SerialNumber
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘BIOS Name’
          $CITRow.Value = $I.Name
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘     Version’
          $CITRow.Value = $I.SMBIOSBIOSVersion
          $CITable.Rows.Add($CITRow)
    
          $I = gwmi -computer $compname Win32_ComputerSystem
    
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘Current User ID’
          $CITRow.Value = $I.Username
          $CITable.Rows.Add($CITRow)
          
          $I = gwmi -computer $compname Win32_OperatingSystem
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘OS Name’
          $CITRow.Value = $I.Caption
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘Serial Number’
          $CITRow.Value = $I.SerialNumber
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘OS Bit Width’
          $CITRow.Value = $I.OSArchitecture
          $CITable.Rows.Add($CITRow)
          
          $I = gwmi -computer $compname Win32_Processor
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘Processor Name’
          $CITRow.Value = $I.Name
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘          Info’
          $CITRow.Value = $I.Caption
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘          Maker’
          $CITRow.Value = $I.Manufacturer
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘          ID’
          $CITRow.Value = $I.ProcessorId
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘          Cores’
          $CITRow.Value = $I.NumberofCores
          $CITable.Rows.Add($CITRow)
    
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘Address Width’
          $CITRow.Value = $I.AddressWidth
          $CITable.Rows.Add($CITRow)
     
     $wmi = gwmi -computer $compname Win32_OperatingSystem
     
          $localdatetime = $wmi.ConvertToDateTime($wmi.LocalDateTime) 
          $lastbootuptime = $wmi.ConvertToDateTime($wmi.LastBootUpTime) 
    
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘Time Current’
          $CITRow.Value = $LocalDateTime
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘     Last Boot’
          $CITRow.Value = $LastBootUpTime
          $CITable.Rows.Add($CITRow)
          
          $CITRow = $CITable.NewRow()
          $CITRow.Item = ‘     Total Up’
          $CITRow.Value = $localdatetime – $lastbootuptime
          $CITable.Rows.Add($CITRow)
          
    #Output table
          $fmt = @{Expression={$_.Item};Label=”Item”;width=20},
                 @{Expression={$_.Value};Label=”Value”;Width=40}
                 
          $CITable | Select-Object Item,Value | Format-Table $fmt
          
    #PC Printer Information 
                “Installed Printer Information:”
                gwmi -computer $compname Win32_Printer | Select-Object DeviceID,DriverName, PortName | Format-Table -autosize
                
    #Disk Info 
                “Drive Information:”
                $fmt = @{Expression={$_.Name};Label=”Drive Letter”;width=12},
                         @{Expression={$_.VolumeName};Label=”Vol Name”;Width=15},
                         @{Expression={ ‘{0:#,000.00}’ -f ($_.Size/1gb)};Label=”Disk Size / GB”;width=14},
                         @{Expression={ ‘{0:#,000.00}’ -f ($_.FreeSpace/1gb)};Label=”Free Space / GB”;width=15}
                         
                $wmi = gwmi -computer $compname Win32_logicaldisk 
                $wmi | Format-Table $fmt
    
    #Memory Info 
                “Memory Information:”
                $fmt = @{Expression={$_.Speed};Label=”Speed”;width=20},
                       @{Expression={$_.DataWidth};Label=”Data Width”;width=10},
                       @{Expression={ ‘{0:#.00}’ -f ($_.Capacity/1gb)};Label=”Module Size / GB”;width=16},
                       @{Expression={$_.DeviceLocator};Label=”Slot”;width=6},
                       @{Expression={$_.SerialNumber};Label=”Serial No.”}
    
                $wmi = gwmi -computer $compname Win32_PhysicalMemory 
                $wmi | Format-Table $fmt
    
    #Monitor Info 
                “Monitor Information:” 
                #Turn off Error Messages 
                $ErrorActionPreference_Backup = $ErrorActionPreference 
                $ErrorActionPreference = “SilentlyContinue” 
     
     
                $keytype=[Microsoft.Win32.RegistryHive]::LocalMachine 
                if($reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$compname)){ 
                    #Create Table To Hold Info 
                    $montable = New-Object system.Data.DataTable “Monitor Info” 
                    #Create Columns for Table 
                    $moncol1 = New-Object system.Data.DataColumn Name,([string]) 
                    $moncol2 = New-Object system.Data.DataColumn Serial,([string]) 
                    $moncol3 = New-Object system.Data.DataColumn Ascii,([string]) 
                    #Add Columns to Table 
                    $montable.columns.add($moncol1) 
                    $montable.columns.add($moncol2) 
                    $montable.columns.add($moncol3) 
     
     
     
                    $regKey= $reg.OpenSubKey(“SYSTEM\CurrentControlSet\EnumDISPLAY” ) 
                    $HID = $regkey.GetSubKeyNames() 
                    foreach($HID_KEY_NAME in $HID){ 
                        $regKey= $reg.OpenSubKey(“SYSTEM\CurrentControlSet\Enum\DISPLAY\$HID_KEY_NAME” ) 
                        $DID = $regkey.GetSubKeyNames() 
                        foreach($DID_KEY_NAME in $DID){ 
                            $regKey= $reg.OpenSubKey(“SYSTEM\CurrentControlSet\Enum\DISPLAY\$HID_KEY_NAME\$DID_KEY_NAME\Device Parameters” ) 
                            $EDID = $regKey.GetValue(“EDID”) 
                            foreach($int in $EDID){ 
                                $EDID_String = $EDID_String+([char]$int) 
                            } 
                            #Create new row in table 
                            $monrow=$montable.NewRow() 
                             
                            #MonitorName 
                            $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFC + [char]0x00            
                            $matchfound = $EDID_String -match “$checkstring([w ]+)” 
                            if($matchfound){$monrow.Name = [string]$matches[1]} else {$monrow.Name = ‘-‘} 
     
                             
                            #Serial Number 
                            $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFF + [char]0x00            
                            $matchfound =  $EDID_String -match “$checkstring(S+)” 
                            if($matchfound){$monrow.Serial = [string]$matches[1]} else {$monrow.Serial = ‘-‘} 
                                                     
                            #AsciiString 
                            $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFE + [char]0x00            
                            $matchfound = $EDID_String -match “$checkstring([w ]+)” 
                            if($matchfound){$monrow.Ascii = [string]$matches[1]} else {$monrow.Ascii = ‘-‘}          
     
                                     
                            $EDID_String = ” 
                             
                            $montable.Rows.Add($monrow) 
                        }   # End – foreach($DID_KEY_NAME in $DID)
                        
                    } # End – foreach($HID_KEY_NAME in $HID)
                    
                    $montable | select-object  -unique Serial,Name,Ascii | Where-Object {$_.Serial -ne “-“} | Format-Table 
                     
                }   # End If
                
                else {  
                    Write-Host “Access Denied – Check Permissions” 
                } 
                
    } #End Function ShowInfo
     
    #———Start Main————– 
    $compname = $args[0] 
    Clear-Host
    if($compname){CheckHost} 
    else{GetCompName}
    ShowInfo

    Enjoy…Comments welcome and appreciated! :cheers:

    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!
    Computer Specs

    Viewing 8 reply threads
    Author
    Replies
    • #1292195

      I tried it and got several errors. Are you running this on Win7?

      When I get a chance I’ll try again and post the errors.

      Joe

      --Joe

      • #1292329

        Joe,

        Yes, This was built & tested on Win-7 HP 64 Bit. Unfortunately, I am currently on the road in our motorhome and don’t have a Win XP machine to test it on. :cheers:

        May the Forces of good computing be with you!

        RG

        PowerShell & VBA Rule!
        Computer Specs

    • #1292357

      I tried it on a Win7 Ultimate X64 machine. Haven’t yet had a chance to try again.

      Joe

      --Joe

    • #1292536

      Tried it again. Got it to work as long as I included the PC name in the call. If I omit the PC name and respond to the prompt I get a lot of errors “Can not validate parameter on argument ‘ComputerName’.

      Joe

      --Joe

    • #1292662

      Joe,

      Ok, I did some more work on this and it looks like I had a Scope problem. I fixed it by using the Global scope modifier in all the functions. I know there has to be a better way but for now it does work. Also, you do NOT need to place single quotes around the argument as previously stated, unless there is a space in the computer name. I also tested it using an IP address and that also worked both ways w/o single quotes.

      Here’s the revised code:

      Code:
      # +——————————————————+
      # | Computer Mentors System Information V4.0             |
      # | Code adapted from:                                   |
      # |          Powershell PC Info Script V1.0b             | 
      # |             Coded By:Trenton Ivey(kno)               | 
      # |                    hackyeah.com                      | 
      # +——————————————————+
       
      function Pause ($Message=”Press any key to continue…”){ 
          “” 
          Write-Host $Message 
          $null = $Host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”) 
      } 
       
       
      function GetCompName{ 
          $global:compname = Read-Host “Please enter a computer name or IP” 
          CheckHost 
      } 
       
      function CheckHost{ 
          $ping = gwmi Win32_PingStatus -filter “Address=’$global:compname'” 
          if($ping.StatusCode -ne 0){Pause “Host $compname down…Press any key to continue”; GetCompName} 
      } 
           
      Function ShowInfo { 
      
            Clear-Host
            “General Computer Information:`n”
            # Create Table
             $CITable = New-Object system.Data.DataTable “Computer Information”
      #Create Columns for table 
             $CITcol1 = New-Object system.Data.DataColumn Item,([string])       
             $CITcol2 = New-Object system.Data.DataColumn Value,([string])
      #Add Columns to table
             $CITable.columns.add($CITcol1)
             $CITable.columns.add($CITcol2)
            $I = gwmi -computer $global:compname Win32_ComputerSystem    
      #Create Row Variable 
            $CITRow = $CITable.NewRow()
      #Assign items to row variable
            $CITRow.Item = ‘Computer Name’ 
            $CITRow.Value = $I.Name
      #Add Row to Table using Row Variable
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Domain Name’
            $CITRow.Value = $I.Domain
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Manufacturer’
            $CITRow.Value = $I.Manufacturer
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Model’
            $CITRow.Value = $I.Model
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘System Type’
            $CITRow.Value = $I.SystemType
            $CITable.Rows.Add($CITRow)
            
            $I = gwmi -computer $global:compname Win32_BIOS
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Serial Number’
            $CITRow.Value = $I.SerialNumber
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘BIOS Name’
            $CITRow.Value = $I.Name
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘     Version’
            $CITRow.Value = $I.SMBIOSBIOSVersion
            $CITable.Rows.Add($CITRow)
      
            $I = gwmi -computer $global:compname Win32_ComputerSystem
      
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Current User ID’
            $CITRow.Value = $I.Username
            $CITable.Rows.Add($CITRow)
            
            $I = gwmi -computer $global:compname Win32_OperatingSystem
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘OS Name’
            $CITRow.Value = $I.Caption
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Serial Number’
            $CITRow.Value = $I.SerialNumber
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘OS Bit Width’
            $CITRow.Value = $I.OSArchitecture
            $CITable.Rows.Add($CITRow)
            
            $I = gwmi -computer $global:compname Win32_Processor
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Processor Name’
            $CITRow.Value = $I.Name
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘          Info’
            $CITRow.Value = $I.Caption
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘          Maker’
            $CITRow.Value = $I.Manufacturer
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘          ID’
            $CITRow.Value = $I.ProcessorId
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘          Cores’
            $CITRow.Value = $I.NumberofCores
            $CITable.Rows.Add($CITRow)
      
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Address Width’
            $CITRow.Value = $I.AddressWidth
            $CITable.Rows.Add($CITRow)
       
       $wmi = gwmi -computer $global:compname Win32_OperatingSystem
       
            $localdatetime = $wmi.ConvertToDateTime($wmi.LocalDateTime) 
            $lastbootuptime = $wmi.ConvertToDateTime($wmi.LastBootUpTime) 
      
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Time Current’
            $CITRow.Value = $LocalDateTime
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘     Last Boot’
            $CITRow.Value = $LastBootUpTime
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘     Total Up’
            $CITRow.Value = $localdatetime – $lastbootuptime
            $CITable.Rows.Add($CITRow)
            
      #Output table
            $fmt = @{Expression={$_.Item};Label=”Item”;width=20},
                   @{Expression={$_.Value};Label=”Value”;Width=40}
                   
            $CITable | Select-Object Item,Value | Format-Table $fmt
            
      #PC Printer Information 
                  “Installed Printer Information:”
                  gwmi -computer $global:compname Win32_Printer | Select-Object DeviceID,DriverName, PortName | Format-Table -autosize
                  
      #Disk Info 
                  “Drive Information:”
                  $fmt = @{Expression={$_.Name};Label=”Drive Letter”;width=12},
                           @{Expression={$_.VolumeName};Label=”Vol Name”;Width=15},
                           @{Expression={ ‘{0:#,000.00}’ -f ($_.Size/1gb)};Label=”Disk Size / GB”;width=14},
                           @{Expression={ ‘{0:#,000.00}’ -f ($_.FreeSpace/1gb)};Label=”Free Space / GB”;width=15}
                           
                  $wmi = gwmi -computer $global:compname Win32_logicaldisk 
                  $wmi | Format-Table $fmt
      
      #Memory Info 
                  “Memory Information:”
                  $fmt = @{Expression={$_.Speed};Label=”Speed”;width=20},
                         @{Expression={$_.DataWidth};Label=”Data Width”;width=10},
                         @{Expression={ ‘{0:#.00}’ -f ($_.Capacity/1gb)};Label=”Module Size / GB”;width=16},
                         @{Expression={$_.DeviceLocator};Label=”Slot”;width=6},
                         @{Expression={$_.SerialNumber};Label=”Serial No.”}
      
                  $wmi = gwmi -computer $global:compname Win32_PhysicalMemory 
                  $wmi | Format-Table $fmt
      
      #Monitor Info 
                  “Monitor Information:” 
                  #Turn off Error Messages 
                  $ErrorActionPreference_Backup = $ErrorActionPreference 
                  $ErrorActionPreference = “SilentlyContinue” 
       
       
                  $keytype=[Microsoft.Win32.RegistryHive]::LocalMachine 
                  if($reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$global:compname)){ 
                      #Create Table To Hold Info 
                      $montable = New-Object system.Data.DataTable “Monitor Info” 
                      #Create Columns for Table 
                      $moncol1 = New-Object system.Data.DataColumn Name,([string]) 
                      $moncol2 = New-Object system.Data.DataColumn Serial,([string]) 
                      $moncol3 = New-Object system.Data.DataColumn Ascii,([string]) 
                      #Add Columns to Table 
                      $montable.columns.add($moncol1) 
                      $montable.columns.add($moncol2) 
                      $montable.columns.add($moncol3) 
       
       
       
                      $regKey= $reg.OpenSubKey(“SYSTEM\CurrentControlSet\EnumDISPLAY” ) 
                      $HID = $regkey.GetSubKeyNames() 
                      foreach($HID_KEY_NAME in $HID){ 
                          $regKey= $reg.OpenSubKey(“SYSTEM\CurrentControlSet\Enum\DISPLAY\$HID_KEY_NAME” ) 
                          $DID = $regkey.GetSubKeyNames() 
                          foreach($DID_KEY_NAME in $DID){ 
                              $regKey= $reg.OpenSubKey(“SYSTEM\CurrentControlSet\Enum\DISPLAY\$HID_KEY_NAME\$DID_KEY_NAME\Device Parameters” ) 
                              $EDID = $regKey.GetValue(“EDID”) 
                              foreach($int in $EDID){ 
                                  $EDID_String = $EDID_String+([char]$int) 
                              } 
                              #Create new row in table 
                              $monrow=$montable.NewRow() 
                               
                              #MonitorName 
                              $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFC + [char]0x00            
                              $matchfound = $EDID_String -match “$checkstring([w ]+)” 
                              if($matchfound){$monrow.Name = [string]$matches[1]} else {$monrow.Name = ‘-‘} 
       
                               
                              #Serial Number 
                              $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFF + [char]0x00            
                              $matchfound =  $EDID_String -match “$checkstring(S+)” 
                              if($matchfound){$monrow.Serial = [string]$matches[1]} else {$monrow.Serial = ‘-‘} 
                                                       
                              #AsciiString 
                              $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFE + [char]0x00            
                              $matchfound = $EDID_String -match “$checkstring([w ]+)” 
                              if($matchfound){$monrow.Ascii = [string]$matches[1]} else {$monrow.Ascii = ‘-‘}          
       
                                       
                              $EDID_String = ” 
                               
                              $montable.Rows.Add($monrow) 
                          }   # End – foreach($DID_KEY_NAME in $DID)
                          
                      } # End – foreach($HID_KEY_NAME in $HID)
                      
                      $montable | select-object  -unique Serial,Name,Ascii | Where-Object {$_.Serial -ne “-“} | Format-Table 
                       
                  }   # End If
                  
                  else {  
                      Write-Host “Access Denied – Check Permissions” 
                  } 
                  
      } #End Function ShowInfo
       
      #———Start Main————– 
      $compname = $args[0] 
      Clear-Host
      if($compname){CheckHost} 
      else{GetCompName}
      ShowInfo

      I’ll keep working on this to get rid of the Global scope variables as I am fully aware that is considered poor programming. The learning curve continues. 😆 :cheers:

      Update: I just noticed that it does not return Monitor Information on my laptop…previous versions worked on my dual monitor desktop!

      Code:
      General Computer Information:
      
      
      Item                 Value                                   
      —-                 —–                                   
      Computer Name        INSPIRON15-I5                           
      Domain Name          HOME                                    
      Manufacturer         Dell Inc.                               
      Model                Inspiron 1564                           
      System Type          x64-based PC                            
      Serial Number        2ND58M1                                 
      BIOS Name            Ver 1.00 BIOS A13 PARTTBL               
           Version         A13                                     
      Current User ID      Inspiron15-i5Bruce                     
      OS Name              Microsoft Windows 7 Home Premium        
      Serial Number        00359-OEM-8992687-00095                 
      OS Bit Width         64-bit                                  
      Processor Name       Intel(R) Core(TM) i5 CPU       M 430 …
                Info       Intel64 Family 6 Model 37 Stepping 2    
                Maker      GenuineIntel                            
                ID         BFEBFBFF00020652                        
                Cores      2                                       
      Address Width        64                                      
      Time Current         08/11/11 11:26:04                       
           Last Boot       08/11/11 10:42:23                       
           Total Up        00:43:41.2260010                        
      
      
      Installed Printer Information:
      
      DeviceID                          DriverName                    PortName                         
      ——–                          ———-                    ——–                         
      PrimoPDF                          PrimoPDF                      PrimoPort:                       
      PDFCreator                        PDFCreator                    PDFCreator:                      
      Microsoft XPS Document Writer     Microsoft XPS Document Writer XPSPort:                         
      HP Photosmart D110 series         HP Photosmart D110 series     HP_192.168.123.110_CN0BBG40D105N9
      Fax                               Microsoft Shared Fax Driver   SHRFAX:                          
      Brother HL-5370DW series          Brother HL-5370DW series      192.168.1.104                    
      \JanetsLaptophp psc 2400 series hp psc 2400 series            USB001                           
      
      
      Drive Information:
      
      Drive Letter Vol Name Disk Size / GB Free Space / GB
      ———— ——– ————– —————
      C:           OS       068.45         027.26         
      D:                    000.00         000.00         
      G:                    229.63         217.44         
      
      
      Memory Information:
      
      Speed Data Width Module Size / GB Slot   Serial No.      
      —– ———- —————- —-   ———-      
       1067         64 2.00             DIMM_A 95B5E0D9        
       1067         64 2.00             DIMM_B 95B5E119        
      
      
      Monitor Information:
      
      

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1292672

      Cool. Thanks for the update.

      Sometimes the programming curves lead you off a cliff.:o: 😎

      Joe

      --Joe

    • #1293224

      Hello Again,

      I need some assistance from y’all. As I’m currently traveling in my moto rhome I don’t have access to my desktops. I’d appreciate it very much if some of you would run the PowerShell program below and post back with the results. I need at least one person with a Full Tower and one with a Mini-Tower. It would also be great if someone with an all-in-one {Screen & System Unit in one but not a laptop} could run the script. Actually, now that I found what all the codes are the more people who run it the better! The purpose of this is to find the reported numbers so I can add that function to the code above and also tune the Monitor information code for laptops if being run from a laptop. Of course anyone who wants to run it on their machine and report back will be appreciated to verify that results are consistent. Thanks again.

      Code:
      # +——————————————————+
      # | Computer Mentors Chassis Information V1.0            |
      # + —————————————————–+
      Clear-Host
      $compname = Read-Host “Please enter a computer name:” 
      $ChassisType = Read-Host “Please enter your system unit type Tower, Mini-Tower, Laptop”
      $I = gwmi -computer $compname Win32_SystemEnclosure
      “User Classification: $ChassisType”
      $SysClass = “System Classification: ”
      $ChassisNo = $I.ChassisTypes[0]
      Switch ($I.ChassisTypes[0])
      {
        1 { “$SysClass $ChassisNo Other” }
        2 { “$SysClass $ChassisNo Unknown” }
        3 { “$SysClass $ChassisNo Desktop” }
        4 { “$SysClass $ChassisNo Low Profile Desktop” }
        5 { “$SysClass $ChassisNo Pizza Box” }
        6 { “$SysClass $ChassisNo Mini Tower” }
        7 { “$SysClass $ChassisNo Tower” }
        8 { “$SysClass $ChassisNo Portable” }
        9 { “$SysClass $ChassisNo Laptop” }
       10 { “$SysClass $ChassisNo Notebook” } 
       11 { “$SysClass $ChassisNo Hand Held” }
       12 { “$SysClass $SysClass $ChassisNo Docking Station” }
       13 { “$SysClass $ChassisNo All-in-One” }
       14 { “$SysClass $ChassisNo Sub Notebook” }
       15 { “$SysClass $ChassisNo Space Saving” }
       16 { “$SysClass $ChassisNo Lunch Box” }
       17 { “$SysClass $ChassisNo Main System Chassis”}
       18 { “$SysClass $ChassisNo Expansion Chassis”}
       19 { “$SysClass $ChassisNo Sub-Chassis”}
       20 { “$SysClass $ChassisNo Bus Expansion Chassis”}
       21 { “$SysClass $ChassisNo Peripheral Chassis” }
       22 { “$SysClass $ChassisNo Storage Chassis” }
       23 { “$SysClass $ChassisNo $ChassisNo Rack Mount Chassis” }
       24 { “$SysClass $ChassisNo Sealed-Case PC” }
       Default { “$SysClass $ChassisNo Currently Unassigned”}
      }

      Instructions:

        [*]Open Notepad
        [*]Paste above code into notepad
        [*]Save as “ChassisType.ps1” {include the quotes!}
        [*]Open PowerShell as Admin
        [*]Type: d:pathChassisType {press Enter}

      You can post back with a screen shot or just type in the results as you wish. :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1293245

      First, here is the output I got:

      Code:
      Please enter a computer name:: localhost
      Please enter your system unit type Tower, Mini-Tower, Laptop: dunno
      User Classification: dunno
      System Classification:  3 Desktop

      But personally, I would rewrite the script as follows:

      Code:
      param (
        $compname = “localhost”
      )
      
      $SysClass = “System Classification: ”
      $enclosureNames = (
        “unknown”,  # 0
        “Other” ,
        “Unknown” ,
        “Desktop” ,
        “Low Profile Desktop” ,
        “Pizza Box” ,  #5
        “Mini Tower” ,
        “Tower” ,
        “Portable” ,
        “Laptop” ,
        “Notebook” , #10
        “Hand Held” ,
        “Docking Station” ,
        “All-in-One” ,
        “Sub Notebook” ,
        “Space Saving” ,  #15
        “Lunch Box” ,
        “Main System Chassis”,
        “Expansion Chassis”,
        “Sub-Chassis”,
        “Bus Expansion Chassis”, #20
        “Peripheral Chassis” ,
        “Storage Chassis” ,
        “Rack Mount Chassis” ,
        “Sealed-Case PC” #24
      )
      
      $enclosure = get-wmiobject -computer $compname Win32_SystemEnclosure
      $ChassisNo = $enclosure.ChassisTypes[0]
      $chassisName = if ($ChassisNo -ge $enclosureNames.length) {“Currently Unassigned”} else {$enclosureNames[$ChassisNo]}
      
      “$SysClass $ChassisNo $chassisName”

      And here is why:

      1) I dislike scripts that sit and wait for me to give then some input. So I prefer scripts that accept parameters and act on them if provided, and use reasonable defaults (such as localhost) when I don’t provide parameter values. It also allows me to later on incorporate one script within another and thus build up a largely automated script that does a number of things. If each little script stops for input then such a larger script is impossible to work with. Also, why ask the user what they think the type is and then tell them what it really is? Especially since they user wasn’t even offered all of the possible choices.

      2) The original script had two minor bugs for the output for types 12 and 23. The technique I used avoiding having to write the output string multiple times – I write it only once and filled it with variables values and the chassis name from a predefined array. Thus the updated code follows the programming principle known as DRY – don’t repeat yourself. And therefore is less prone to the types of errors in the original code.

      3) I replace $I with $enclosure. It is always preferable to use descriptive variable names.

      4) I replaced gwmi with get-wmiobject. It is always preferable to use the full cmdlet name and not an alias within a script.

      Please don’t take the comments above as being negative towards you or the code your wrote. They are not. I think that it is great that you are trying out PowerShell and you are willing to share your efforts with the community. I just want to help and provide some of my expertise. But if you prefer I don’t please let me know, I won’t be offended.

      (BTW, at work I am known to be especially picky on how code is written. It’s a curse. Or is it that I’m cursed at? I can never figure out which…)

    • #1293260

      Cafed00d,

      Thanks very much for the input. I’m glad someone who knows PowerShell is providing input. I am also picky about code. I, however, am very new to PowerShell and I’m working on modifying code written by someone else as a learning exercise. I fully agree that aliases are NOT good practice, I just didn’t know it was an alias, now I do. Please keep the comments comming. Thanks again. :cheers:

      Update: Here’s the latest version of the code.

      Code:
      # +——————————————————–+
      # | Computer Mentors System Information V5.0               |
      # | Code adapted from:                                     |
      # |          Powershell PC Info Script V1.0b               | 
      # |             Coded By:Trenton Ivey(kno)                 | 
      # |                    hackyeah.com                        |
      # | Incorporated Coding changes recommed by Cafed00d @ WSL |
      # +——————————————————–+
      
      param (
        $compname = “localhost”  #Default if no Compname Arg.
      )
        
      $enclosureNames = (
        “unknown”,  # 0
        “Other” ,
        “Unknown” ,
        “Desktop” ,
        “Low Profile Desktop” ,
        “Pizza Box” ,  #5
        “Mini Tower” ,
        “Tower” ,
        “Portable” ,
        “Laptop” ,
        “Notebook” , #10
        “Hand Held” ,
        “Docking Station” ,
        “All-in-One” ,
        “Sub Notebook” ,
        “Space Saving” ,  #15
        “Lunch Box” ,
        “Main System Chassis”,
        “Expansion Chassis”,
        “Sub-Chassis”,
        “Bus Expansion Chassis”, #20
        “Peripheral Chassis” ,
        “Storage Chassis” ,
        “Rack Mount Chassis” ,
        “Sealed-Case PC” #24
      )
           
            Clear-Host
            “General Computer Information:`n”
            # Create Table
             $CITable = New-Object system.Data.DataTable “Computer Information”
      #Create Columns for table 
             $CITcol1 = New-Object system.Data.DataColumn Item,([string])       
             $CITcol2 = New-Object system.Data.DataColumn Value,([string])
      #Add Columns to table
             $CITable.columns.add($CITcol1)
             $CITable.columns.add($CITcol2)
            $ComputerSysObj = get-WMIObject -computer $compname Win32_ComputerSystem    
      #Create Row Variable 
            $CITRow = $CITable.NewRow()
      #Assign items to row variable
            $CITRow.Item = ‘Computer Name’ 
            $CITRow.Value = $ComputerSysObj.Name
      #Add Row to Table using Row Variable
            $CITable.Rows.Add($CITRow)
      
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Current User ID’
            $CITRow.Value = $ComputerSysObj.Username
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Domain Name’
            $CITRow.Value = $ComputerSysObj.Domain
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Manufacturer’
            $CITRow.Value = $ComputerSysObj.Manufacturer
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Model’
            $CITRow.Value = $ComputerSysObj.Model
            $CITable.Rows.Add($CITRow)
      
            $enclosure = get-wmiobject -computer $compname Win32_SystemEnclosure
            $ChassisNo = $enclosure.ChassisTypes[0]
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Enclosure Type’
            $CITRow.Value = if ($ChassisNo -ge $enclosureNames.length) {
                                “Currently Unassigned”
                            } 
                            else {
                                $enclosureNames[$ChassisNo]
                            }
            $CITable.Rows.Add($CITRow)
      
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘System Type’
            $CITRow.Value = $ComputerSysObj.SystemType
            $CITable.Rows.Add($CITRow)
            
            $BIOSObject = get-WMIObject -computer $compname Win32_BIOS
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Serial Number’
            $CITRow.Value = $BIOSObject.SerialNumber
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘BIOS Name’
            $CITRow.Value = $BIOSObject.Name
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘     Version’
            $CITRow.Value = $BIOSObject.SMBIOSBIOSVersion
            $CITable.Rows.Add($CITRow)
            
            $OS_Object = get-WMIObject -computer $compname Win32_OperatingSystem
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘OS Name’
            $CITRow.Value = $OS_Object.Caption
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Serial Number’
            $CITRow.Value = $OS_Object.SerialNumber
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘OS Bit Width’
            $CITRow.Value = $OS_Object.OSArchitecture
            $CITable.Rows.Add($CITRow)
       
            $localdatetime = $OS_Object.ConvertToDateTime($OS_Object.LocalDateTime) 
            $lastbootuptime = $OS_Object.ConvertToDateTime($OS_Object.LastBootUpTime) 
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Time Current’
            $CITRow.Value = $LocalDateTime
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘     Last Boot’
            $CITRow.Value = $LastBootUpTime
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘     Total Up’
            $CITRow.Value = $localdatetime – $lastbootuptime
            
            $Processor_Object = get-WMIObject -computer $compname Win32_Processor
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘Processor Name’
            $CITRow.Value = $Processor_Object.Name
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘          Info’
            $CITRow.Value = $Processor_Object.Caption
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘          Maker’
            $CITRow.Value = $Processor_Object.Manufacturer
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘          ID’
            $CITRow.Value = $Processor_Object.ProcessorId
            $CITable.Rows.Add($CITRow)
            
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘          Cores’
            $CITRow.Value = $Processor_Object.NumberofCores
            $CITable.Rows.Add($CITRow)
      
            $CITRow = $CITable.NewRow()
            $CITRow.Item = ‘  Address Width’
            $CITRow.Value = $Processor_Object.AddressWidth
            $CITable.Rows.Add($CITRow)
            
      #Output table
            $fmt = @{Expression={$_.Item};Label=”Item”;width=20},
                   @{Expression={$_.Value};Label=”Value”;Width=40}
                   
            $CITable | Select-Object Item,Value | Format-Table $fmt
            
      #PC Printer Information 
                  “Installed Printer Information:”
                  get-WMIObject -computer $compname Win32_Printer | Select-Object DeviceID,DriverName, PortName | Format-Table -autosize
                  
      #Disk Info 
                  “Drive Information:”
                  $fmt = @{Expression={$_.Name};Label=”Drive Letter”;width=12},
                           @{Expression={$_.VolumeName};Label=”Vol Name”;Width=15},
                           @{Expression={ ‘{0:#,000.00}’ -f ($_.Size/1gb)};Label=”Disk Size / GB”;width=14},
                           @{Expression={ ‘{0:#,000.00}’ -f ($_.FreeSpace/1gb)};Label=”Free Space / GB”;width=15}
                           
                  $Disk_Object = get-WMIObject -computer $compname Win32_logicaldisk 
                  $Disk_Object | Format-Table $fmt
      
      #Memory Info 
                  “Memory Information:”
                  $fmt = @{Expression={$_.Speed};Label=”Speed”;width=20},
                         @{Expression={$_.DataWidth};Label=”Data Width”;width=10},
                         @{Expression={ ‘{0:#.00}’ -f ($_.Capacity/1gb)};Label=”Module Size / GB”;width=16},
                         @{Expression={$_.DeviceLocator};Label=”Slot”;width=6},
                         @{Expression={$_.SerialNumber};Label=”Serial No.”}
      
                  $Mem_Object = get-WMIObject -computer $compname Win32_PhysicalMemory 
                  $Mem_Object | Format-Table $fmt
      
      #Monitor Info 
                  “Monitor Information:” 
                  #Turn off Error Messages 
                  $ErrorActionPreference_Backup = $ErrorActionPreference 
                  $ErrorActionPreference = “SilentlyContinue” 
       
       
                  $keytype=[Microsoft.Win32.RegistryHive]::LocalMachine 
                  if($reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$compname)){ 
                      #Create Table To Hold Info 
                      $montable = New-Object system.Data.DataTable “Monitor Info” 
                      #Create Columns for Table 
                      $moncol1 = New-Object system.Data.DataColumn Name,([string]) 
                      $moncol2 = New-Object system.Data.DataColumn Serial,([string]) 
                      $moncol3 = New-Object system.Data.DataColumn Ascii,([string]) 
                      #Add Columns to Table 
                      $montable.columns.add($moncol1) 
                      $montable.columns.add($moncol2) 
                      $montable.columns.add($moncol3) 
       
       
       
                      $regKey= $reg.OpenSubKey(“SYSTEM\CurrentControlSet\EnumDISPLAY” ) 
                      $HID = $regkey.GetSubKeyNames() 
                      foreach($HID_KEY_NAME in $HID){ 
                          $regKey= $reg.OpenSubKey(“SYSTEM\CurrentControlSet\Enum\DISPLAY\$HID_KEY_NAME” ) 
                          $DID = $regkey.GetSubKeyNames() 
                          foreach($DID_KEY_NAME in $DID){ 
                              $regKey= $reg.OpenSubKey(“SYSTEM\CurrentControlSet\Enum\DISPLAY\$HID_KEY_NAME\$DID_KEY_NAME\Device Parameters” ) 
                              $EDID = $regKey.GetValue(“EDID”) 
                              foreach($int in $EDID){ 
                                  $EDID_String = $EDID_String+([char]$int) 
                              } 
                              #Create new row in table 
                              $monrow=$montable.NewRow() 
                               
                              #MonitorName 
                              $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFC + [char]0x00            
                              $matchfound = $EDID_String -match “$checkstring([w ]+)” 
                              if($matchfound){$monrow.Name = [string]$matches[1]} else {$monrow.Name = ‘-‘} 
       
                               
                              #Serial Number 
                              $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFF + [char]0x00            
                              $matchfound =  $EDID_String -match “$checkstring(S+)” 
                              if($matchfound){$monrow.Serial = [string]$matches[1]} else {$monrow.Serial = ‘-‘} 
                                                       
                              #AsciiString 
                              $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFE + [char]0x00            
                              $matchfound = $EDID_String -match “$checkstring([w ]+)” 
                              if($matchfound){$monrow.Ascii = [string]$matches[1]} else {$monrow.Ascii = ‘-‘}          
       
                                       
                              $EDID_String = ” 
                               
                              $montable.Rows.Add($monrow) 
                          }   # End – foreach($DID_KEY_NAME in $DID)
                          
                      } # End – foreach($HID_KEY_NAME in $HID)
                      
                      $montable | select-object  -unique Serial,Name,Ascii | Where-Object {$_.Serial -ne “-“} | Format-Table 
                       
                  }   # End If
                  
                  else {  
                      Write-Host “Access Denied – Check Permissions” 
                  } 
         
      

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1425041

      Hello Again,

      I’ve just updated this utility to include information on network adapters. So here’s the latest.
      35596-CMsPCInfo
      Hope someone finds this useful. :cheers:

      FYI: Now works with all versions of Windows w/PowerShell.

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    Viewing 8 reply threads
    Reply To: PowerShell PC Information Utility

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: