From 89558500bc60d9abb4e7a0576b6750a2ccc9ff63 Mon Sep 17 00:00:00 2001 From: Bartenbach Date: Mon, 23 May 2016 11:00:35 -0500 Subject: [PATCH 1/6] * New cmdlets don't work on Win7 :( * Renamed powershell to better conform with naming convention --- PC-Information.ps1 => Get-PC-Information.ps1 | 6 ++++-- RUN-ME.bat | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) rename PC-Information.ps1 => Get-PC-Information.ps1 (94%) diff --git a/PC-Information.ps1 b/Get-PC-Information.ps1 similarity index 94% rename from PC-Information.ps1 rename to Get-PC-Information.ps1 index 1a39433..fd85a1d 100644 --- a/PC-Information.ps1 +++ b/Get-PC-Information.ps1 @@ -17,11 +17,13 @@ function Handle-NoConnection { $FriendlyName = $Computer.split(":")[1] $Host.UI.WriteErrorLine("Error: No connection could be made to [$FriendlyName] -- 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 } @@ -53,8 +55,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 + #$ipaddress = (Resolve-DnsName Ariel | Select-Object -Expand IPAddress)[3] # formatting $memory = [Math]::round($totalphysicalmemory/1024/1024/1024) diff --git a/RUN-ME.bat b/RUN-ME.bat index 6b3fd05..eef1d66 100644 --- a/RUN-ME.bat +++ b/RUN-ME.bat @@ -1,4 +1,4 @@ @echo off mode con:cols=120 lines=60 -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 From 1e1c4580f3b5f321a7c898b443e7c1a93424c2ff Mon Sep 17 00:00:00 2001 From: Bartenbach Date: Tue, 24 May 2016 13:49:55 -0500 Subject: [PATCH 2/6] * Added in a version check / warning message * Fixed IP Address information in Windows 7 --- Get-PC-Information.ps1 | 19 +++++++++++++++---- README.md | Bin 38 -> 0 bytes 2 files changed, 15 insertions(+), 4 deletions(-) delete mode 100644 README.md diff --git a/Get-PC-Information.ps1 b/Get-PC-Information.ps1 index fd85a1d..82e0a72 100644 --- a/Get-PC-Information.ps1 +++ b/Get-PC-Information.ps1 @@ -29,12 +29,23 @@ function Handle-InvalidOperatingSystem { function Initialize { Write-Host "PC Information - 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 5) { + Write-Host "(You should probably update your PowerShell to the latest version or things might not work)" -ForegroundColor "red" + Write-Host "(You're using PowerShell Version " -n -ForegroundColor "red" + Write-Host $PSVersionTable.PSVersion.Major -n -ForegroundColor "red" + Write-Host ".0)" -ForegroundColor "red" + Write-Host "https://www.microsoft.com/en-us/download/details.aspx?id=50395" -ForegroundColor "red" + } +} + function Main { Clear Initialize @@ -55,8 +66,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) @@ -131,8 +142,8 @@ 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 "" } diff --git a/README.md b/README.md deleted file mode 100644 index 7b50a77bc91ff2569957319a1bd675f9851ccf10..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 38 scmezWPnki1A%MY|L6^akA&()AA)ld$A(tVMp@bn5$j)QnW#D1}0I|{so&W#< From 4fa7ac57377613ece2b16c85af09bfcbed684050 Mon Sep 17 00:00:00 2001 From: Bartenbach Date: Tue, 24 May 2016 14:00:08 -0500 Subject: [PATCH 3/6] * Updated version checking to make more sense --- Get-PC-Information.ps1 | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Get-PC-Information.ps1 b/Get-PC-Information.ps1 index 82e0a72..317d25a 100644 --- a/Get-PC-Information.ps1 +++ b/Get-PC-Information.ps1 @@ -37,12 +37,8 @@ function Initialize { } function Check-PowerShell-Version { - if ($PSVersionTable.PSVersion.Major -lt 5) { - Write-Host "(You should probably update your PowerShell to the latest version or things might not work)" -ForegroundColor "red" - Write-Host "(You're using PowerShell Version " -n -ForegroundColor "red" - Write-Host $PSVersionTable.PSVersion.Major -n -ForegroundColor "red" - Write-Host ".0)" -ForegroundColor "red" - Write-Host "https://www.microsoft.com/en-us/download/details.aspx?id=50395" -ForegroundColor "red" + if ($PSVersionTable.PSVersion.Major -lt 2) { + Write-Warning "(You should probably update your PowerShell to the latest version or things might not work)" } } @@ -66,7 +62,7 @@ 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 + #$macaddress = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $Computer | Select-Object -Expand MacAddress $ip = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where {$_.Ipaddress.length -gt 1} # formatting @@ -143,7 +139,7 @@ function Display-Result { Write-Host "" Write-Host "Network" -ForegroundColor "Magenta" Format-Result Cyan " IP " Cyan $ip.ipaddress[0] - Format-Result Cyan " Mac " Cyan $macaddress + #Format-Result Cyan " Mac " Cyan $macaddress Write-Host "---------------------------------------------------------" -foregroundcolor "Green" Write-Host "" } From f86a3bd2d0a424efc7e95452248c88442aa7c478 Mon Sep 17 00:00:00 2001 From: Bartenbach Date: Mon, 6 Jun 2016 08:47:41 -0500 Subject: [PATCH 4/6] * Fixed some formatting --- Get-PC-Information.ps1 | 27 +++++++++++++-------------- RUN-ME.bat | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Get-PC-Information.ps1 b/Get-PC-Information.ps1 index 317d25a..366f448 100644 --- a/Get-PC-Information.ps1 +++ b/Get-PC-Information.ps1 @@ -14,9 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -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 } @@ -82,12 +81,12 @@ function Main { $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 } } @@ -96,19 +95,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) { diff --git a/RUN-ME.bat b/RUN-ME.bat index eef1d66..ebcdeb1 100644 --- a/RUN-ME.bat +++ b/RUN-ME.bat @@ -1,4 +1,4 @@ @echo off -mode con:cols=120 lines=60 +mode con:cols=79 lines=37 powershell -ExecutionPolicy Bypass .\Get-PC-Information.ps1 \ No newline at end of file From 2bfa5295f4e7e05721f037dc04633b1f95606742 Mon Sep 17 00:00:00 2001 From: Bartenbach Date: Tue, 7 Jun 2016 13:15:15 -0500 Subject: [PATCH 5/6] + Added logging to file --- Get-PC-Information.ps1 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Get-PC-Information.ps1 b/Get-PC-Information.ps1 index 366f448..355546f 100644 --- a/Get-PC-Information.ps1 +++ b/Get-PC-Information.ps1 @@ -76,6 +76,7 @@ function Main { } Display-Result + Output-To-File Write-Host "Press any key to exit..." -ForegroundColor "Green" $Pause = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") @@ -143,4 +144,37 @@ function Display-Result { Write-Host "" } +function Output-To-File { + $file = "$HOME\AppData\Local\Temp\PC-Information.log" + + if (!(Test-Path $file)) { + New-Item -Path $file -Type File -Force + } + "----------------------------------------------------------" >> $file + "Computer" >> $file + " System Name " + $system >> $file + " Manufacturer " + $manufacturer >> $file + " Model " + $model >> $file + " 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 \ No newline at end of file From 4b1cf3a49dc89b6904fb3b24220ad90bd83131d4 Mon Sep 17 00:00:00 2001 From: Bartenbach Date: Thu, 16 Jun 2016 08:50:17 -0500 Subject: [PATCH 6/6] * Fixed logging to file messages --- Get-PC-Information.ps1 | 6 ++++-- RUN-ME.bat | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Get-PC-Information.ps1 b/Get-PC-Information.ps1 index 355546f..0ef243b 100644 --- a/Get-PC-Information.ps1 +++ b/Get-PC-Information.ps1 @@ -145,10 +145,11 @@ function Display-Result { } function Output-To-File { - $file = "$HOME\AppData\Local\Temp\PC-Information.log" + $file = "$HOME\Documents\PC-Information.log" if (!(Test-Path $file)) { - New-Item -Path $file -Type File -Force + New-Item -Path $file -Type File -Force >> $null + Write-Host "Log file created at $file `n" -ForegroundColor "Yellow" } "----------------------------------------------------------" >> $file "Computer" >> $file @@ -175,6 +176,7 @@ function Output-To-File { #" Mac " $macaddress >> $file "---------------------------------------------------------" >> $file "" >> $file + } Main \ No newline at end of file diff --git a/RUN-ME.bat b/RUN-ME.bat index ebcdeb1..481e757 100644 --- a/RUN-ME.bat +++ b/RUN-ME.bat @@ -1,4 +1,4 @@ @echo off -mode con:cols=79 lines=37 +mode con:cols=82 lines=37 powershell -ExecutionPolicy Bypass .\Get-PC-Information.ps1 \ No newline at end of file