Skip to content

Commit

Permalink
Merge branch 'master' of github.com:proxa/PC-Information
Browse files Browse the repository at this point in the history
  • Loading branch information
bartenbach committed Feb 18, 2017
2 parents 61b5b18 + 4b1cf3a commit ae4a098
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
PC-Information.ps1~
..gitignore.un~
.gitignore~
.Get-PC-Information.ps1.un~
Get-PC-Information.ps1~
83 changes: 65 additions & 18 deletions PC-Information.ps1 → Get-PC-Information.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,33 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
$version = '0.0.1'

function Handle-NoConnection {
$FriendlyName = $Computer.split(":")[1]
$Host.UI.WriteErrorLine("Error: No connection could be made to [$FriendlyName] -- Is the machine on?")
function Handle-NoConnection ([String]$Computer){
$Host.UI.WriteErrorLine("Error: No connection could be made to [$Computer] -- Is the machine on?")
$Pause = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Exit
}

function Handle-InvalidOperatingSystem {
$Host.UI.WriteErrorLine("Error: Invalid Operating System -- Is that a Windows machine?")
$Pause = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Exit
}

function Initialize {
Write-Host "PC Information $version - Jonathon Ament, Blake Bartenbach - Copyright 2016" -foregroundcolor "DarkGray"
Check-PowerShell-Version
$OS = Get-WmiObject -Computer $env:computername -Class Win32_OperatingSystem
if ($OS.caption -notlike "*Windows*") {
Handle-InvalidOperatingSystem
}
}

function Check-PowerShell-Version {
if ($PSVersionTable.PSVersion.Major -lt 2) {
Write-Warning "(You should probably update your PowerShell to the latest version or things might not work)"
}
}

function Main {
Clear
Initialize
Expand All @@ -54,8 +62,8 @@ function Main {
$sp = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer | Select-Object -Expand ServicePackMajorVersion
$username = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Computer | Select-Object -Expand Username
$printers = Get-WmiObject -Class Win32_Printer -ComputerName $Computer | Select-Object -Expand Name
$macaddress = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer | Select-Object -Expand MacAddress
$ipaddress = (Resolve-DnsName Ariel | Select-Object -Expand IPAddress)[3]
#$macaddress = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer | Select-Object -Expand MacAddress
$ip = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where {$_.Ipaddress.length -gt 1}

# formatting
$memory = [Math]::round($totalphysicalmemory/1024/1024/1024)
Expand All @@ -69,17 +77,18 @@ function Main {
}

Display-Result
Output-To-File

Write-Host "Press any key to exit..." -ForegroundColor "Green"
$Pause = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}

function Check-Connection([String]$ComputerName) {
function Check-Connection([String]$Computer) {
Write-Host "----------------------------------------------------------" -foregroundcolor "Green"
Write-Host "Checking connection..." -ForegroundColor "green"
$Connection = Test-Connection -ComputerName $computer -Quiet
$Connection = Test-Connection -ComputerName $Computer -Quiet
if (!$Connection) {
Handle-NoConnection
Handle-NoConnection $Computer
}
}

Expand All @@ -88,19 +97,19 @@ function Get-ComputerName {
$computer = Read-Host

if ([string]::IsNullOrEmpty($computer)) {
return $env:computername
return $env:computername
} else {
return $computer
return $computer
}
}

function Get-Uptime {
$os = Get-WmiObject win32_operatingsystem
$uptime = (Get-Date) - ($os.ConvertToDateTime($os.lastbootuptime))
$days = $Uptime.Days
$hours = $Uptime.Hours
$minutes = $Uptime.Minutes
return "$days days, $hours hours, $minutes minutes"
$os = Get-WmiObject win32_operatingsystem
$uptime = (Get-Date) - ($os.ConvertToDateTime($os.lastbootuptime))
$days = $Uptime.Days
$hours = $Uptime.Hours
$minutes = $Uptime.Minutes
return "$days days, $hours hours, $minutes minutes"
}

function Format-Result([System.ConsoleColor]$color1, [String]$s, [System.ConsoleColor]$color2, [String]$info) {
Expand Down Expand Up @@ -133,10 +142,48 @@ function Display-Result {
Format-Result Cyan " Domain\Username " Cyan $username
Write-Host ""
Write-Host "Network" -ForegroundColor "Magenta"
Format-Result Cyan " Mac Address " Cyan $macaddress
Format-Result Cyan " IP Address " Cyan $ipaddress
Format-Result Cyan " IP " Cyan $ip.ipaddress[0]
#Format-Result Cyan " Mac " Cyan $macaddress
Write-Host "---------------------------------------------------------" -foregroundcolor "Green"
Write-Host ""
}

function Output-To-File {
$file = "$HOME\Documents\PC-Information.log"

if (!(Test-Path $file)) {
New-Item -Path $file -Type File -Force >> $null
Write-Host "Log file created at $file `n" -ForegroundColor "Yellow"
}
"----------------------------------------------------------" >> $file
"Computer" >> $file
" System Name " + $system >> $file
" Manufacturer " + $manufacturer >> $file
" Model " + $model >> $file
# serial number may not be available
if (![string]$serialnumber.equals("System Serial Number")) {
" Serial Number " + $serialnumber >> $file
}
" BIOS Version " + $biosversion >> $file
"" >> $file
"Specifications" >> $file
" CPU " + $processor >> $file
" Total RAM " + $memoryString >> $file
" Operating System " + $osname >> $file
" Uptime " + (Get-Uptime) >> $file
"" >> $file
"Printers" >> $file
" $printers" >> $file
"" >> $file
"User" >> $file
" Domain\Username " + $username >> $file
"" >> $file
"Network" >> $file
" IP " + $ip.ipaddress[0] >> $file
#" Mac " $macaddress >> $file
"---------------------------------------------------------" >> $file
"" >> $file

}

Main
Binary file removed README.md
Binary file not shown.
4 changes: 2 additions & 2 deletions RUN-ME.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo off
mode con:cols=120 lines=60
mode con:cols=82 lines=37

powershell -ExecutionPolicy Bypass .\PC-Information.ps1
powershell -ExecutionPolicy Bypass .\Get-PC-Information.ps1

0 comments on commit ae4a098

Please sign in to comment.