diff --git a/.gitignore b/.gitignore index 959d11d..9b97c0b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ PC-Information.ps1~ ..gitignore.un~ .gitignore~ +.Get-PC-Information.ps1.un~ +Get-PC-Information.ps1~ diff --git a/PC-Information.ps1 b/Get-PC-Information.ps1 similarity index 61% rename from PC-Information.ps1 rename to Get-PC-Information.ps1 index 7dc1249..582a57f 100644 --- a/PC-Information.ps1 +++ b/Get-PC-Information.ps1 @@ -15,25 +15,33 @@ # along with this program. If not, see . $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 @@ -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) @@ -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 } } @@ -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) { @@ -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 diff --git a/README.md b/README.md deleted file mode 100644 index 7b50a77..0000000 Binary files a/README.md and /dev/null differ diff --git a/RUN-ME.bat b/RUN-ME.bat index 6b3fd05..481e757 100644 --- a/RUN-ME.bat +++ b/RUN-ME.bat @@ -1,4 +1,4 @@ @echo off -mode con:cols=120 lines=60 +mode con:cols=82 lines=37 -powershell -ExecutionPolicy Bypass .\PC-Information.ps1 \ No newline at end of file +powershell -ExecutionPolicy Bypass .\Get-PC-Information.ps1 \ No newline at end of file