Get-ComputerInfo.ps1


<#PSScriptInfo
 
.VERSION 1.9
 
.GUID b5d5d431-3fce-4a60-b19a-22426cc507dc
 
.AUTHOR J.B. Walters
 
.COMPANYNAME Walters I.T. Consulting
 
.COPYRIGHT
 
.TAGS CIM, Remote, Computer Information, BIOS
 
.LICENSEURI https://1drv.ms/t/s!AmvOxfM2BImuiO5OxPL8lzmpwZYikQ?e=RWbfld
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>
 






# AUTHOR: Walters I.T. Consulting
# LAST MODIFIED: 6/29/2020
# version 1.9

<#
.SYNOPSIS
      Queryies a computer by its computer name using CIM for basic information about the computer specified.
.DESCRIPTION
     The Get-ComputerInfo.ps1 script uses CIM to get information about a computer that is specified in the -ComputerName parameter.
     The -ComputerName is optional, when not specified, the script defaults to the name of the local computer for the input to the -ComputerName parameter. This script gathers information such as BIOS, Disk, Memory and other specific information about the computer.
.EXAMPLE
     Get-ComputerInfo.ps1 -ComputerName <String>
     This command uses the name of computer as input and returns information about said computer.
.EXAMPLE
     Get-ComputerInfo.ps1
     This command is being ran without the -ComputerName parameter and the user will be prompt for the computer name during the script execution.
.EXAMPLE
     Get-ComputerInfo.ps1 -ComputerName <String> | Out-File -Append <String>
     This command uses the name of the computer as input, and then writes the output of the script to a file defined in the command.
.NOTES
     Some things such as sorting output, formating output, and selecting output that is generated from this script does not work at this time. Also this script works best in domain enviroments, where one is querying another computer on a domain using its computer name.
 
     This script also has been tested over a VPN and it works if your VPN is set up correctly.
 
     The operating systems that this script has been tested on includes but is not limited to is Windows 10, Windows Server 2016 Datacenter, and Windows Server 2019 Datacenter.
 
     Note about current logged on user value: when no user is currently logged on the system, the value will be null.
#>


# accecpting user input as a parameter
param(
[string]$ComputerName = (Read-Host "Please enter the name of the computer you would like to query, or press enter to query your local machine")
)

# if statement setting a default value for $ComputerName if it is NullOrWhiteSpace
if([string]::IsNullOrWhiteSpace($ComputerName))
{
$ComputerName = 'localhost'
}

# letting user(s) know what computer is being queried
Write-Output "Currently querying the following computer: $ComputerName"

$List = @()

# variables
$Bios = Get-CimInstance -ClassName Win32_BIOS -ComputerName $ComputerName
$System= Get-CimInstance -ClassName Win32_ComputerSystem -ComputerName $ComputerName
$Proc = Get-CimInstance -ClassName Win32_processor -ComputerName $ComputerName | Select-Object -First 1
$Memory = Get-CimInstance -ClassName Win32_physicalmemory -ComputerName $ComputerName
$Computer = Get-CimInstance -ClassName Win32_OperatingSystem -ComputerName $ComputerName
$DisksSize = Get-CimInstance -ClassName CIM_LogicalDisk -ComputerName $ComputerName | Select-Object @{Name="Size(GB)";Expression={$_.Size/1GB -as [int]}}, DeviceID, DriveType | Where-Object DriveType -EQ '3'
$DiskStatus = Get-CimInstance -ClassName Win32_DiskDrive -ComputerName $ComputerName
$DisksSpace = Get-CimInstance -ClassName CIM_LogicalDisk -ComputerName $ComputerName | Select-Object @{Name="Free (%)";Expression={"{0,6:P0}" -f(($_.freespace/1gb) / ($_.size/1gb))}}, DeviceID, DriveType | Where-Object DriveType -EQ '3'
$PlaceHolder = Write-Output ""
$Title = Write-Output "Computer Information"
$Uptime = (get-date) - (Get-CimInstance Win32_OperatingSystem -ComputerName $ComputerName).LastBootUpTime | Select-Object Days, hours, minutes
# $testreboot = Test-PendingReboot.ps1 -ComputerName $computer.CsName
# Note: Admin rights are needed in order to run this script with the test reboot option


$List += [pscustomobject]@{
    'Computer Information'= $Title
    ' '                   = $placeholder
    'Computer Name'       = $Computer.CSName
    'Manufacturer'        = $System.Manufacturer
    'Model'                  = $System.Model
    'Current Logged In User' =$System.UserName
    'BIOS Manufacturer'   = $Bios.Manufacturer
    'BIOS Version'        = $Bios.BIOSVersion
    'BIOS Date'              = $Bios.ReleaseDate
    'Serial Number'       = $Bios.SerialNumber
    'Processor Number'    = $System.NumberOfProcessors
    'Processor Name'      = $Proc.name
    'Processor Cores'     = $System.NumberOfLogicalProcessors
    'Speed (MHZ)'         = $Proc.CurrentClockSpeed
    'RAM (GB)'            = $System.TotalPhysicalMemory / 1GB -as [int]
    'Memory Speed'          = $Memory.Speed
    'Used RAM slot'       = $Memory.count
    'Disk Health'         = $DiskStatus.Status
    'Disk Size (GB)'       = $DisksSize
    'Free Space (%)'      = $DisksSpace
    'System Uptime'       = $Uptime
# 'Reboot Needed' = $testreboot
}


$List | Format-List
Read-Host -Prompt "Press Enter to Exit"

# SIG # Begin signature block
# MIIKSgYJKoZIhvcNAQcCoIIKOzCCCjcCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU4LpefHS3/dpCvjtU55h7KmtW
# 6a+gggagMIIGnDCCBYSgAwIBAgITGgAAAAliBBrBU0VcIwAAAAAACTANBgkqhkiG
# 9w0BAQ0FADBcMRMwEQYKCZImiZPyLGQBGRYDY29tMSMwIQYKCZImiZPyLGQBGRYT
# V2FsdGVyc2l0Y29uc3VsdGluZzEgMB4GA1UEAxMXV2FsdGVycyBJLlQuIENvbnN1
# bHRpbmcwHhcNMjAwMTIxMjIwMTEwWhcNMjIwMTIxMjIxMTEwWjAiMSAwHgYDVQQK
# ExdXYWx0ZXJzIEkuVC4gQ29uc3VsdGluZzCCAiIwDQYJKoZIhvcNAQEBBQADggIP
# ADCCAgoCggIBALKOYZ0u7pJ3GcFJ6aFBhSWlTxWsEsFMPrmfZKFwTVXRU3OuC58a
# RGDybS3t0kmafK7odd1ZrhHYJoabBhFDXbBsj88Ogn9ByxChztKn+AwvXpthkoWo
# 5ebuhpUfmLK5n7iKNnfdCSCFumARLKiK1ZRkEwR7RhT5nrKtPvvFTskZrf6TEfd1
# /yncAIZgaKWiEug7V0Zxcd3ShSJDL1tW3Pa/kskMWwwASjPCmgyPqMdG2WELPbVQ
# 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LWLY+7gFmY4/2RQKJ9H2lmMWVHeHys
# /wnZanlyK8rMnvxgvgSw5n0AxVLWNLvFkL23fsQx+fC4IR+6fR0EFh7s2DVHI1no
# ZKm+xdQMPNYR6yYlPyJxTR99Eo/Q7/5t9WRewB3wb8a5r0UlETmc//DF+HxRZLdC
# 2fKAVm+LiHZ1nL2SSTeyfe0qtp+hL4GnOSl/1aZ5UP67sW3iUTC6rW3tYqleTBmc
# jCvzicI1SgUe7WGhE3t5+sZsQCjyajaJ9osoIibM5xFjPSalZcwzX7zB8Gd4RmH8
# vHd/5Azrsw80/O7IZdot6GkN+axoKwnUj0EiJ8BgyTSbqQUTTJwIcxGG5L2Tnu3A
# yVzUwG2Gd9aAjXJt0yvAQlJc4T+wZbvCa7SebD30WFzy2e+In9MC1/Oof5QSwPPa
# Wmeq8WRne5vWofMdAt4LhxylZzBWtVK2Hs15O+YxsabMcXRdicNV7tlwitL5sKbU
# gePtkiONJqTYApxBCqD2jo/reDoiYhPU8WZzIAv/YgMlK+KtfdZhxVIe5RdVSAWm
# DTnAsi+HIdhPRl/NNcd5buSAs7kjHn6nMpLbp2RJchcOfXLHZBLp6cFUMiQIBR4s
# FI3abGY5E+Gj65l4jHrAsQroM+KAQUeQ60swy3WZ03zqAQ7jtGSz0vCvyTYSxA==
# SIG # End signature block

# Change Log:

# Version 1.9
# Added Tags

# Version 1.8
# Fixed help in script

# Version 1.7
# Removed Param() at top which caused an error

# Version 1.6
# Updated PSScriptFileInfo
# Updated help content

# Version 1.5
# Updated user prompt
# Added default value for $ComputerName
# Added help content

# Version 1.4
# Added ability to query remote computers
# Added more CIM commands

# Version 1.3
# Added pending reboot tester (note, pending reboot tester calls a script which can be installed by using the following: Install-Script Test-PendingReboot)
# Added system uptime calculation
# Added formating to the code
# Deleted trailing whitespace in code

# Version 1.2
# Changed from using WMI to CIM
# Signed script

# Version 1.1
# Changed some code

# Version 1.0
# Created code (some reused from online examples)