Last active
February 26, 2018 06:31
-
-
Save Agazoth/4ef9694c3daf50035a9e9f2a2d623e78 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
class ComputerInfo { | |
[string]$ComputerName | |
[string]$BIOSManufacturer | |
[string]$BIOSVersion | |
[string]$Domain | |
[int]$Processors | |
[int]$Cores | |
[int]$TotalPhysicalMemoryGB | |
[string]$OSName | |
[string]$OSArchitecture | |
[string]$Timezone | |
[int]$SizeCDriveGB | |
[int]$CDriveFreeSpaceGB | |
hidden [bool]$LoadAllValues | |
hidden [Microsoft.Management.Infrastructure.CimSession]$CimSession | |
ComputerInfo(){} | |
ComputerInfo([string]$ComputerName,[string]$Domain){ | |
$this.ComputerName=$ComputerName | |
$this.Domain=$Domain | |
} | |
LoadCimSession(){ | |
if (!$this.ComputerName){$this.ComputerName=hostname} | |
$this.CimSession = New-CimSession -ComputerName $this.ComputerName | |
} | |
LoadComputerData(){ | |
if (!$this.CimSession){$this.LoadCimSession()} | |
$CimComputer=Get-CimInstance -ClassName Win32_ComputerSystem -CimSession $this.CimSession | |
if ($CimComputer.Domain -ne $CimComputer.Workgroup){ | |
$this.Domain = $CimComputer.Domain | |
} else { | |
$this.Domain = 'Not Domain joined' | |
} | |
} | |
LoadBiosData(){ | |
if (!$this.CimSession){$this.LoadCimSession()} | |
$CimBios=Get-CimInstance -ClassName Win32_Bios -CimSession $this.CimSession | |
$this.BIOSManufacturer = $CimBios.Manufacturer | |
$this.BIOSVersion = $CimBios.BIOSVersion -join ';' | |
} | |
LoadOSData(){ | |
if (!$this.CimSession){$this.LoadCimSession()} | |
$CimOS=Get-CimInstance -ClassName Win32_OperatingSystem -CimSession $this.CimSession | |
$this.OSName = $CimOS.Caption | |
$this.OSArchitecture = $CimOS.OSArchitecture | |
} | |
LoadProcessorData(){ | |
if (!$this.CimSession){$this.LoadCimSession()} | |
$CimProcessor=Get-CimInstance -ClassName Win32_Processor -CimSession $this.CimSession | |
$this.Processors = $CimProcessor.NumberOfLogicalProcessors | |
$this.Cores = $CimProcessor.NumberOfCores | |
} | |
LoadMemoryData(){ | |
if (!$this.CimSession){$this.LoadCimSession()} | |
$this.TotalPhysicalMemoryGB = $(Get-CimInstance -ClassName win32_PhysicalMemory -CimSession $this.CimSession | Measure-Object -Sum Capacity).Sum/1GB | |
} | |
LoadTimeZone(){ | |
if (!$this.CimSession){$this.LoadCimSession()} | |
$this.Timezone=Get-CimInstance -ClassName Win32_TimeZone -CimSession $this.CimSession | Select-Object -ExpandProperty Caption | |
} | |
LoadDiskData(){ | |
if (!$this.CimSession){$this.LoadCimSession()} | |
$CimDisk = Get-CimInstance -ClassName Win32_LogicalDisk -CimSession $this.CimSession | Where-Object {$_.DeviceID -eq 'C:'} | |
$this.SizeCDriveGB = $CimDisk.size/1GB | |
$this.CDriveFreeSpaceGB = $CimDisk.FreeSpace/1GB | |
} | |
[string]GetFreeDiskPctOnC(){ | |
if (!$this.SizeCDriveGB){$this.LoadDiskData()} | |
return "{0:P}" -f ($this.CDriveFreeSpaceGB/$this.SizeCDriveGB) | |
} | |
ComputerInfo([string]$ComputerName,[bool]$LoadAllValues){ | |
$this.LoadBiosData() | |
$this.LoadCimSession() | |
$this.LoadComputerData() | |
$this.LoadDiskData() | |
$this.LoadMemoryData() | |
$this.LoadOSData() | |
$this.LoadProcessorData() | |
$this.LoadTimeZone() | |
} | |
} |
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
iex ((New-Object System.Net.WebClient).DownloadString('https://gist.githubusercontent.com/Agazoth/4ef9694c3daf50035a9e9f2a2d623e78/raw/96a64abfac6dc87b527bf6e2bb9e284228151132/ComputerInfoClass.ps1'));[ComputerInfo]::new('',$true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment