Skip to content

Instantly share code, notes, and snippets.

@assiless
Last active November 28, 2023 18:46
Show Gist options
  • Save assiless/79f06622882fdaac427baaa7ca41a56f to your computer and use it in GitHub Desktop.
Save assiless/79f06622882fdaac427baaa7ca41a56f to your computer and use it in GitHub Desktop.
PC Information
#Requires -Version 3.0
# run as admin
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" +$myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
pause
}
function Get-NotifyIconText {
# [DateTime]::Now.Second.ToString()
((Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi").CurrentTemperature / 10 - 273.15).ToString()
# ((Get-Counter '\\mypc\network interface(Intel[R] 82579V Gigabit Network Connection)\bytes total/sec').countersamples).cookedvalue*8/102400000*100
}
Add-Type -ReferencedAssemblies @("System.Windows.Forms"; "System.Drawing") -TypeDefinition @"
using System;
using System.Drawing;
using System.Windows.Forms;
public static class TextNotifyIcon
{
// it's difficult to call DestroyIcon() with powershell only...
[System.Runtime.InteropServices.DllImport("user32")]
private static extern bool DestroyIcon(IntPtr hIcon);
public static NotifyIcon CreateTrayIcon()
{
var notifyIcon = new NotifyIcon();
notifyIcon.Visible = true;
return notifyIcon;
}
public static void UpdateIcon(NotifyIcon notifyIcon, string text)
{
using (var b = new Bitmap(16, 16))
using (var g = Graphics.FromImage(b))
using (var font = new Font(FontFamily.GenericMonospace, 8))
{
g.DrawString(text, font, Brushes.Red, 0, 0);
var icon = b.GetHicon();
try
{
notifyIcon.Icon = Icon.FromHandle(icon);
} finally
{
DestroyIcon(icon);
}
}
}
}
"@
$icon = [TextNotifyIcon]::CreateTrayIcon()
while ($true) {
$text = Get-NotifyIconText
# (Get-CimInstance MSAcpi_ThermalZoneTemperature -Namespace "root/wmi").CurrentTemperature / 10 - 273.15
[TextNotifyIcon]::UpdateIcon($icon, $text)
[Threading.Thread]::Sleep(1000)
}
## usage : ⬇️
# (wget "https://gist.githubusercontent.com/assiless/8bcd985475aaecd2ccd98ed9d09f973e/raw/Detect_Laptop.ps1").Content | Set-Content -encoding unicode "Detect_Laptop.ps1"
# Detect_Laptop.ps1
# https://powershell.one/wmi/root/cimv2/win32_systemenclosure
# http://woshub.com/sccm-and-wmi-query-to-find-all-laptops-and-desktops/
###########################################################################################
##########################💡🤔💭TO GET "Win32_" IDEA 💭🤔💡###############################
### Get-WMIObject -List| Where{$_.name -match "^Win32_"} | Sort Name | Format-Table Name###
### or#####################################################################################
### Get-WmiObject -List####################################################################
###########################################################################################
# Get-CimInstance -ClassName Win32_ComputerSystem -Property *
# Get-CimInstance -ClassName Win32_SystemEnclosure -Property *
# Get-WmiObject -ClassName win32_battery -Property *
Function Detect-Laptop
{
Param( [string]$computer = “localhost” )
$isLaptop = $false
#The chassis is the physical container that houses the components of a computer. Check if the machine’s chasis type is 9.Laptop 10.Notebook 14.Sub-Notebook
if(Get-WmiObject -Class win32_systemenclosure -ComputerName $computer | Where-Object { $_.chassistypes -eq 9 -or $_.chassistypes -eq 10 -or $_.chassistypes -eq 14})
{ $isLaptop = $true }
#Shows battery status , if true then the machine is a laptop.
if(Get-WmiObject -Class win32_battery -ComputerName $computer)
{ $isLaptop = $true }
$isLaptop
}
If(Detect-Laptop) { "it's a laptop" }
else { "it's not a laptop" }
#Listing computer manufacturer and model
Get-CimInstance -ClassName Win32_ComputerSystem
## usage : ⬇️
# (wget "https://gist.githubusercontent.com/assiless/79f06622882fdaac427baaa7ca41a56f/raw/pc_data.ps1").Content | Set-Content -encoding unicode "pc_data.ps1"
# pc_data.ps1
# OUTPUT is "pc_data.txt" ON YOUR DESKTOP
# @ECHO OFF
# cd %userprofile%\Desktop
# del "pc_data.txt" >nul 2>&1
# echo "wmic computersystem get:" > pc_data.txt
# wmic computersystem get model >> pc_data.txt
# wmic csproduct get >> pc_data.txt
# wmic bios get serialnumber >> pc_data.txt
Set-Location $ENV:UserProfile\Desktop
Remove-Item "pc_data.txt" -ErrorAction Ignore
"wmic computersystem get:" > "pc_data.txt"
wmic computersystem get >> "pc_data.txt"
"wmic csproduct get:" >> "pc_data.txt"
wmic csproduct get >> "pc_data.txt"
"wmic bios get:" >> "pc_data.txt"
wmic bios get >> "pc_data.txt"
"___________________________________________________" >> "pc_data.txt"
wmic computersystem get model >> "pc_data.txt"
wmic bios get serialnumber >> "pc_data.txt"
PAUSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment