GUI: System Information Collector

WMI System Information Collector uses WMI to obtain a variety of system information where it may not be possible to use WINRM and CIM.

This tool may be used on helpdesks to provide some immediate triage as the call is logged in ticketing system. Any suggestions are welcomed.

PowerShell Studio Code

$PCWMIInfo_Load = {
}


$ExecuteButton_Click = {
	
	##Gets Inputted PC Name
	if ($ComputerNameTextBox.Text -eq "")
	{
		[System.Windows.Forms.MessageBox]::Show('Computer name cannot be blank', 'Error', 'OK', 'Error')
	}
	
	Else
	{
		$ComputerName = $ComputerNameTextBox.Text
		
		##For each control type set the default value.
		$ManufacturerTextBox.Text = ''
		$ModelTextBox.Text = ''
		$SerialNoTextBox.Text = ''
		$WindowsVersionTextBox.Text = ''
		$CurrentlyLoggedOnTextBox.Text = ''
		$ChassisTextBox.Text = ''
		$PendingRestartTextBox.Text = ''
		$InstalledMemoryTextBox.Text = ''
		$AvailableMemorySlotsTextBox.Text = ''
		$WindowsInstallDateTextBox.Text = ''
		$WindowsLastBootDateTextBox.Text = ''
		$IPDetailsListBox.Items.Clear()
		$LatestWindowsUpdateListView.Items.Clear()
		$DiskListView.Items.Clear()
		
		##ComputerOnlineTest
		$PCStatus = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet -ErrorAction Ignore
		
		if ($PCStatus -eq $false)
		{
			$ComputerStatusTextBox.Text = "Host Unreachable"
			$ComputerStatusTextBox.BackColor = 'Red'
			$ComputerStatusTextBox.ForeColor = 'White'
		}
		elseif ($PCStatus -eq $true)
		{
			$ComputerStatusTextBox.Text = "Host Online"
			$ComputerStatusTextBox.BackColor = 'Green'
			$ComputerStatusTextBox.ForeColor = 'White'
			
			$WMIOperatingSystem = Get-WMIObject -Class Win32_Operatingsystem -ComputerName $ComputerName
			$WMIComputerSystem = Get-WMIObject -Class Win32_ComputerSystem -ComputerName $ComputerName
			$WMIPhysicalMemory = Get-WMIObject -Class Win32_PhysicalMemory -ComputerName $ComputerName
			$WMINetworkAdapter = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $ComputerName
			$WMIReliabilityRecords = Get-WmiObject -Class Win32_ReliabilityRecords -ComputerName $ComputerName
			$WMILogicalDisk = Get-WMIObject Win32_LogicalDisk -ComputerName $ComputerName
			$WMIBios = Get-WmiObject -Class Win32_Bios -ComputerName $ComputerName
			$WMIChassis = Get-WmiObject -Class Win32_SystemEnclosure -ComputerName $ComputerName
			$RegistryConnection = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]"LocalMachine", $ComputerName)
			
			##Disk Space
			$DiskInfos = $WMILogicalDisk | Select-Object DeviceID, VolumeName, Size, FreeSpace
			foreach ($DiskInfo in $DiskInfos)
			{
				$listItem3 = $DiskListView.Items.Add("$($DiskInfo.DeviceID)")
				$listItem3.SubItems.Add("$($DiskInfo.VolumeName)")
				$listItem3.SubItems.Add("$([decimal]::round(($DiskInfo.Size /1GB), 2))")
				$listItem3.SubItems.Add("$([decimal]::round(($DiskInfo.FreeSpace /1GB), 2))")
			}
			
			##Pending Reboot
			$RegSubKeysCBS = $RegistryConnection.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\").GetSubKeyNames()
			$CBSRebootPend = $RegSubKeysCBS -contains "RebootPending"
			$RegSubKeySM = $RegistryConnection.OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\")
			$RegValuePFRO = $RegSubKeySM.GetValue("PendingFileRenameOperations", $false)
			$RegWindowsUpdate = $RegistryConnection.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\").GetSubKeyNames()
			$WUAURebootReq = $RegWindowsUpdate -contains "RebootRequired"
			$RegistryConnection.Close()
			If ($CBSRebootPend -or $RegValuePFRO -or $WUAURebootReq) { $PendingRestartTextBox.Text = "Yes" }
			Else { $PendingRestartTextBox.Text = "No" }
			
			##OS Install
			$WindowsInstallDateTextBox.Text = try { Get-Date $WMIOperatingSystem.ConvertToDateTime($WMIOperatingSystem.InstallDate) -Format dd/MM/yyyy }
			catch { "Null" }
			
			##Last boot time
			$WindowsLastBootDateTextBox.Text = Get-Date $WMIOperatingSystem.ConvertToDateTime($WMIOperatingSystem.lastbootuptime) -Format "dd/MM/yyyy HH:MM"
			
			##Memory installed
			$InstalledMemoryTextBox.Text = [Math]::Round(($WMIComputerSystem.TotalPhysicalMemory/ 1GB), 2)
			
			##Available RAM slots
			$AvailableRamSlots = $WMIPhysicalMemory | select DeviceLocator, capacity | Where-Object { ($_.Capacity -lt '1') -and ($_.DeviceLocator -notlike "System ROM") } | measure-object | Select-Object Count
			$UnavailableRamSlots = $WMIPhysicalMemory | select DeviceLocator, capacity | Where-Object { ($_.Capacity -gt '1') -and ($_.DeviceLocator -notlike "System ROM") } | measure-object | Select-Object Count
			$AvailableMemorySlotsTextBox.Text = "$($AvailableRamSlots.count)/$($AvailableRamSlots.count + $UnavailableRamSlots.count)"
			
			##Logged on user
			$CurrentlyLoggedOnTextBox.Text = $($WMIComputerSystem | Select-Object UserName).UserName
			
			##IP Info
			$IPDetails = $WMINetworkAdapter | Where-Object { $_.IPEnabled -eq "True" } | Select IPAddress, DefaultIPGateway
			foreach ($IPDetail in $IPDetails)
			{
				$listItem = $IPDetailsListBox.Items.Add("$($IPDetail.IPAddress | Where-Object { $_ -notmatch ':' })")
				$listItem.SubItems.Add("$($IPDetail.DefaultIPGateway | Where-Object { $_ -notmatch ':' })")
			}
			
			##Last Windows Updates
			$LastUpdates = $WMIReliabilityRecords | Where-Object { $_.SourceName -eq "Microsoft-Windows-WindowsUpdateClient" }
			foreach ($LastUpdate in $LastUpdates)
			{
				$UpdateTimeDateConversion = $LastUpdate.ConvertToDateTime($LastUpdate.timegenerated)
				$UpdateTimeDateFormat = get-date $UpdateTimeDateConversion -Format dd/MM/yyyy
				$listItem1 = $LatestWindowsUpdateListView.Items.Add("$($UpdateTimeDateFormat)")
				$listItem1.SubItems.Add("$($LastUpdate.ProductName)")
				$listItem1.SubItems.Add("$(($LastUpdate.message -split ':')[0])")
			}
			
			##Computer Make Model
			$ManufacturerTextBox.Text = $WMIComputerSystem.Manufacturer
			$ModelTextBox.Text = $WMIComputerSystem.Model
			$SerialNoTextBox.Text = $WMIBios.SerialNumber
			
			##Chassis Type
			$Laptops = @("8", "9", "10", "12", "14", "18", "21")
			$Desktops = @("3", "4", "5", "6", "7", "13")
			$VirtualMachine = @("1")
			$PhysicalServer = @("3", "4", "5")
			if ($Laptops -match $WMIChassis.ChassisTypes) { $ChassisTextBox.Text = "Laptop" }
			elseif ($Desktops -match $WMIChassis.ChassisTypes) { $ChassisTextBox.Text = "Desktop" }
			elseif ($VirtualMachine -match $WMIChassis.ChassisTypes) { $ChassisTextBox.Text = "Virtual Machine" }
			elseif ($PhysicalServer -match $WMIChassis.ChassisTypes) { $ChassisTextBox.Text = "Physical Server" }
			else { $ChassisTextBox.Text = "Unknown" }
			
			##OS Version
			$WindowsVersionTextBox.Text = $WMIOperatingSystem.Caption
			
		}
	}
}
$ExitButton_Click = {
	$PCWMIInfo.close()
}

$toolstripstatuslabel2_Click = {
	[System.Diagnostics.Process]::Start($toolstripstatuslabel2.Tag)
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.