saldar1234

Get-SummaryInfo

May 18th, 2020
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Get-SummaryInfo {
  2. <#
  3.   .SYNOPSIS
  4.     This script uses basic windows modules to get basic detailed information about a computer
  5.   .DESCRIPTION
  6.     Queries WMI objects to get information about a computer. Does not require administrator permissions to run successfully.
  7.   .PARAMETER Output
  8.     (Default) List: Outputs information in standard console list format.
  9.     Gridview: Outputs information in a GridView window.
  10.     Raw: Outputs information raw, unformatted.
  11.     CSV: Outputs informationt to a CSV file.
  12.   .OUTPUTS
  13.     Outputs basic computer information formatted based on input parameter.
  14.   .NOTES
  15.     Version:        1.0
  16.     Author:         Josh Fletcher
  17.     Creation Date:  5/18/2020
  18.     Purpose/Change: Initial script development
  19.  
  20.   .EXAMPLE
  21.     PS C:\> Get-SummaryInfo
  22.  
  23.     Name              : DESKTOP-ABCD123
  24.     Serial Number     : System Serial Number
  25.     Domain            : Computer not domain joined, Workgroup name: WORKGROUP
  26.     Local Credentials : Not Detected
  27.     Uptime            : 3D 21H 40M
  28.     IPv4 Address      : 192.###.###.###
  29.     IPv6 Address      : fe80::####:####:####:######
  30.     OS Caption        : Windows 10 Pro
  31.     OS Version        : 10.0 (Build 18362)
  32.     OS Architecture   : x64
  33.     OS Release        : 1903
  34.     Update Revision   : 836
  35.     Installed On      : Tuesday, November 5, 2019 @ 07:36PM
  36.     Model             : System manufacturer System Product Name
  37.     SKU               : SKU
  38.     Motherboard       : ASUSTeK COMPUTER INC. STRIX Z270H GAMING
  39.     CPU               : Intel Core i7-7700K
  40.     RAM               : 16 GB, 2 out of 4 slots used
  41.     Disk Drive        : 500GB SSD - Samsung SSD 970 EVO Plus 500GB; 2000GB HDD - ST2000DM001-1ER164
  42.     Video             : NVIDIA GeForce GTX 1070
  43.  
  44.   .EXAMPLE
  45.     PS C:\> Get-SummaryInfo -Output GridView
  46. #>
  47. Param(
  48.     [Parameter()][ValidateSet("List", "GridView", "CSV")][String]$Output = "List"
  49. )
  50.  
  51.     $r = $(
  52.         $os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $env:COMPUTERNAME
  53.         $bios = Get-WmiObject -Class Win32_Bios -ComputerName $env:COMPUTERNAME
  54.         If ((Get-LocalUser "LocalAdmin" -ErrorAction SilentlyContinue).enabled) {$LocalCredentials="Username: LocalAdmin`nPassword: GW$($bios.SerialNumber.ToLower())"} Else {$LocalCredentials="Not Detected"}
  55.         $cs = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $env:COMPUTERNAME
  56.         $domain = If ($cs.partofdomain) {"$((Get-WmiObject win32_computersystem).Domain)"} else {"Computer not domain joined, Workgroup name: $((Get-WmiObject win32_computersystem).Domain)"}
  57.         $ipv4address = (Test-Connection $env:COMPUTERNAME -count 1).IPV4Address.IPAddressToString
  58.         $ipv6address = (Test-Connection $env:COMPUTERNAME -count 1).IPV6Address.IPAddressToString
  59.         $User = $cs.username
  60.         $mb = Get-WmiObject win32_baseboard  -computer $env:COMPUTERNAME
  61.         $memcap = (Get-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Sum
  62.         $memmods = (Get-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Count
  63.         $cpu = Get-WmiObject Win32_Processor -computer $env:COMPUTERNAME; Write-Verbose "$env:COMPUTERNAME CPU: $($cpu.Name.Replace(`"(R)`",`"`").Replace(`"(TM)`",`"`").Replace(`"CPU `",`"`").replace(`"   `",`"`").split(`"@`") | Select-Object -First 1)"
  64.         $ram = [int](($memcap) / [math]::Pow(1024,3)); $ram = $ram.ToString(); Write-Verbose "$env:COMPUTERNAME RAM: $($ram + "GB")"
  65.         $sticks = (Get-WmiObject -class "Win32_PhysicalMemoryArray").MemoryDevices
  66.         $hds = @(Get-WmiObject -Class Win32_DiskDrive -ComputerName $env:COMPUTERNAME | ? {$_.model -notlike "*generic*"});$HardDrives = @();$index = 0
  67.         foreach ($hd in $hds) {
  68.             $hdsize = [int](($hd.size) / [math]::Pow(1000,3)); $hdSize = $hdSize.ToString()
  69.             If ([version]$os.version -gt [version]"6.1.7601.0") {If ((@(Get-WmiObject -Namespace root\Microsoft\Windows\Storage -Class MSFT_PhysicalDisk -ComputerName $env:COMPUTERNAME | Select-Object -ExpandProperty Spindlespeed)[$index]) -gt 0) {$MediaType = "HDD"} Else {$MediaType = "SSD"}} Else {$MediaType = "Model: $($hd.model.Replace(`"SCSI`",`"`").Replace(`"Disk`",`"`").Replace(`"Device`",`"`"))"}
  70.             $HardDrives += @("$($hdSize)GB $($MediaType.Trim()) - $($hd.model)")
  71.             $index++
  72.         }
  73.         $video = ((Get-WmiObject Win32_VideoController  -ComputerName $env:COMPUTERNAME).description).replace("  ","") -Join ", "; Write-Verbose "$env:COMPUTERNAME video: $video"
  74.         $bt = $os | %{ $_.ConvertToDateTime($_.LastBootUpTime) };$now=get-date;$ut=$now-$bt;$d=$ut.Days;$h=$ut.Hours;$m=$ut.Minutes;$Uptime=""|Select-Object ut;$uptime.ut="$d`D $h`H $m`M"; Write-Verbose "$computer Uptime: $($uptime.ut)"
  75.         $manufacturer = If(($cs.Manufacturer -like "*HP*") -or ($cs.Manufacturer -like "*Hewlett*")) {"HP"} ElseIf($cs.Manufacturer -like "*Fuji*") {"Fujitsu"} Else {($cs.Manufacturer).Replace(" Corporation","")}
  76.         $model = ($cs.model).Replace("HP ","").Replace("146D____","EliteBook 6550b").Replace(" (FN022UT#ABA)","")
  77.  
  78.         $pcProperties = @{
  79.             'Name'=$cs.Name
  80.             'Serial Number'=If ($cs.model -like "*Virtual*") {"VM"} Else {$bios.SerialNumber};
  81.             'Domain'=$domain
  82.             'Local Credentials' = $LocalCredentials
  83.             'CPU'=$cpu.Name.Replace("(R)","").Replace("(TM)","").Replace("CPU ","").replace("   ","").split("@") | Select-Object -First 1;
  84.             'Motherboard'="$($mb.Manufacturer) $($mb.Product)"
  85.             'RAM'="$($ram) GB, $($memmods) out of $($sticks) slots used";
  86.             'Disk Drive'=$HardDrives -join "; "
  87.             'OS Caption'=($os.Caption).Replace("Microsoft ","");
  88.             'OS Version'="$([System.Environment]::OSVersion.Version.Major).$([System.Environment]::OSVersion.Version.Minor) (Build $([System.Environment]::OSVersion.Version.Build))";
  89.             'OS Release'=(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name ReleaseID).ReleaseID;
  90.             'Update Revision'=(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR;
  91.             'Model'= "$manufacturer $model"
  92.             'SKU'=$cs.SystemSKUNumber;
  93.             'OS Architecture'=($cs.SystemType).replace("-based PC","");
  94.             'Installed On'=$os.ConvertToDateTime($os.InstallDate).ToString('dddd, MMMM d, yyyy @ hh:mmtt');
  95.             'Uptime'=$uptime.ut;
  96.             'IPv4 Address'=$ipv4address;
  97.             'IPv6 Address'=$ipv6address;
  98.             'User'=If($Status -like "*Remote*"){"GW\$User"}Else{$cs.username};
  99.             'Video'=$video
  100.         }
  101.         New-Object -TypeName PSCustomObject -Property $pcProperties
  102.     )
  103.     $Raw = ($r | Select-Object "Name","Serial Number","Domain","Local Credentials","Uptime","IPv4 Address","IPv6 Address","OS Caption","OS Version","OS Architecture","OS Release","Update Revision","Installed On","Model","SKU","Motherboard","CPU","RAM","Disk Drive","Video")
  104.     $Results = @();$ResultNames = @()
  105.     $ResultNames = $Raw.PSObject.Properties | Select-Object -ExpandProperty Name
  106.     $Raw.PSObject.Properties | ForEach-Object {$Results += New-Object -TypeName PSObject -Property @{Property = $_.Name}}
  107.     $count = 0
  108.     $ResultNames | %{If ($Raw.($_)){$Results[$count] | Add-Member -Name $Raw.Name -Type NoteProperty -Value $Raw.($_)} Else {$Results[$count] | Add-Member -Name $Raw.Name -Type NoteProperty -Value $NULL}; $count++}
  109.  
  110.     Switch($Output) {
  111.         ("List") {$r | Select-Object "Name","Serial Number","Domain","Local Credentials","Uptime","IPv4 Address","IPv6 Address","OS Caption","OS Version","OS Architecture","OS Release","Update Revision","Installed On","Model","SKU","Motherboard","CPU","RAM","Disk Drive","Video" | FL}
  112.         ("GridView") {$Results | Out-GridView}
  113.         ("CSV") {[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
  114.             $SFD = New-Object System.Windows.Forms.SaveFileDialog
  115.             $SFD.InitialDirectory = "$env:USERPROFILE\Documents"
  116.             $SFD.Filter = "CSV Files (*.csv)|*.csv|Text Files (*.txt)|*.txt|Excel Worksheet (*.xls)|*.xls|All Files (*.*)|*.*"
  117.             $SFD.ShowDialog() | Out-Null
  118.             $Results | Export-Csv -Path $SFD.FileName -Force -NoTypeInformation -ErrorAction SilentlyContinue
  119.             If(($SFD.FileName).Length -gt 0) {Write-host -ForegroundColor Cyan "File has been saved to $($SFD.FileName)"} else {Write-Warning "File not created"}
  120.         }
  121.     }
  122. }; If (!(Get-Alias -Name info -ErrorAction SilentlyContinue)) {New-Alias -Name info -value Get-SummaryInfo -Force -ErrorAction SilentlyContinue}
Add Comment
Please, Sign In to add comment