70 lines
2.4 KiB
PowerShell
70 lines
2.4 KiB
PowerShell
|
|
param(
|
||
|
|
[Parameter(Mandatory=$true)]
|
||
|
|
[ValidateSet("battery","time","cpu","ram","disk","all")]
|
||
|
|
[string]$Topic
|
||
|
|
)
|
||
|
|
|
||
|
|
$ErrorActionPreference = 'SilentlyContinue'
|
||
|
|
|
||
|
|
function Get-BatteryInfo {
|
||
|
|
$b = Get-CimInstance -ClassName Win32_Battery
|
||
|
|
if (-not $b) { return "Батарея не обнаружена (видимо, десктоп)" }
|
||
|
|
$pct = [int]$b.EstimatedChargeRemaining
|
||
|
|
$status = switch ($b.BatteryStatus) {
|
||
|
|
1 { "разряжается" }
|
||
|
|
2 { "от сети" }
|
||
|
|
3 { "заряжена" }
|
||
|
|
4 { "низкий заряд" }
|
||
|
|
5 { "критический заряд" }
|
||
|
|
default { "статус $($b.BatteryStatus)" }
|
||
|
|
}
|
||
|
|
return "Батарея: $pct%, $status"
|
||
|
|
}
|
||
|
|
|
||
|
|
function Get-TimeInfo {
|
||
|
|
$ru = [System.Globalization.CultureInfo]::GetCultureInfo("ru-RU")
|
||
|
|
$now = Get-Date
|
||
|
|
return "Сейчас: " + $now.ToString("HH:mm, dd MMMM, dddd", $ru)
|
||
|
|
}
|
||
|
|
|
||
|
|
function Get-CpuInfo {
|
||
|
|
$cpu = Get-CimInstance -ClassName Win32_Processor | Select-Object -First 1
|
||
|
|
$load = (Get-CimInstance -ClassName Win32_PerfFormattedData_PerfOS_Processor -Filter "Name='_Total'" -ErrorAction SilentlyContinue).PercentProcessorTime
|
||
|
|
if ($null -eq $load) { $load = $cpu.LoadPercentage }
|
||
|
|
return "CPU: $($cpu.Name.Trim()), загрузка $load%"
|
||
|
|
}
|
||
|
|
|
||
|
|
function Get-RamInfo {
|
||
|
|
$os = Get-CimInstance -ClassName Win32_OperatingSystem
|
||
|
|
$totalGB = [math]::Round($os.TotalVisibleMemorySize / 1MB, 1)
|
||
|
|
$freeGB = [math]::Round($os.FreePhysicalMemory / 1MB, 1)
|
||
|
|
$usedGB = [math]::Round($totalGB - $freeGB, 1)
|
||
|
|
$pct = [int](($usedGB / $totalGB) * 100)
|
||
|
|
return "RAM: $usedGB из $totalGB ГБ ($pct% занято)"
|
||
|
|
}
|
||
|
|
|
||
|
|
function Get-DiskInfo {
|
||
|
|
$sys = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='$($env:SystemDrive)'"
|
||
|
|
if (-not $sys) {
|
||
|
|
$sys = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | Select-Object -First 1
|
||
|
|
}
|
||
|
|
$freeGB = [math]::Round($sys.FreeSpace / 1GB, 1)
|
||
|
|
$totalGB = [math]::Round($sys.Size / 1GB, 1)
|
||
|
|
return "Диск $($sys.DeviceID): свободно $freeGB из $totalGB ГБ"
|
||
|
|
}
|
||
|
|
|
||
|
|
switch ($Topic) {
|
||
|
|
"battery" { Get-BatteryInfo }
|
||
|
|
"time" { Get-TimeInfo }
|
||
|
|
"cpu" { Get-CpuInfo }
|
||
|
|
"ram" { Get-RamInfo }
|
||
|
|
"disk" { Get-DiskInfo }
|
||
|
|
"all" {
|
||
|
|
Get-TimeInfo
|
||
|
|
Get-BatteryInfo
|
||
|
|
Get-CpuInfo
|
||
|
|
Get-RamInfo
|
||
|
|
Get-DiskInfo
|
||
|
|
}
|
||
|
|
}
|