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}
# +——————————————————+ # | 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: