Created
March 17, 2017 07:26
-
-
Save TheRealNoob/1c111ae22eabe3120b5cffb3ccb8c399 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
<# | |
TODO | |
SUGGESTIONS: | |
------------------------------------------ | |
alternatives to WMI: CIM (maxfrost), async (jrich) | |
FIREWALL: | |
------------------------------------------ | |
get UAC level | |
MEMORY: | |
------------------------------------------ | |
fix numbers. bad data inputs | |
DRIVES: | |
------------------------------------------ | |
unify formatting. Update Removable and network drives. | |
#> | |
Function Get-SystemInfo { | |
<# | |
.SYNOPSIS | |
Get Complete details of local system info | |
.DESCRIPTION | |
This function uses WMI class to query local machine for system info. | |
Output is saved to [array] $data | |
.EXAMPLE | |
Get-SystemInfo | |
.EXAMPLE | |
Get-SystemInfo -ComputerName HQSPDBSP01 | |
.NOTES | |
To get help: | |
Get-Help Get-SystemInfo | |
Original credit of script goes to: | |
https://gallery.technet.microsoft.com/scriptcenter/PowerShell-System-571521d1 | |
#> | |
Param( | |
[Parameter(Mandatory=$false,ValueFromPipeline=$true)] | |
[ValidateNotNullOrEmpty()] | |
[ValidateCount(1,1)] | |
[string]$ComputerName = $env:COMPUTERNAME | |
) | |
# Declare main data hashtable to be populated later | |
$data = New-Object System.Collections.Specialized.OrderedDictionary #Same as PSv3 [ordered]. For PSv1, PSv2 compatibility | |
$data.'Hostname'=$ComputerName | |
# Get BIOS info from WMI | |
if ($wmi = Get-WmiObject -Computer $ComputerName -Class Win32_Bios -ErrorAction SilentlyContinue) { | |
$data.'BIOS Manufacturer' = $wmi.Manufacturer | |
$data.'BIOS Name' = $wmi.Name | |
$data.'BIOS Version' = $wmi.Version | |
$wmi = $null | |
} | |
# Get various info from the ComputerSystem WMI class | |
if ($wmi = Get-WmiObject -ComputerName $ComputerName -Class Win32_ComputerSystem -ErrorAction SilentlyContinue) { | |
$data.'Hardware Manufacturer' = $wmi.Manufacturer | |
$data.'Hardware Model' = $wmi.Model | |
$data.'Memory - Physical' = ([math]::Round($wmi.TotalPhysicalMemory/1MB, 2)).ToString() + 'MB' | |
$data.'Users - Logged On User' = $wmi.Username | |
$wmi = $null | |
} | |
# Do a DNS lookup with a .NET class method. Suppress error messages. | |
$ErrorActionPreference = 'SilentlyContinue' | |
if ( $ips = [System.Net.Dns]::GetHostAddresses($ComputerName) | foreach { $_.IPAddressToString } ) { | |
$data.'IP Address(es) from DNS' = ($ips -join ', ') | |
} else { | |
$data.'IP Address from DNS' = 'Could not resolve' | |
} | |
$ErrorActionPreference = 'Continue' | |
# Local disks | |
if ($wmi = Get-WmiObject -Computer $ComputerName -Class Win32_LogicalDisk -Filter 'DriveType=3' -ErrorAction SilentlyContinue) { | |
$wmi | Select 'DeviceID', 'Size', 'FreeSpace' | Foreach { | |
$data."Disk - Local $($_.DeviceID) - Label" = $_.VolumeName | |
$data."Disk - Local $($_.DeviceID) - Total (GB)" = ($_.Size/1GB).ToString('n') | |
$data."Disk - Local $($_.DeviceID) - Used (GB)" = (($_.Size - $_.FreeSpace)/1GB).ToString('n') + ' (' + ([Math]::Round((($_.Size - $_.FreeSpace) / $_.Size)*100,2)).ToString() + '%)' | |
$data."Disk - Local $($_.DeviceID) - Free (GB)" = ($_.FreeSpace/1GB).ToString('n') + ' (' + ([Math]::Round(($_.FreeSpace / $_.Size)*100,2)).ToString() + '%)' | |
} | |
$wmi = $null | |
} | |
# Removable disks | |
if ($wmi = Get-WmiObject -Computer $ComputerName -Class Win32_LogicalDisk -Filter 'DriveType=2' -ErrorAction SilentlyContinue) { | |
$wmi | Select 'DeviceID', 'Size', 'FreeSpace' | Foreach { | |
$data."Disk - Removable $($_.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 | |
} | |
# Network drives | |
if ($wmi = Get-WmiObject -Computer $ComputerName -Class Win32_LogicalDisk -Filter 'DriveType=4' -ErrorAction SilentlyContinue) { | |
$wmi | Select 'DeviceID', 'Size', 'FreeSpace' | Foreach { | |
$data."Disk - Network $($_.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 | |
} | |
# Get IP addresses from all local network adapters through WMI | |
if ($wmi = Get-WmiObject -Computer $ComputerName -Class Win32_NetworkAdapterConfiguration -ErrorAction SilentlyContinue) { | |
$Ips = @{} | |
$wmi | Where { $_.IPAddress -match '\S+' } | Foreach { $_.MACAddress = $Ips.$($_.IPAddress -join ', ') } | |
$counter = 0 | |
$Ips.GetEnumerator() | Foreach { | |
$counter++ | |
$data."IP Address $counter" = '' + $_.Name + ' (MAC: ' + $_.Value + ')' | |
} | |
$wmi = $null | |
} | |
# Get CPU information with WMI | |
if ($wmi = Get-WmiObject -Computer $ComputerName -Class Win32_Processor -ErrorAction SilentlyContinue) { | |
$wmi | Foreach { | |
$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 | |
} | |
# Get operating system info from WMI | |
if ($wmi = Get-WmiObject -Computer $ComputerName -Class Win32_OperatingSystem -ErrorAction SilentlyContinue) { | |
$data.'OS - Install Date' = $wmi.ConvertToDateTime($wmi.InstallDate) | |
$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 - Service Pack' = [string]$wmi.ServicePackMajorVersion + '.' + $wmi.ServicePackMinorVersion | |
$wmi = $null | |
} | |
# Scan for open ports | |
$ports = @{ | |
'FTP (Data)' = '20' ; | |
'FTP (Control)' = '21' ; | |
'SSH' = '22' ; | |
'Telnet' = '23' ; | |
'SMTP' = '25' ; | |
'Finger' = '79' ; | |
'HTTP' = '80' ; | |
'POP3' = '110' ; | |
'Ident' = '113' ; | |
'NNTP' = '119' ; | |
'DCE endpoint' = '135' ; | |
'NetBIOS' = '137' ; | |
'File shares/RPC' = '139' ; | |
'IMAP' = '143' ; | |
'LDAP' = '389' ; | |
'HTTPS' = '443' ; | |
'File shares' = '445' ; | |
'MS NetMeeting' = '1002' ; | |
'(trojans)' = '1024' ; | |
'(KWM trojans)' = '1030' ; | |
'SOCKS proxy' = '1080' ; | |
'VOIP' = '1720' ; | |
'Zenworks' = '1761'; | |
'UPnP Discovery' = '1900' ; | |
'RDP' = '3389'; | |
'(multiple)' = '5000'; | |
'alt. HTTP' = '8080'; | |
} | |
foreach ($service in $ports.Keys) { | |
$socket = New-Object Net.Sockets.TcpClient | |
# Suppress error messages | |
$ErrorActionPreference = 'SilentlyContinue' | |
# Try to connect | |
$socket.Connect($ComputerName, $ports.$service) | |
# Make error messages visible again | |
$ErrorActionPreference = 'Continue' | |
if ($socket.Connected) { | |
$data."Port $($ports.$service) ($service)" = 'Open' | |
$socket.Close() | |
}else { | |
$data."Port $($ports.$service) ($service)" = 'Closed or filtered' | |
} | |
$socket = $null | |
$wmi = $null | |
} | |
# RAM, Processor(s), User(s) | |
if ($wmi = Get-WmiObject -ComputerName $ComputerName -Class Win32_OperatingSystem -ErrorAction SilentlyContinue| Select-Object Name, TotalVisibleMemorySize, FreePhysicalMemory,TotalVirtualMemorySize,FreeVirtualMemory,FreeSpaceInPagingFiles,NumberofProcesses,NumberOfUsers ) { | |
$wmi | Foreach { | |
$data.'Memory - Total (GB)' = [Math]::Round($_.TotalVisibleMemorySize / 1GB,2).ToString() | |
$data.'Memory - Free (GB)' = [Math]::Round($_.FreePhysicalMemory / 1GB,2).ToString() + ' (' + ([Math]::Round(($_.FreePhysicalMemory / $_.TotalVisibleMemorySize)*100,2)).ToString() + '%)' | |
$data.'Memory - Used (GB)' = [Math]::Round(($_.TotalVisibleMemorySize - $_.FreePhysicalMemory) / 1GB,2).ToString() + ' (' + ([Math]::Round((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory) / $_.TotalVisibleMemorySize)*100,2)).ToString() + '%)' | |
$data.'Memory - TotalVirtualMemorySize (MB)' = ([Math]::Round($_.TotalVirtualMemorySize,2)/1MB).ToString() | |
$data.'Memory - FreeVirtualMemory (MB)' = ([Math]::Round($_.FreeVirtualMemory,2)/1MB).ToString() | |
$data.'Memory - FreeSpaceInPagingFiles (MB)' = ([Math]::Round($_.FreeSpaceInPagingFiles,2)/1MB).ToString() | |
$data.'NumberofProcesses'= $_.NumberofProcesses | |
$data.'Users - Number of users' = $_.NumberOfUsers | |
} | |
$wmi = $null | |
} | |
# Output data | |
"#"*80 | |
"System Information" | |
"Completion time : " + (get-date) | |
"Ran from PC : " + ($env:COMPUTERNAME) | |
"Ran against PC : " + ($ComputerName) | |
"#"*80 | |
return $data | |
#$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