From e1429781c1e0b97f8cc23c2049d8405d3d6cd4e2 Mon Sep 17 00:00:00 2001 From: efrick Date: Tue, 20 Apr 2021 10:08:24 -0400 Subject: [PATCH] Powershell is now working. The powershell version is now functional. The .bat version has been updated to include RAM output as well. --- README.md | 19 +++++--- sysinfo.bat | 4 +- sysinfo.ps1 | 133 ++++++++++++++++++++++++++++++++++++---------------- 3 files changed, 109 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index f4992d9..3887f0a 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ A script to output to output basic system information. ## Usage -1. Download the `.bat` file. -2. Run from `CMD` with `C:\Path\to\sysinfo.bat` +1. Download the `.ps1` file. +2. Run from `CMD` with `C:\Path\to\sysinfo.ps1` ## Features @@ -13,17 +13,22 @@ It currently outputs: * The Hostname * The CPU name +* The CPU Architecture * The OS Version +* The OS Architecture +* The System's Manufacturer +* The System's Model name * The system's serial number -* The model name of the system +* The GPU model name +* The amount of system RAM ## Quick Run Copy and past into `CMD` ``` -curl https://efrick.ddns.net/git/efrick/Sysinfo/raw/branch/master/sysinfo.bat > %userprofile%\AppData\Local\Temp\temp.bat -%userprofile%\AppData\Local\Temp\temp.bat +curl https://efrick.ddns.net/git/efrick/Sysinfo/raw/branch/master/sysinfo.bat > %userprofile%\AppData\Local\Temp\sysinfo.ps1 +%userprofile%\AppData\Local\Temp\sysinfo.ps1 ``` @@ -35,4 +40,6 @@ Uses `echo` and `wmic`. ## `sysinfo.ps1` -This is currently under development. Don't use it. \ No newline at end of file +This is now the recommended file to use. + +It will require the ability to run Powershell Scripts which is restricted by default. \ No newline at end of file diff --git a/sysinfo.bat b/sysinfo.bat index 85b65bf..a46d546 100644 --- a/sysinfo.bat +++ b/sysinfo.bat @@ -10,4 +10,6 @@ wmic os get Caption echo System Serial Number wmic bios get serialnumber echo System Model Name -wmic csproduct get name \ No newline at end of file +wmic csproduct get name +echo System RAM + systeminfo.exe | findstr /C:"Total Physical Memory" \ No newline at end of file diff --git a/sysinfo.ps1 b/sysinfo.ps1 index 71e552e..5708738 100644 --- a/sysinfo.ps1 +++ b/sysinfo.ps1 @@ -1,43 +1,96 @@ #sysinfo.ps1 #Inumerate a systems processor, serial number, modle number, and ammount of RAM. -echo "Hostname" -wmic computersystem get name -echo "CPU name" -wmic cpu get name -echo "OS Type" -wmic os get Caption -echo "System Serial Number" -wmic bios get serialnumber -echo "System Model Name" -wmic csproduct get name -# wmic computersystem get name; wmic cpu get name; wmic os get Caption;wmic bios get serialnumber; wmic csproduct get name -#Get-ServerInformation.ps1 -#------------------- -#$serversOuPath = 'OU=Servers,DC=powerlab,DC=local' -#$servers = Get-ADComputer -SearchBase $serversOuPath -Filter * | -#Select-Object -ExpandProperty Name -#foreach ($server in $servers) { -# $output = @{ -# 'ServerName' = $null -# 'IPAddress' = $null -# 'OperatingSystem' = $null -# 'AvailableDriveSpace (GB)' = $null -# 'Memory (GB)' = $null -# 'UserProfilesSize (MB)' = $null -# 'StoppedServices' = $null -# } -# $getCimInstParams = @{ -# CimSession = New-CimSession -ComputerName $server -# } -# $output.ServerName = $server -# $output.'UserProfilesSize (MB)' = (Get-ChildItem -Path "\\$server\c$\ -# Users\" -File | Measure-Object -Property Length -Sum).Sum -# $output.'AvailableDriveSpace (GB)' = [Math]::Round(((Get-CimInstance @getCimInstParams -ClassName Win32_LogicalDisk).FreeSpace / 1GB),1) -# $output.'OperatingSystem' = (Get-CimInstance @getCimInstParams -ClassName Win32_OperatingSystem).Caption -# $output.'Memory (GB)' = (Get-CimInstance @getCimInstParams -ClassName Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Sum /1GB -# $output.'IPAddress' = (Get-CimInstance @getCimInstParams -ClassName Win32_NetworkAdapterConfiguration -Filter "IPEnabled = 'True'").IPAddress[0] -# $output.StoppedServices = (Get-Service -ComputerName $server | Where-Object { $_.Status -eq 'Stopped' }).DisplayName -# Remove-CimSession -CimSession $getCimInstParams.CimSession -# [pscustomobject]$output -#} \ No newline at end of file +param( + [switch]$write_output, + [switch]$file_location, + [string]$file_path +) + +function Show-Notification { #Shows a notification in the system notification tray. + param ( + [string] + $ToastTitle, + [string] + $ToastText + ) + + [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null + $Template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02) + $RawXML = [xml] $Template.GetXML() + ($RawXML.toast.visual.binding.text|Where-Object {$_.id -eq "1"}).AppendChild($RawXml.CreateTextNode($ToastTitle)) > $null + ($RawXml.toast.visual.binding.text|Where-Object {$_.id -eq "2"}).AppendChild($RawXml.CreateTextNode($ToastText)) > $null + + $SerializedXml = New-Object Windows.Data.Xml.Dom.XmlDocument + $SerializedXml.LoadXml($RawXml.OuterXml) + + $Toast = [Windows.UI.Notifications.ToastNotification]::new($SerializedXml) + $Toast.Tag = "PowerShell" + $Toast.Group = "PowerShell" + $Toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(1) + + $Notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Sysinfo") + $Notifier.Show($Toast); +} + + +function Find-RAM { #This finds the systems total physical memory and then returns this as a value in Gigabytes. + + $cs = Get-CimInstance -ClassName win32_computersystem + + $system_memory = $cs.totalphysicalmemory + + $system_memory = $system_memory * 0.000000001 #Multiplies by 0.000000001 as the number give by CIM is in bytes. + $system_memory = [math]::floor($system_memory) + $system_memory = [String]$system_memory + " GB" + + return $system_memory +} + +function Find-Computer-Info { + + $cs = Get-CimInstance -ClassName Win32_ComputerSystem + $bios_info = Get-CimInstance -ClassName CIM_BIOSElement + $cpu_info = Get-CimInstance -ClassName Win32_Processor + $gpu_info = Get-CimInstance -ClassName CIM_VideoController + $computer_os_info = Get-CimInstance -ClassName CIM_OperatingSystem + + #Init array for storing computer's data + $computer_info = @("HOSTNAME:", $cs.Name, + "OS Version:", $computer_os_info.Caption, + "OS Architecture:", $computer_os_info.OSArchitecture, + "Manufacture:", $cs.manufacturer, + "Model Name:", $cs.model, + "Serial Number:", $bios_info.SerialNumber, + "CPU Name:", $cpu_info.Name, + "CPU Type:", $cpu_info.Caption, + "GPU Name:", $gpu_info.Name) + + return $computer_info +} + +function Show-Computer-Info { # Function writes by default to stdout. If given a command line option it will write to a file. + if ($write_output.IsPresent){ #If this switch is present the script will write the output to a file. Otherwise it writes to stdout. + $computer_hostname = Get-CimInstance -ClassName Win32_ComputerSystem + $output_filename = "SystemProfile_" + $computer_hostname.Name + ".txt" + $output_path = "" + if ($file_location.IsPresent){ + $output_path = "$file_path\$output_filename" + }else { + $output_path = $env:USERPROFILE + "\Desktop\" + $output_filename + } + foreach($line in $cs_info){ + $line | Out-File -FilePath $output_path -Encoding utf8 -Append + Show-Notification("File is done writing.`nWriten to: $output_path") + } + }else { + foreach($line in $cs_info){ + Write-Output $line + } + } +} + +$cs_info = Find-Computer-Info +$RAM_info = Find-RAM +$cs_info += ("RAM:", $RAM_info) +Show-Computer-Info \ No newline at end of file