This is my code for checking desktop hardware. I’m trying not to use external sources like csv as i want to roll it up into an exe for others to use.
Set-StrictMode -Version "latest"
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Form = New-Object System.Windows.Forms.Form
$Form.BackColor = "White"
$Form.StartPosition = "CenterScreen"
$User = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$Form.text = "Test"
$Form.Size = New-Object System.Drawing.Size(800,510)
############################################## Start Check Hardware functions
function checkhw {
$HostName=$InputBox.text;
$newLine = [System.Environment]::NewLine
foreach ($HostName In $InputBox.text){
$ping = (Test-Connection -ComputerName $HostName -Count 1 -quiet)
if (-not $ping) {
continue
}
$outputBoxping.text = $ping
$errorActionPreference = "stop"
$outputboxquery.text = write "Querying: $HostName"
$computerSystem = get-wmiobject Win32_ComputerSystem -ComputerName $HostName
$computerBIOS = get-wmiobject Win32_BIOS -ComputerName $HostName
$computerOS = get-wmiobject Win32_OperatingSystem -ComputerName $HostName
$computerOSB = get-wmiobject Win32_OperatingSystem -ComputerName $HostName
$computerBLD = get-wmiobject Win32_OperatingSystem -ComputerName $HostName
$computerCPU = get-wmiobject Win32_Processor -ComputerName $HostName
$computerHDD = Get-WmiObject Win32_LogicalDisk -ComputerName $HostName -Filter "DeviceID='C:'"
$computerLCD = get-wmiobject Win32_DesktopMonitor -ComputerName $HostName
$outputboxquery.text = write "Done"
$Man = $computerSystem.Manufacturer
$Mod = $computerSystem.model -replace "1095BV6", "C30" -replace "3664AK7", "M72e" -replace "30A0S0AT0A", "E32"-replace "32373A0", "M92p" -replace "3237EF9", "M92p" -replace "3167BC8", "M71e" -replace "10A4S00R0D", "M93" -replace "3664AK9", "M72e" -replace "3267B69", "M72e Tiny" -replace "0833AL2", "M70e" -replace "4263BM6", "C20" -replace "30A8S00300", "P700" -replace "11363A0", "C30" -replace "30AGS0CR05", "P300" -replace "43516D7", "S30" -replace "0606C26", "S30" -replace "43517A4", "S30 QA" -replace "VMware Virtual Platform", "VDI" -replace "30A8S00400", "P700 QA" -replace "4157ER5", "S20"
$Ser = $computerBIOS.SerialNumber
$CPUs = $ComputerSystem.NumberOfProcessors
$Cores = $ComputerSystem.NumberOfLogicalProcessors
$HDD = "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
$RAM = "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
$HDDF = "{0:N2}" -f ($computerHDD.freespace/1GB) + "GB"
$OS = $computerOS.caption -replace "Microsoft Windows 7 Enterprise", "Win 7" -replace "Microsoft Windows XP Professional", "XP"
$OSB = $computerOSB.ConvertToDateTime(($computerOSB).InstallDate)
$Usr = $computerSystem.UserName
$Check = write " Hostname: " $computerSystem.Name, $newline, "Manufacturer: " $Man, $newline, "Model: " $Mod, $newline, "Serial: " $Ser, $newline, "No. CPU's: " $CPUs,$newline, "No. Cores's: " $Cores, $newline, "Memory: " $RAM, $newline, "HDD Size: " $HDD, $newline, "HDD Free Space: " $HDDF, $newline, "Operating System: " $OS, $newline, "Built Date: " $OSB, $newline, "User Logged in: " $Usr
$outputBoxHW.text=$Check
}
{
out-file $labelPing.text
}
}
############################################## End Check Hardware functions
############################################## Start Heading Label
$labelHead = New-Object Windows.Forms.Label
$labelHead.ForeColor = "darkgray"
$labelHead.Location = New-Object Drawing.Point 320,40
$labelHead.Size = New-Object Drawing.Point 300,60
$labelHead.text = "Desktop Information Tool"
$Form.Controls.Add($labelHead)
############################################## end heading Label
############################################## Start HostName Label
$labelHN = New-Object Windows.Forms.Label
$labelHN.Location = New-Object Drawing.Point 10,25
$labelHN.Size = New-Object Drawing.Point 120,20
$labelHN.text = "Enter Hostname"
$Form.Controls.Add($labelHN)
############################################## end Hostname Label
############################################## Start Ping Label
$labelPing = New-Object Windows.Forms.Label
$labelPing.Location = New-Object Drawing.Point 10,382
$labelPing.Size = New-Object Drawing.Point 50,17
$labelPing.text = "Pinging?"
$Form.Controls.Add($labelPing)
############################################## end Ping functions
############################################## Start Hardware Info Label
$labelquery = New-Object Windows.Forms.Label
$labelquery.Location = New-Object Drawing.Point 10,100
$labelquery.Size = New-Object Drawing.Point 170,17
$labelquery.text = "Hardware Information"
$Form.Controls.Add($labelquery)
############################################## end Hardware Info Label
############################################## Start Version Label
$labelver = New-Object Windows.Forms.Label
$labelver.Location = New-Object Drawing.Point 725,450
$labelver.Size = New-Object Drawing.Point 30,30
$labelver.text = "v1.0"
$Form.Controls.Add($labelver)
############################################## end Version Labe
############################################## Start text fields
$InputBox = New-Object System.Windows.Forms.TextBox
$InputBox.Location = New-Object System.Drawing.Size(10,45)
$InputBox.Size = New-Object System.Drawing.Size(150,20)
$Form.Controls.Add($InputBox)
$outputBoxHW = New-Object System.Windows.Forms.TextBox
$outputBoxHW.Location = New-Object System.Drawing.Size(10,120)
$outputBoxHW.Size = New-Object System.Drawing.Size(325,245)
$outputBoxHW.MultiLine = $True
$Form.Controls.Add($outputBoxHW)
############################################## end text fields
############################################## Start Output Build Check Box
$outputBoxBC = New-Object System.Windows.Forms.TextBox
$outputBoxBC.Location = New-Object System.Drawing.Size(365,120)
$outputBoxBC.Size = New-Object System.Drawing.Size(325,245)
$outputBoxBC.MultiLine = $True
$Form.Controls.Add($outputBoxBC)
############################################## end Output Build Check Box
############################################## Start Ping Output box
$outputBoxping = New-Object System.Windows.Forms.TextBox
$outputBoxping.Location = New-Object System.Drawing.Size(70,380)
$outputBoxping.Size = New-Object System.Drawing.Size(50,20)
$Form.Controls.Add($outputBoxping)
############################################## end Ping Output box
############################################## Start Hardware buttons
$ButtonHW = New-Object System.Windows.Forms.Button
$ButtonHW.Location = New-Object System.Drawing.Size(180,30)
$ButtonHW.Size = New-Object System.Drawing.Size(75,50)
$ButtonHW.Text = "Check Hardware"
$ButtonHW.Add_Click({$outputBoxHW.Text=""})
$ButtonHW.Add_Click({$outputBoxping.Text=""})
$ButtonHW.Add_Click({checkhw})
$Form.Controls.Add($ButtonHW)
############################################## end Hardware buttons
############################################## Start Close buttons
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Size(700,413)
$cancelButton.Size = New-Object System.Drawing.Size(75,25)
$cancelButton.Text = "Close"
$cancelButton.Add_Click({ $form.Tag = $null; $form.Close() })
$Form.Controls.Add($cancelButton)
############################################## end Close buttons
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()