-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysinfo_windows.ps1
More file actions
103 lines (81 loc) · 4.54 KB
/
sysinfo_windows.ps1
File metadata and controls
103 lines (81 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#Requires -Version 3.0
<#
.SYNOPSIS
Collects hardware, OS, and network information on Windows.
Produces the same output structure as task4_1.sh.
.OUTPUTS
sysinfo_windows.out in the same directory as this script.
#>
$OutputFile = Join-Path $PSScriptRoot "sysinfo_windows.out"
$lines = [System.Collections.Generic.List[string]]::new()
# ─────────────────────────────────────────────────────────────── Hardware ────
$lines.Add("--- Hardware ---")
# CPU
$cpu = (Get-CimInstance Win32_Processor | Select-Object -First 1).Name.Trim()
$lines.Add("CPU: $(if ($cpu) { $cpu } else { 'Unknown' })")
# RAM — total physical memory in MB
$ramBytes = (Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory
$ramMB = [math]::Round($ramBytes / 1MB)
$lines.Add("RAM: $ramMB MB")
# Motherboard
$board = Get-CimInstance Win32_BaseBoard | Select-Object -First 1
$noData = @("", $null, "Not Available", "Not Specified", "To Be Filled By O.E.M.", "Default string")
$mfr = if ($board.Manufacturer -and $board.Manufacturer.Trim() -notin $noData) { $board.Manufacturer.Trim() } else { "" }
$prod = if ($board.Product -and $board.Product.Trim() -notin $noData) { $board.Product.Trim() } else { "Unknown" }
$mb = if ($mfr) { "$mfr $prod" } else { $prod }
$lines.Add("Motherboard: $mb")
# System Serial Number
$serial = (Get-CimInstance Win32_BIOS | Select-Object -First 1).SerialNumber
if (-not $serial -or $serial.Trim() -in $noData) { $serial = "Unknown" }
$lines.Add("System Serial Number: $serial")
# ──────────────────────────────────────────────────────────────── System ─────
$lines.Add("--- System ---")
# OS Distribution
$osCaption = (Get-CimInstance Win32_OperatingSystem | Select-Object -First 1).Caption.Trim()
$lines.Add("OS Distribution: $(if ($osCaption) { $osCaption } else { 'Unknown' })")
# Kernel version (Windows build number)
$kernelVer = [System.Environment]::OSVersion.Version.ToString()
$lines.Add("Kernel version: $kernelVer")
# Installation date (UTC)
$installRaw = (Get-CimInstance Win32_OperatingSystem).InstallDate.ToUniversalTime()
$installStr = $installRaw.ToString("ddd MMM dd HH:mm:ss") + " UTC " + $installRaw.Year
$lines.Add("Installation date: $installStr")
# Hostname
$lines.Add("Hostname: $($env:COMPUTERNAME.ToLower())")
# Uptime — computed from last boot time
$lastBoot = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
$totalMins = [math]::Floor(((Get-Date) - $lastBoot).TotalMinutes)
$upWeeks = [math]::Floor($totalMins / 10080)
$upDays = [math]::Floor(($totalMins % 10080) / 1440)
$upHours = [math]::Floor(($totalMins % 1440) / 60)
$upMins = $totalMins % 60
$uptimeParts = @()
if ($upWeeks -gt 0) { $uptimeParts += "$upWeeks weeks" }
if ($upDays -gt 0) { $uptimeParts += "$upDays days" }
if ($upHours -gt 0) { $uptimeParts += "$upHours hours" }
if ($upMins -gt 0) { $uptimeParts += "$upMins minutes" }
if ($uptimeParts.Count -eq 0) { $uptimeParts = @("0 minutes") }
$lines.Add("Uptime: $($uptimeParts -join ', ')")
# Processes running
$lines.Add("Processes running: $((Get-Process).Count)")
# Users logged in — interactive and remote-interactive sessions
$userSessions = Get-CimInstance Win32_LogonSession |
Where-Object { $_.LogonType -in @(2, 10) }
$lines.Add("Users logged in: $(($userSessions | Measure-Object).Count)")
# ────────────────────────────────────────────────────────────── Network ──────
$lines.Add("--- Network ---")
Get-NetAdapter | Sort-Object InterfaceIndex | ForEach-Object {
$adapterName = $_.Name
$addrs = Get-NetIPAddress -InterfaceIndex $_.InterfaceIndex `
-AddressFamily IPv4 `
-ErrorAction SilentlyContinue
if ($addrs) {
$ipList = ($addrs | ForEach-Object { "$($_.IPAddress)/$($_.PrefixLength)" }) -join ", "
$lines.Add("${adapterName}: $ipList")
} else {
$lines.Add("${adapterName}: -")
}
}
# ─────────────────────────────────────────────────────────────── Output ──────
$lines | Set-Content -Path $OutputFile -Encoding UTF8
Write-Host "Written: $OutputFile"