Last active
August 28, 2024 01:55
-
-
Save gabriel-vanca/e69158ba05dd29b9751f1b42d18d0e9d to your computer and use it in GitHub Desktop.
Get-SysInfo
This file contains hidden or 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-SysInfo { | |
<# | |
.SYNOPSIS | |
Gether system inforamtion | |
.DESCRIPTION | |
Gather information such as the Computer Name, OS, Memory Information, Disk Information and CPU Information on a local or remote system. | |
.PARAMETER Computer | |
The local or remote system to gather information from | |
#> | |
[CmdletBinding()] | |
[Alias('Get-SystemInfo')] | |
param($Computer = $ENV:COMPUTERNAME) | |
#Gets the OS info | |
$GetOS = get-ciminstance -class Win32_OperatingSystem | |
$OS = $GetOS.Caption | |
$OSArchitecture = $GetOS.OSArchitecture | |
$OSBuildNumber = $GetOS.BuildNumber | |
#Gets memory information | |
$Getmemoryslot = get-ciminstance Win32_PhysicalMemoryArray | |
$Getmemory = get-ciminstance Win32_PhysicalMemory | |
$Getmemorymeasure = get-ciminstance Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum | |
$MemorySlot = $Getmemoryslot.MemoryDevices | |
# $MaxMemory = $($Getmemoryslot.MaxCapacity / 1024 / 1024) | |
$TotalMemSticks = $Getmemorymeasure.count | |
$TotalMemSize = $($Getmemorymeasure.sum / 1024 / 1024 / 1024) | |
#Get the disk info | |
$GetDiskInfo = get-ciminstance Win32_logicaldisk -Filter "DeviceID='$ENV:SystemDrive'" | |
$DiskSize = $([math]::Round($GetDiskInfo.Size / 1GB)) | |
$FreeSpace = $([math]::Round($GetDiskInfo.FreeSpace / 1GB)) | |
$UsedSapce = $([math]::Round($DiskSize - $FreeSpace)) | |
#Gets CPU info | |
$GetCPU = get-ciminstance win32_processor | |
$CPUName = $GetCPU.Name | |
$CPUManufacturer = $GetCPU.Manufacturer | |
$CPUMaxClockSpeed = $GetCPU.MaxClockSpeed | |
#Computer Model | |
$ComputerModel = (get-ciminstance Win32_ComputerSystem).Model | |
#Serial Number | |
$SerialNumber = (get-ciminstance win32_bios).SerialNumber | |
#account status | |
$LoggedOnUser = (get-ciminstance win32_computersystem).Username | |
#Gets BIOS info | |
$BIOSName = (get-ciminstance win32_bios ).Name | |
$BIOSManufacturer = (get-ciminstance win32_bios).Manufacturer | |
$BIOSVersion = (get-ciminstance win32_bios).Version | |
#Gets Motherboard info | |
$MotherBoardName = (get-ciminstance Win32_BaseBoard).Name | |
$MotherBoardManufacturet = (get-ciminstance Win32_BaseBoard).Manufacturer | |
$MotherBoardModel = (get-ciminstance Win32_BaseBoard).Model | |
$MotherBoardProduct = (get-ciminstance Win32_BaseBoard).Product | |
$MotherBoardSerial = (get-ciminstance Win32_BaseBoard).SerialNumber | |
$ComputerInfo = New-Object -TypeName psobject | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name OperatingSystem -Value $os | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name OSArchitecture -Value $OSArchitecture | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name OSBuild -Value $OSBuildNumber | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Comp | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name ComputerModel -Value $ComputerModel | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name SerialNumber -Value $SerialNumber | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name LoggedInUsers -Value $LoggedOnUser | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name ComputerIsLocked -Value $Locked | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MemorySlots -Value $MemorySlot | |
# $ComputerInfo | Add-Member -MemberType NoteProperty -Name MaxMemory -Value "$MaxMemory GB" | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MemorySlotsUsed -Value $TotalMemSticks | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MemoryInstalled -Value "$TotalMemSize GB" | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name SystemDrive -Value $ENV:SystemDrive | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name DiskSize -Value "$DiskSize GB" | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name FreeSpace -Value "$FreeSpace GB" | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name UsedSpace -Value "$UsedSapce GB" | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name CPU -Value $CPUName | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name CPUManufacturer -Value $CPUManufacturer | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name CPUMaxClockSpeed -Value $CPUMaxClockSpeed | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MotherBoard -Value $MotherBoardName | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MotherBoardManufacturer -Value $MotherBoardManufacturet | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MotherBoardModel -Value $MotherBoardModel | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MotherBoardSerialNumber -Value $MotherBoardSerial | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name MotherBoardProduct -Value $MotherBoardProduct | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name BIOSName -Value $BIOSName | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name BIOSManufacturer -Value $BIOSManufacturer | |
$ComputerInfo | Add-Member -MemberType NoteProperty -Name BIOSVersion -Value $BIOSVersion | |
$ComputerInfo | |
Write-Output "" | |
class UnifiedNetworkDevice { | |
[string] $Index | |
[string] $ServiceName | |
[string] $Description | |
[string] $IPv4_Address | |
[string] $IPSubnet | |
[string] $Gateway | |
[string] $DHCPEnabled | |
[string] $DHCPServer | |
[string] $DNSHostName | |
[string] $DNSDomain | |
[string] $DNSServerSearchOrder | |
[string] $MACAddress | |
[string] $MACAddress_Hyphenated | |
} | |
#get network config | |
function Get-NetAdapterConiguration { | |
# Enumerating Network Cards via WMI | |
$allNetworkDevices = (get-ciminstance win32_NetworkadapterConfiguration | Where-Object IPAddress -ne $null) | |
if(!$allNetworkDevices) { | |
throw "No Network Adapter Devices Found." | |
} | |
$networkDevices = @() | |
foreach($currentNetDevice in $allNetworkDevices) { | |
[UnifiedNetworkDevice] $tempUND = [UnifiedNetworkDevice]::new() | |
$networkDevices += $tempUND | |
$tempUND.Index = $currentNetDevice.Index | |
$tempUND.ServiceName = $currentNetDevice.ServiceName | |
$tempUND.Description = $currentNetDevice.Description | |
$tempUND.IPv4_Address = if($currentNetDevice.IPAddress.Size -gt 0) {($currentNetDevice.IPAddress | Sort-Object)[0]} else { " " } | |
$tempUND.IPSubnet = if($currentNetDevice.IPSubnet.Size -gt 0) {($currentNetDevice.IPSubnet| Sort-Object)[0]} else { " " } | |
$tempUND.Gateway = $currentNetDevice.DefaultIPGateway | |
$tempUND.DHCPEnabled = $currentNetDevice.DHCPEnabled | |
$tempUND.DHCPServer = $currentNetDevice.DHCPServer | |
$tempUND.DNSHostName = $currentNetDevice.DNSHostName | |
$tempUND.DNSDomain = $currentNetDevice.DNSDomain | |
$tempUND.DNSServerSearchOrder = $currentNetDevice.DNSServerSearchOrder | |
$tempUND.MACAddress = $currentNetDevice.MACAddress | |
$tempUND.MACAddress_Hyphenated = Format-MacAddress $currentNetDevice.MACAddress -Separator 'Hyphen' | |
} | |
return ($networkDevices | Sort-Object @{Expression = "Gateway"; Descending = $true}, @{Expression = "IPv4_Address"; Descending = $false} | Select-Object -Property Index, ServiceName, Description, IPv4_Address, Gateway, DNSHostName, DNSDomain, DNSServerSearchOrder | Format-Table) | |
} | |
Get-NetAdapterConiguration | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment