Uncategorized

SysInfo

Decided to write a little script to see how much “practical” information I could pack into one screen.
I think it turned out pretty well.

clear
Get-Variable -Exclude PWD,*Preference | Remove-Variable -EA 0

# include programs? (takes noticeably longer to gather info)
[bool]$showPrograms = $true

# define accent colors
$c1 = 'Magenta'
$c2 = 'Green'

# ------------------------------------------ #

if(([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") -eq $true) {$privs = "ADMIN"} else {$privs = "regular"}
if(Test-Connection google.com -Quiet){$ip = (Invoke-WebRequest ifconfig.co).ParsedHtml.getElementsByTagName("code") | foreach { $_.outerText }}else{$ip = 'No external IP detected'}

$bios = Get-CimInstance win32_BIOS
$os = Get-CimInstance win32_OperatingSystem
$cs = Get-WmiObject win32_ComputerSystem
$cpu = Get-CimInstance CIM_Processor
$mobo = Get-CimInstance Win32_BaseBoard | Select-Object Manufacturer, Product
if($showPrograms){$prod = Get-CimInstance win32_product}
$freemem = ([math]::round(($os.FreePhysicalMemory / 1024 / 1024), 2))
$totalmem = ([math]::round(($os.TotalVisibleMemorySize / 1024 / 1024), 2))
[string]$memory = ([math]::round(100-($freemem/$totalmem)*100, 0))
$memory = $memory.Trim(' ')

$uptime = (Get-Date) - ($os.lastbootuptime)
$suptime = "" + $Uptime.Days + " day(s), " + $Uptime.Hours + " hour(s), " + $Uptime.Minutes + " minute(s)"

if ($bios.serialnumber -like "*-*" -or $bios.serialnumber -like "*VM*" -or $bios.serialnumber -like "*vm*") {$hw = "TRUE"} else {$hw = "FALSE”} 

$hdds = Get-WmiObject win32_LogicalDisk -Filter "DriveType = 3"
foreach ($hdd in $hdds) {[string]$diskAvail += $hdd.DeviceID +" "+ [math]::truncate($hdd.freespace / 1GB) + "GB (" + [Math]::round((($hdd.freespace/$hdd.size) * 100)) + "%), "}

$table = New-Object system.Data.DataTable
$networks = Get-WmiObject win32_NetworkAdapterConfiguration | ? {$_.IPEnabled}
$nicCount = ($networks | measure).Count
foreach ($network in $networks) {
    $IPAddress  = $network.IpAddress[0]
    $SubnetMask  = $network.IPSubnet[0]
    $CIDR = ' /'+(([Convert]::toString(([IPAddress][String]([IPAddress]$SubnetMask).Address).Address,2)).ToCharArray() | Group)[0].Count
    $DefaultGateway = $network.DefaultIPGateway[0]
    $DNSServers  = $network.DNSServerSearchOrder
    if($network.DHCPEnabled) {
        $IsDHCPEnabled = $true
        $timex = New-TimeSpan -Start (Get-Date) -End ([datetime]::ParseExact($network.DHCPLeaseExpires.Split('.')[0],”yyyyMMddHHmmss”,$null))
        $leaseExpiry = $timex.Hours,$timex.Minutes,$timex.Seconds -join ':'
        $DHCPserver = $network.DHCPServer
    }else{$IsDHCPEnabled = $false}
    $MACAddress  = $network.MACAddress
    $AdapterName = (Get-WmiObject win32_NetworkAdapter | ? {$_.MACAddress -eq $MACAddress}).NetConnectionID
    
    # Comment out any info you dont want and/or need
    $OutputObj  = New-Object -Type PSObject
    $OutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress
    #$OutputObj | Add-Member -MemberType NoteProperty -Name SubnetMask -Value $SubnetMask
    $OutputObj | Add-Member -MemberType NoteProperty -Name CIDR -Value $CIDR
    $OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value $DefaultGateway
    $OutputObj | Add-Member -MemberType NoteProperty -Name DHCP -Value $IsDHCPEnabled
    if($IsDHCPEnabled){
        #$OutputObj | Add-Member -MemberType NoteProperty -Name 'Server(s)' -Value $DHCPserver
        $OutputObj | Add-Member -MemberType NoteProperty -Name Expires -Value $leaseExpiry
        }
    $OutputObj | Add-Member -MemberType NoteProperty -Name 'DNSServer(s)' -Value $DNSServers
    #$OutputObj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $MACAddress
    $OutputObj | Add-Member -MemberType NoteProperty -Name AdapterName -Value $AdapterName
    $table += $OutputObj
   }

$line = " ══════════════════════════════════╗"

New-Alias -Name w -Value Write-Host
w ''
w '        ,.=:!!t3Z3z.,                  ' -f R -n; w '' -f $c1 -n; w "  script is running with $privs rights" -f DarkGray
w '       :tt:::tt333EE3             ' -f R -n; w "User:" -f Gray -n; w $env:USERNAME -n; w " Computer:" -f Gray -n; w $env:COMPUTERNAME -n; w " Domain:" -f Gray -n; w $env:USERDOMAIN
w '       Et:::ztt33EEEL ' -f R -n; w '@Ee.,      .., ' -f Gre -n; w ''
w '      ;tt:::tt333EE7 ' -f R -n; w ';EEEEEEttttt33# ' -f Gre -n; w '  OS: '  -f $c1 -n; w $os.caption -n; w ' Build: ' -f $c1 -n; w $os.BuildNumber
w '     :Et:::zt333EEQ. ' -f R -n; w '$EEEEEttttt33QL ' -f Gre -n; w '  ServicePackMajor: ' -f $c1 -n; w $os.ServicePackMajorVersion -n; w ' ServicePackMinor: ' -f $c1 -n; w $os.ServicePackMinorVersion
w '     it::::tt333EEF ' -f R -n; w '@EEEEEEttttt33F  ' -f Gre -n; w '  Windows serial: ' -f $c1 -n; w $os.SerialNumber
w '    ;3=*^```"*4EEV ' -f R -n; w ':EEEEEEttttt33@.  ' -f Gre -n; w '  Install date: ' -f $c1 -n; w $os.InstallDate.DateTime
w '    ,.=::::!t=., ' -f C -n; w '` ' -f R -n; w '@EEEEEEtttz33QF   ' -f Gre -n; w '  System locale: ' -f $c1 -n; w $os.MUILanguages -n; w ' Input locale: ' -f $c1 -n; w (Get-Culture).Name
w '   ;::::::::zt33)   ' -f C -n; w '"4EEEtttji3P*    ' -f Gre -n; w '  TimeZone: ' -f $c1 -n; if (([TimeZoneInfo]::Local).DisplayName.Length -gt 40) { ([TimeZoneInfo]::Local).DisplayName.Substring(0, 40) }else{w ([TimeZoneInfo]::Local).DisplayName}
w '  :t::::::::tt33.' -f C -n; w ':Z3z..  ' -f Y -n; w '`` ' -f Gre -n; w ',..g.    ' -f Y -n; w '  Services: ' -f $c1 -n; w (Get-Service | ? {$_.status -eq 'Running'}).count "running /" (Get-Service | ? {$_.status -eq 'Stopped'}).count "stopped /" (Get-Service).count "total"
w '  i::::::::zt33F ' -f C -n; w 'AEEEtttt::::ztF     ' -f Y -n; w '  Uptime: ' -f $c1 -n; w $suptime 
w ' ;:::::::::t33V ' -f C -n; w ';EEEttttt::::t3      ' -f Y -n; w '  Virtual machine: ' -f $c1 -n; w $hw -n; w ''
w ' E::::::::zt33L ' -f C -n; w '@EEEtttt::::z3F      ' -f Y -n; w '  CPU: ' -f $c1 -n; w $cs.NumberOfProcessors "*" ($cpu.Name -replace '\s+', ' ')
w '{3=*^```"*4E3) ' -f C -n; w ';EEEtttt:::::tZ`      ' -f Y -n; w '  Cores: ' -f $c1 -n; w $cpu.NumberOfCores "cores &" $cpu.NumberOfLogicalProcessors "logical processors"
w '             ` ' -f C -n; w ':EEEEtttt::::z7       ' -f Y -n; w '  Motherboard: ' -f $c1 -n; w $mobo.Manufacturer $mobo.Product
w '                 "VEzjt:;;z>*`       ' -f Y -n; w '  Memory: ' -f $c1 -n; w ($totalmem-$freemem) "GB used of" $totalmem "GB total ($memory%)"
w '                                     ' -n; w '' -f $c1 -n; w '  HDD Free: ' -f $c1 -n; $diskAvail.Substring(0,$diskAvail.Length-2)
if($bios.Name -eq 'Default System BIOS'){w '  BIOS: ' -f $c1 -n; w $bios.Manufacturer $bios.Version '' -n; w $bios.SMBIOSBIOSVersion -n; w ' Serial: ' -f $c1 -n; w $bios.SerialNumber}
    else{w '  BIOS: ' -f $c1 -n; w $bios.Manufacturer -n; w '' $bios.Name '' -n; w $bios.SMBIOSBIOSVersion.Trim()}
if($cs.Manufacturer -ne 'System manufacturer'){w '  Manufacturer: ' -f $c1 -n; w $cs.Manufacturer -n; w ' Family: ' -f $c1 -n; w $cs.SystemFamily -n; w ' Model: ' -f $c1 -n; w $cs.Model; w ''}else{w ''}
w "╔══════" -f $c2 -n;w " NETWORK INFO " -f W -n;w "═════════════════" -f $c2 -n; w " EXTERNAL IP: " -f $c1 -n; w "$ip " -n; w $line.Substring(0+$ip.Length) -f $c2
if ($cs.partofdomain -eq $true) {w " ║" -f $c2 -n;w '  Primary DC: '([ADSI]”LDAP://RootDSE”).dnsHostName}
$table | ft -AutoSize
w "╠══════ " -f $c2 -n;w (Get-HotFix).Count "HOTFIXES INSTALLED " -n; 
if((Get-HotFix).Count -lt 10) {w "═==" -f $c2 -n;}
    elseif((Get-HotFix).Count -lt 100) {w "==" -f $c2 -n;}
    elseif((Get-HotFix).Count -lt 1000) {w "=" -f $c2 -n;}
w " (showing 5 most recent)" -f W -n;w " ═══════════════════════════════╣" -f $c2
$ErrorActionPreference = 'SilentlyContinue'
# Select hotfix info fields
Get-HotFix | sort InstalledOn -Descending | select HotFixID,Description,InstalledOn,InstalledBy,FixComments -First 5 | ft
$ErrorActionPreference = 'Continue'
if($showPrograms){
    w "╠════ " -f $c2 -n;w $prod.Count "PROGRAMS INSTALLED " -n; 
    if($prod.Count -lt 10) {w "═==" -f $c2 -n;}
    elseif($prod.Count -lt 100) {w "==" -f $c2 -n;}
    elseif($prod.Count -lt 1000) {w "=" -f $c2 -n;}
    w " (showing 10 most recent)" -f W -n;w " ════════════════════════════════╣" -f $c2
    $prod | sort installdate -Descending | select InstallDate,Name,Version -First 10 | ft}
w "╚═══════════════════════════════════════════════════════════════════════════════════════╝" -f $c2
Remove-Item Alias:w

Example output below
sysinfo-example