Last active
September 4, 2020 16:00
-
-
Save PolarBearGod/c9c5c01706b0061e59d018a0a4993ba9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-SystemInfo { | |
param([Parameter(Mandatory = $true)] $ComputerName, [switch] $IgnorePing) | |
$computer = $ComputerName | |
$data = @{} | |
$data.' ComputerName' = $computer | |
$ping = Test-Connection -quiet -count 1 $computer | |
$Ping = $(if ($ping) { 'Yes' }else { 'No' }) | |
$ErrorActionPreference = 'SilentlyContinue' | |
if ($ips = [System.Net.Dns]::GetHostAddresses($computer) | ForEach-Object { $_.IPAddressToString }) { $data.'IP Address(es) from DNS' = ($ips -join ', ') }else { $data.'IP Address from DNS' = 'Could not resolve' } | |
$ErrorActionPreference = 'Continue' | |
if ($ping -or $ignorePing) { | |
$data.'WMI Data Collection Attempt' = 'Yes (ping reply or -IgnorePing)' | |
if ($wmi = Get-WmiObject -Computer $computer -Class Win32_ComputerSystem -ErrorAction SilentlyContinue) { | |
$data.'Computer Hardware Manufacturer' = $wmi.Manufacturer | |
$data.'Computer Hardware Model' = $wmi.Model | |
$data.'Memory Physical in MB' = ($wmi.TotalPhysicalMemory / 1MB).ToString('N') | |
$data.'Logged On User' = $wmi.Username | |
} | |
$wmi = $null | |
if ($wmi = Get-WmiObject -Computer $computer -Class Win32_LogicalDisk -Filter 'DriveType=3' -ErrorAction SilentlyContinue) { $wmi | Select-Object 'DeviceID', 'Size', 'FreeSpace' | ForEach-Object { $data."Local disk $($_.DeviceID)" = ('' + ($_.FreeSpace / 1MB).ToString('N') + ' MB free of ' + ($_.Size / 1MB).ToString('N') + ' MB total space with ' + ($_.Size / 1MB - $_.FreeSpace / 1MB).ToString('N') + ' MB Used Space') } } | |
$wmi = $null | |
if ($wmi = Get-WmiObject -Computer $computer -Class Win32_NetworkAdapterConfiguration -ErrorAction SilentlyContinue) { | |
$Ips = @{} | |
$wmi | Where-Object { $_.IPAddress -match '\S+' } | ForEach-Object { $Ips.$($_.IPAddress -join ', ') = $_.MACAddress } | |
$counter = 0 | |
$Ips.GetEnumerator() | ForEach-Object { $counter++; $data."IP Address $counter" = '' + $_.Name + ' (MAC: ' + $_.Value + ')' } | |
} | |
$wmi = $null | |
if ($wmi = Get-WmiObject -Computer $computer -Class Win32_Processor -ErrorAction SilentlyContinue) { | |
$wmi | ForEach-Object { | |
$maxClockSpeed = $_.MaxClockSpeed | |
$numberOfCores += $_.NumberOfCores | |
$description = $_.Description | |
$numberOfLogProc += $_.NumberOfLogicalProcessors | |
$socketDesignation = $_.SocketDesignation | |
$status = $_.Status | |
$manufacturer = $_.Manufacturer | |
$name = $_.Name } | |
$data.'CPU Clock Speed' = $maxClockSpeed | |
$data.'CPU Cores' = $numberOfCores | |
$data.'CPU Description' = $description | |
$data.'CPU Logical Processors' = $numberOfLogProc | |
$data.'CPU Socket' = $socketDesignation | |
$data.'CPU Status' = $status | |
$data.'CPU Manufacturer' = $manufacturer | |
$data.'CPU Name' = $name -replace '\s+', ' ' | |
} | |
$wmi = $null | |
if ($wmi = Get-WmiObject -Computer $computer -Class Win32_Bios -ErrorAction SilentlyContinue) { | |
$data.'BIOS Manufacturer' = $wmi.Manufacturer | |
$data.'BIOS Name' = $wmi.Name | |
$data.'BIOS Version' = $wmi.Version | |
} | |
$wmi = $null | |
if ($wmi = Get-WmiObject -Computer $computer -Class Win32_OperatingSystem -ErrorAction SilentlyContinue) { | |
$data.'OS Boot Time' = $wmi.ConvertToDateTime($wmi.LastBootUpTime) | |
$data.'OS System Drive' = $wmi.SystemDrive | |
$data.'OS System Device' = $wmi.SystemDevice | |
$data.'OS Language' = $wmi.OSLanguage | |
$data.'OS Version' = $wmi.Version | |
$data.'OS Windows dir' = $wmi.WindowsDirectory | |
$data.'OS Name' = $wmi.Caption | |
$data.'OS Install Date' = $wmi.ConvertToDateTime($wmi.InstallDate) | |
$data.'OS Service Pack' = [string]$wmi.ServicePackMajorVersion + '.' + $wmi.ServicePackMinorVersion | |
} | |
$ports = @{'File shares/RPC' = '139'; 'File shares' = '445'; 'RDP' = '3389'; 'SSH' = '22'; 'FTP' = '21'; 'Telnet' = '23'; 'SMTP' = '25'; } | |
foreach ($service in $ports.Keys) { | |
$socket = New-Object Net.Sockets.TcpClient | |
$ErrorActionPreference = 'SilentlyContinue' | |
$socket.Connect($computer, $ports.$service) | |
$ErrorActionPreference = 'Continue' | |
if ($socket.Connected) { | |
$data."Port $($ports.$service)($service)" = 'Open' | |
$socket.Close() | |
} | |
else { $data."Port $($ports.$service)($service)" = 'Closed or filtered' }$socket = $null | |
} | |
} | |
else { $data.'WMI Data Collected' = 'No (no ping reply and -IgnorePing not specified)' } | |
$wmi = $null | |
if ($wmi = Get-WmiObject -Class Win32_OperatingSystem -computername $Computer -ErrorAction SilentlyContinue | Select-Object Name, TotalVisibleMemorySize, FreePhysicalMemory, TotalVirtualMemorySize, FreeVirtualMemory, FreeSpaceInPagingFiles, NumberofProcesses, NumberOfUsers ) { | |
$wmi | ForEach-Object { $TotalRAM = $_.TotalVisibleMemorySize / 1MB | |
$FreeRAM = $_.FreePhysicalMemory / 1MB | |
$UsedRAM = $_.TotalVisibleMemorySize / 1MB - $_.FreePhysicalMemory / 1MB | |
$TotalRAM = [Math]::Round($TotalRAM, 2) | |
$FreeRAM = [Math]::Round($FreeRAM, 2) | |
$UsedRAM = [Math]::Round($UsedRAM, 2) | |
$RAMPercentFree = ($FreeRAM / $TotalRAM) * 100 | |
$RAMPercentFree = [Math]::Round($RAMPercentFree, 2) | |
$TotalVirtualMemorySize = [Math]::Round($_.TotalVirtualMemorySize / 1MB, 3) | |
$FreeVirtualMemory = [Math]::Round($_.FreeVirtualMemory / 1MB, 3) | |
$FreeSpaceInPagingFiles = [Math]::Round($_.FreeSpaceInPagingFiles / 1MB, 3) | |
$NumberofProcesses = $_.NumberofProcesses | |
$NumberOfUsers = $_.NumberOfUsers } | |
$data.'Memory - Total RAM GB' = $TotalRAM | |
$data.'Memory - RAM Free GB' = $FreeRAM | |
$data.'Memory - RAM Used GB' = $UsedRAM | |
$data.'Memory - Percentage Free' = $RAMPercentFree | |
$data.'Memory - TotalVirtualMemorySize' = $TotalVirtualMemorySize | |
$data.'Memory - FreeVirtualMemory' = $FreeVirtualMemory | |
$data.'Memory - FreeSpaceInPagingFiles' = $FreeSpaceInPagingFiles | |
$data.'NumberofProcesses' = $NumberofProcesses | |
$data.'NumberOfUsers' = $NumberOfUsers -replace '\s+', ' ' | |
} | |
"#" * 80 | |
"OS Complete Information" | |
"Generated $(get-date)" | |
"Generated from $(Get-Content env:computername)" | |
"#" * 80 | |
$data.GetEnumerator() | Sort-Object 'Name' | Format-Table -AutoSize | |
$data.GetEnumerator() | Sort-Object 'Name' | Out-GridView -Title "$computer Information" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment