Skip to content

Instantly share code, notes, and snippets.

@art0rz
Last active March 5, 2019 18:49
Show Gist options
  • Save art0rz/cac2d8dab5708ecb440265b60ee20ff8 to your computer and use it in GitHub Desktop.
Save art0rz/cac2d8dab5708ecb440265b60ee20ff8 to your computer and use it in GitHub Desktop.
moo.ps1
function Get-OSProp($Class, $Prop) {
$value = (Get-WmiObject -Class $class | select-object -expand $Prop)
return $value;
}
# copy and pasted this from somewhere
function Format-TimeSpan {
process {
"{0:00} d {1:00} h {2:00} m {3:00} s" -f $_.Days, $_.Hours, $_.Minutes, $_.Seconds
}
}
# copy and pasted this from somewhere
function Out-Object {
param(
[System.Collections.Hashtable[]] $hashData
)
$order = @()
$result = @{}
$hashData | ForEach-Object {
$order += ($_.Keys -as [Array])[0]
$result += $_
}
New-Object PSObject -Property $result | Select-Object $order
}
# copy and pasted this from somewhere
function Get-FriendlySize {
param($Bytes)
$sizes = 'Bytes,KB,MB,GB,TB,PB,EB,ZB' -split ','
for ($i = 0; ($Bytes -ge 1kb) -and
($i -lt $sizes.Count); $i++) {$Bytes /= 1kb}
$N = 2;
if ($i -eq 0) {$N = 0}
"{0:N$($N)} {1}" -f $Bytes, $sizes[$i]
}
# copy and pasted this from somewhere
function Get-Uptime {
param(
$computerName,
$credential
)
# In case pipeline input contains ComputerName property
if ( $computerName.ComputerName ) {
$computerName = $computerName.ComputerName
}
if ( (-not $computerName) -or ($computerName -eq ".") ) {
$computerName = [Net.Dns]::GetHostName()
}
$params = @{
"Class" = "Win32_OperatingSystem"
"ComputerName" = $computerName
"Namespace" = "root\CIMV2"
}
if ( $credential ) {
# Ignore -Credential for current computer
if ( $computerName -ne [Net.Dns]::GetHostName() ) {
$params.Add("Credential", $credential)
}
}
try {
$wmiOS = Get-WmiObject @params -ErrorAction Stop
}
catch {
Write-Error -Exception (New-Object $_.Exception.GetType().FullName `
("Cannot connect to the computer '$computerName' due to the following error: '$($_.Exception.Message)'",
$_.Exception))
return
}
$lastBootTime = [Management.ManagementDateTimeConverter]::ToDateTime($wmiOS.LastBootUpTime)
Out-Object `
@{"ComputerName" = $computerName},
@{"LastBootTime" = $lastBootTime},
@{"Uptime" = (Get-Date) - $lastBootTime | Format-TimeSpan}
}
# See https://github.com/dvl/axtage/blob/master/sys/addons/moo.mrc
# Some of these variables are not being used
$name = Get-OSProp -Class Win32_ComputerSystem -Prop Name
$ostitle = Get-OSProp -Class Win32_OperatingSystem -Prop Caption
$ossp = Get-OSProp -Class Win32_OperatingSystem -Prop CSDVersion
$osver = Get-OSProp -Class Win32_OperatingSystem -Prop Version
$osarc = Get-OSProp -Class Win32_OperatingSystem -Prop OSArchitecture
$uptime = Get-Uptime | Select-Object -expand Uptime
$cpuname = Get-OSProp -Class Win32_Processor -Prop Name
$cpuspeed = Get-OSProp -Class Win32_Processor -Prop CurrentClockSpeed
$cpuload = Get-OSProp -Class Win32_Processor -Prop LoadPercentage
$cputotal = Get-OSProp -Class Win32_ComputerSystem -Prop NumberOfProcessors
$cpuarch = Get-OSProp -Class Win32_Processor -Prop Architecture
# I have 2 GPUs, #0 is integrated (Intel) #1 is discreet (NVIDIA),
$gfxmake = (Get-OSProp -Class Win32_VideoController -Prop AdapterCompatibility)[1]
$gfxproc = (Get-OSProp -Class Win32_VideoController -Prop VideoProcessor)[1]
$gfxram = Get-FriendlySize -Bytes (Get-OSProp -Class Win32_VideoController -Prop AdapterRam)[1]
# I also have 2 4k screens
# I *could* show them all in the moo line, but I didn't feel like creating more ugly code
# So I'll just get the first one
$hres = (Get-OSProp -Class Win32_VideoController -Prop currenthorizontalresolution)[0]
$vres = (Get-OSProp -Class Win32_VideoController -Prop currentverticalresolution)[0]
$resbit = (Get-OSProp -Class Win32_VideoController -Prop currentbitsperpixel)[0]
$resrate = (Get-OSProp -Class Win32_VideoController -Prop currentrefreshrate)[0]
$rammax = Get-OSProp -Class Win32_OperatingSystem -Prop TotalVisibleMemorySize
$ramuse = $rammax - (Get-OSProp -Class Win32_OperatingSystem -Prop FreePhysicalMemory)
$rammaxfriendly = Get-FriendlySize -Bytes ($rammax * 1000)
$ramusefriendly = Get-FriendlySize -Bytes ($ramuse * 1000)
$ramusepercent = [math]::Round(($ramuse / $rammax) * 100);
# Unused
$netname = Get-OSProp -Class Win32_PerfRawData_Tcpip_NetworkInterface -Prop Name
$netspeed = Get-OSProp -Class Win32_PerfRawData_Tcpip_NetworkInterface -Prop CurrentBandwidth
$netin = Get-OSProp -Class Win32_PerfRawData_Tcpip_NetworkInterface -Prop BytesReceivedPersec
$netout = Get-OSProp -Class Win32_PerfRawData_Tcpip_NetworkInterface -Prop BytesSentPersec
# echo "name: $name"
# echo "ostitle: $ostitle"
# echo "ossp: $ossp"
# echo "osver: $osver"
# echo "uptime: $uptime"
# echo "osarc: $osarc"
# echo "cpuname: $cpuname"
# echo "cpuspeed: $cpuspeed"
# echo "cpuload: $cpuload"
# echo "cputotal: $cputotal"
# echo "cpuarch: $cpuarch"
# echo "gfxmake: $gfxmake"
# echo "gfxproc: $gfxproc"
# echo "gfxram: $gfxram"
# echo "res: $res"
# echo "resbit: $resbit"
# echo "resrate: $resrate"
# echo "rammax: $rammax"
# echo "ramuse: $ramuse"
# echo "netname: $netname"
# echo "netspeed: $netspeed"
# echo "netin: $netin"
# echo "netout: $netout"
echo "moo: os: $ostitle - $osver up: $uptime cpu: $cpuname at $($cpuspeed)Hz ($cpuload% Load) ram: $($ramusefriendly)/$($rammaxfriendly) ($($ramusepercent)%) gfx: $gfxmake $gfxproc gfxram: $gfxram res: $($hres)x$($vres) $($resbit)bit $($resrate)Hz"
# moo: os: Microsoft Windows 10 Professionnel - (10.0.18348) up: 1hr 50mins 48secs cpu: Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz (x64) at 1600MHz (7% Load)
# gfx: Intel Corporation Intel(R) HD Graphics Family 1.00GB res: 1920x1080 32bit 59Hz ram: 5003/8112MB (61.67%) [||----]
# hdd: C:\ 83.17GB/230.94GB net: Marvell AVASTAR Wireless Composite Device _2 - 0MB/s 0B In 0B Out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment