-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-SysInfo.ps1
82 lines (65 loc) · 2.91 KB
/
Get-SysInfo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<#
.Synopsis
Gathers system information.
.DESCRIPTION
Returns local or remote system information. Designed to be used with Get-ADComputer.
.EXAMPLE
PS C:\Windows\system32> Get-ADComputer -Filter 'OperatingSystem -like "*server*"' | Get-SysInfo | ft
ComputerName Description OS Asset Tag CPU Memory Manufacturer Model
------------ ----------- -- --------- --- ------ ------------ -----
DC01 Primary DC Microsoft Windows Server 2008 R2 Standard VMware 1 4 VMware, Inc. VMw...
TS01 Terminal Server Microsoft Windows Server 2008 R2 Standard VMware 2 12 VMware, Inc. VMw...
Builds server list from AD and then gathers system info.
.EXAMPLE
PS C:\Windows\system32> Get-SysInfo
ComputerName : 100IT001
Description : Clint Colding
OS : Microsoft Windows 10 Pro
Asset Tag : H3CXXXX
CPU : 2
Memory : 8
Manufacturer : Dell Inc.
Model : Latitude E5440
Gathers localhost system info.
#>
function Get-SysInfo{
[CmdletBinding()]
Param(
[Alias("ComputerName")]
[Parameter(ValueFromPipelineByPropertyName=$true,
Position=0)]
[string[]]$Name='localhost'
)
Process{
try{
foreach($Computer in $Name){
$Asset = Get-WmiObject Win32_BIOS -ComputerName $Computer -ErrorAction Stop -ErrorVariable AssetError
$CPU = Get-WmiObject Win32_Processor -ComputerName $Computer -ErrorAction Stop -ErrorVariable CPUError
$OS = Get-WmiObject Win32_OperatingSystem -ComputerName $Computer -ErrorAction Stop -ErrorVariable OSError
$System = Get-WmiObject Win32_ComputerSystem -ComputerName $Computer -ErrorAction Stop -ErrorVariable SysError
$Prop = [ordered]@{
'ComputerName' = $OS.PSComputerName
'Description' = $OS.Description
'OS' = $OS.Caption
'Asset Tag' = if($Asset.SerialNumber -like "*VMware*"){'VMware'}
else{$Asset.SerialNumber}
'CPU' = ($CPU.NumberOfCores | Measure-Object -Sum).Sum
'Memory' = [math]::Round($System.TotalPhysicalMemory / 1GB)
'Manufacturer' = $System.Manufacturer
'Model' = $System.Model
}
$Obj = New-Object -TypeName PSObject -Property $Prop
Write-Output $Obj
}
}
catch [System.Runtime.InteropServices.COMException]{
$Warning = Write-Warning "Could not connect to $Computer."
}
catch{
$AssetError
$CPUError
$OSError
$SysError
}
}
}